§
    ÈtºfÚ   ã            
       óì  — d Z ddlmZmZ ddlmZmZmZmZm	Z	m
Z
mZmZ ddlmZ ddlmZ ddlmZ ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZ  e¦   «         Zeeef         Zdedefd„Z dedefd„Z!d„  ed¦  «        d„ d„ fd„  ed¦  «        e e!fgZ"d„ e"D ¦   «         Z#dede$fd„Z%de$defd„Z&dedefd„Z'dedefd „Z(	 d*d"ee         d#edefd$„Z)	 	 d+d'ee         d#e
e         d(e*de	e         fd)„Z+d%S ),zA
Tools for saving and loading log events in a structured format.
é    )ÚdumpsÚloads)ÚIOÚAnyÚAnyStrÚDictÚIterableÚOptionalÚUnionÚcast)ÚUUID)ÚNamedConstant)ÚFailureé   ©ÚFileLogObserver)ÚflattenEvent)ÚLogEvent)ÚLogLevel)ÚLoggerÚfailureÚreturnc                 óŽ   — t          |                      ¦   «         t          | j        j        | j        j        ¬¦  «        ¬¦  «        S )zÖ
    Convert a failure to a JSON-serializable data structure.

    @param failure: A failure to serialize.

    @return: a mapping of strings to ... stuff, mostly reminiscent of
        L{Failure.__getstate__}
    )Ú
__module__Ú__name__)Útype)ÚdictÚ__getstate__r   r   r   )r   s    úS/var/www/surfInsights/venv3-11/lib/python3.11/site-packages/twisted/logger/_json.pyÚfailureAsJSONr       sL   € õ Ø×ÒÑÔÝØ”|Ô.Ø”\Ô*ð
ñ 
ô 
ðñ ô ð ó    ÚfailureDictc                 ó¦   — t          j        t           ¦  «        }| d         }t          |d         d|¦  «        | d<   |                     | ¦  «         |S )zÌ
    Load a L{Failure} from a dictionary deserialized from JSON.

    @param failureDict: a JSON-deserialized object like one previously returned
        by L{failureAsJSON}.

    @return: L{Failure}
    r   r   © )r   Ú__new__r   Ú__setstate__)r"   ÚfÚtypeInfos      r   ÚfailureFromJSONr)   .   sO   € õ 	Œ�Ñ Ô €AØ˜6Ô"€HÝ˜x¨
Ô3°R¸ÑBÔB€K�ÑØ‡N‚N�;ÑÔÐØ€Hr!   c                 óf   — t          | t          ¦  «        ot          t          | j        d ¦  «        | u S ©N)Ú
isinstancer   Úgetattrr   Úname©Úlevels    r   ú<lambda>r1   @   s/   € Ý�u�mÑ,Ô,ð =Ý� %¤*¨dÑ3Ô3°uÐ<ð r!   z$02E59486-F24D-46AD-8224-3ACDF2A5732Ac                 ó,   — t          | j        ¬¦  «        S )N)r.   )r   r.   r/   s    r   r1   r1   E   s   € •d ¤
Ð+Ñ+Ô+€ r!   c                 ó:   — t          t          | d         d ¦  «        S )Nr.   )r-   r   r/   s    r   r1   r1   F   s   € •g�h¨¨f¬°tÑ<Ô<€ r!   c                 ó,   — t          | t          ¦  «        S r+   )r,   r   )Úos    r   r1   r1   I   s   € •*˜Q¥Ñ(Ô(€ r!   z$E76887E2-20ED-49BF-A8F8-BA25CC586F2Dc                 ó   — i | ]
\  }}}}||“ŒS r$   r$   )Ú.0Ú	predicateÚuuidÚsaverÚloaders        r   ú
<dictcomp>r<   Q   s#   € ÐOÐOÐOÑ!A )¨T°5¸&��fÐOÐOÐOr!   ÚaDictc                 ó^   — d| v r(t          t          | d         ¦  «                 | ¦  «        S | S )a#  
    Dictionary-to-object-translation hook for certain value types used within
    the logging system.

    @see: the C{object_hook} parameter to L{json.load}

    @param aDict: A dictionary loaded from a JSON object.

    @return: C{aDict} itself, or the object represented by C{aDict}
    Ú__class_uuid__)ÚuuidToLoaderr   )r=   s    r   ÚobjectLoadHookrA   T   s5   € ð ˜5Ð Ð Ý�D Ð'7Ô!8Ñ9Ô9Ô:¸5ÑAÔAÐAØ€Lr!   ÚpythonObjectc                 ó€   — t           D ]3\  }}}} || ¦  «        r! || ¦  «        }t          |¦  «        |d<   |c S Œ4ddiS )a�  
    Object-to-serializable hook for certain value types used within the logging
    system.

    @see: the C{default} parameter to L{json.dump}

    @param pythonObject: Any object.

    @return: If the object is one of the special types the logging system
        supports, a specially-formatted dictionary; otherwise, a marker
        dictionary indicating that it could not be serialized.
    r?   ÚunpersistableT)Ú	classInfoÚstr)rB   r8   r9   r:   r;   Úresults         r   ÚobjectSaveHookrH   d   si   € õ +4ð ð Ñ&ˆ	�4˜ Øˆ9�\Ñ"Ô"ð 	Ø�U˜<Ñ(Ô(ˆFÝ'*¨4¡y¤yˆFÐ#Ñ$ØˆMˆMˆMð	ð ˜TÐ"Ð"r!   Úeventc                 óŒ   — dt           dt          t          t          f         fd„}t	          | ¦  «         t          | |d¬¦  «        S )a˜  
    Encode an event as JSON, flattening it if necessary to preserve as much
    structure as possible.

    Not all structure from the log event will be preserved when it is
    serialized.

    @param event: A log event dictionary.

    @return: A string of the serialized JSON; note that this will contain no
        newline characters, and may thus safely be stored in a line-delimited
        file.
    Úunencodabler   c                 ót   — t          | t          ¦  «        r|                      d¦  «        S t          | ¦  «        S )z®
        Serialize an object not otherwise serializable by L{dumps}.

        @param unencodable: An unencodable object.

        @return: C{unencodable}, serialized
        Úcharmap)r,   ÚbytesÚdecoderH   )rK   s    r   ÚdefaultzeventAsJSON.<locals>.defaultˆ   s8   € õ �k¥5Ñ)Ô)ð 	1Ø×%Ò% iÑ0Ô0Ð0Ý˜kÑ*Ô*Ð*r!   T)rP   Úskipkeys)Úobjectr   ÚJSONDictrF   r   r   )rI   rP   s     r   ÚeventAsJSONrT   y   sR   € ð
+�Vð 
+­­h½¨mÔ(<ð 
+ð 
+ð 
+ð 
+õ �ÑÔÐÝ� °$Ð7Ñ7Ô7Ð7r!   Ú	eventTextc                 óT   — t          t          t          | t          ¬¦  «        ¦  «        S )z¦
    Decode a log event from JSON.

    @param eventText: The output of a previous call to L{eventAsJSON}

    @return: A reconstructed version of the log event.
    )Úobject_hook)r   rS   r   rA   )rU   s    r   ÚeventFromJSONrX   ˜   s!   € õ •�% 	µ~ÐFÑFÔFÑGÔGÐGr!   úÚoutFileÚrecordSeparatorc                 ó*   ‡— t          | ˆfd„¦  «        S )aÏ  
    Create a L{FileLogObserver} that emits JSON-serialized events to a
    specified (writable) file-like object.

    Events are written in the following form::

        RS + JSON + NL

    C{JSON} is the serialized event, which is JSON text.  C{NL} is a newline
    (C{"\n"}).  C{RS} is a record separator.  By default, this is a single
    RS character (C{"\x1e"}), which makes the default output conform to the
    IETF draft document "draft-ietf-json-text-sequence-13".

    @param outFile: A file-like object.  Ideally one should be passed which
        accepts L{str} data.  Otherwise, UTF-8 L{bytes} will be used.
    @param recordSeparator: The record separator to use.

    @return: A file log observer.
    c                 ó,   •— ‰› t          | ¦  «        › d�S )Nú
)rT   )rI   r[   s    €r   r1   z%jsonFileLogObserver.<locals>.<lambda>º   s   ø€  /ÐIµ;¸uÑ3EÔ3EÐIÐIÐI€ r!   r   )rZ   r[   s    `r   ÚjsonFileLogObserverr_   £   s&   ø€ õ, ØÐIÐIÐIÐIñô ð r!   Né   ÚinFileÚ
bufferSizec              #   ó€  ‡K  — dt           dt          fd„}dt          dt          t                   fd„Š|€* ||                      d¦  «        ¦  «        }|dk    r|}nd	}n ||¦  «        }d	}|d	k    rd
}‰}ndt          dt          t                   fˆfd„}t          |¦  «        }	 |                      |¦  «        }|s&t          |¦  «        dk    r ||¦  «        }	|	�|	V — dS | ||¦  «        z  }|                     |¦  «        }
|
dd…         D ]&}t          |¦  «        dk    r ||¦  «        }	|	�|	V — Œ'|
d         }Œš)aM  
    Load events from a file previously saved with L{jsonFileLogObserver}.
    Event records that are truncated or otherwise unreadable are ignored.

    @param inFile: A (readable) file-like object.  Data read from C{inFile}
        should be L{str} or UTF-8 L{bytes}.
    @param recordSeparator: The expected record separator.
        If L{None}, attempt to automatically detect the record separator from
        one of C{"\x1e"} or C{""}.
    @param bufferSize: The size of the read buffer used while reading from
        C{inFile}.

    @return: Log events as read from C{inFile}.
    Úsr   c                 óZ   — t          | t          ¦  «        r| S |                      d¦  «        S )Núutf-8)r,   rN   Úencode)rd   s    r   ÚasBytesz&eventsFromJSONLogFile.<locals>.asBytesÒ   s+   € Ý�a�ÑÔð 	%ØˆHà—8’8˜GÑ$Ô$Ð$r!   Úrecordc                 óR  — 	 t          | ¦  «                             d¦  «        }n:# t          $ r- t                               dt          | ¦  «        ¬¦  «         Y d S w xY w	 t          |¦  «        S # t          $ r- t                               dt          | ¦  «        ¬¦  «         Y d S w xY w)Nrf   z2Unable to decode UTF-8 for JSON record: {record!r}©ri   z&Unable to read JSON record: {record!r})rN   rO   ÚUnicodeDecodeErrorÚlogÚerrorrX   Ú
ValueError)ri   Útexts     r   ÚeventFromBytearrayz1eventsFromJSONLogFile.<locals>.eventFromBytearrayØ   s¿   € ð	Ý˜‘=”=×'Ò'¨Ñ0Ô0ˆDˆDøÝ!ð 	ð 	ð 	Ý�IŠIØDÝ˜V‘}”}ð ñ ô ð ð �4�4ð	øøøð	Ý  Ñ&Ô&Ð&øÝð 	ð 	ð 	Ý�IŠIÐ>ÅuÈVÁ}Ä}ˆIÑUÔUÐUØ�4�4ð	øøøs!   ‚"% ¥3AÁAÁ A/ Á/3B&Â%B&Nr   ó   r!   ó   
c                 ó¢   •— | d         t          d¦  «        k    r ‰| ¦  «        S t                               dt          | ¦  «        ¬¦  «         d S )Néÿÿÿÿr^   z0Unable to read truncated JSON record: {record!r}rk   )Úordrm   rn   rN   )ri   rq   s    €r   ÚeventFromRecordz.eventsFromJSONLogFile.<locals>.eventFromRecordþ   sW   ø€ Ø�bŒz�S ™YœYÒ&Ð&Ø)Ð)¨&Ñ1Ô1Ð1å—	’	ØFÝ  ™=œ=ð ñ ô ð ð �4r!   Tr   ru   )r   rN   Ú	bytearrayr
   r   ÚreadÚlenÚsplit)ra   r[   rb   rh   ÚfirstÚrecordSeparatorBytesrw   ÚbufferÚnewDatarI   Úrecordsri   rq   s               @r   ÚeventsFromJSONLogFiler�   ¾   sÈ  øè è € ð(%•6ð %�eð %ð %ð %ð %ð¥9ð µ½(Ô1Cð ð ð ð ð  ÐØ�˜Ÿš A™œÑ'Ô'ˆà�GÒÐà#(Ð Ð ð $'Ð Ð ð  '˜w Ñ7Ô7ÐØˆà˜sÒ"Ð"Ø$Ðà,ˆˆð	¥Ið 	µ(½8Ô2Dð 	ð 	ð 	ð 	ð 	ð 	õ �uÑÔ€FðØ—+’+˜jÑ)Ô)ˆàð 	Ý�6‰{Œ{˜QŠˆØ'˜¨Ñ/Ô/�ØÐ$Ø�K�K�KØˆEà�'�'˜'Ñ"Ô"Ñ"ˆØ—,’,Ð3Ñ4Ô4ˆà˜c˜r˜c”lð 	 ð 	 ˆFÝ�6‰{Œ{˜QŠˆØ'˜¨Ñ/Ô/�ØÐ$Ø�K�K�Køà˜”ˆð'r!   )rY   )Nr`   ),Ú__doc__Újsonr   r   Útypingr   r   r   r   r	   r
   r   r   r9   r   Ú
constantlyr   Útwisted.python.failurer   Ú_filer   Ú_flattenr   Ú_interfacesr   Ú_levelsr   Ú_loggerr   rm   rF   rS   r    r)   rE   r@   rR   rA   rH   rT   rX   r_   Úintr�   r$   r!   r   ú<module>r�      së  ðð
ð ð Ð Ð Ð Ð Ð Ð Ð Ø IÐ IÐ IÐ IÐ IÐ IÐ IÐ IÐ IÐ IÐ IÐ IÐ IÐ IÐ IÐ IÐ IÐ IÐ IÐ IØ Ð Ð Ð Ð Ð à $Ð $Ð $Ð $Ð $Ð $à *Ð *Ð *Ð *Ð *Ð *Ø "Ð "Ð "Ð "Ð "Ð "Ø "Ð "Ð "Ð "Ð "Ð "Ø !Ð !Ð !Ð !Ð !Ð !Ø Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð à€f�h„h€ð ��S�Œ>€ð˜7ð  xð ð ð ð ð$ ð ¨gð ð ð ð ð$	
ð 	
ð 	ˆÐ3Ñ4Ô4Ø+Ð+Ø<Ð<ðð 	)Ð(ØˆÐ3Ñ4Ô4ØØð	ð€	ð& PÐOÀYÐOÑOÔO€ð˜(ð  vð ð ð ð ð # ð #¨Hð #ð #ð #ð #ð*8�xð 8 Cð 8ð 8ð 8ð 8ð>H˜Sð H Xð Hð Hð Hð Hð .4ðð Ø�ŒWðØ'*ðàðð ð ð ð: &*Øð_ð _ØˆsŒGð_à˜c”]ð_ð ð_ð ˆhÔð	_ð _ð _ð _ð _ð _r!   