+
    Dfj               
          R t ^ RIHtHt ^ RIHtHtHtHtH	t	H
t
HtHt ^ RIHt ^ RIHt ^ RIHt ^RIHt ^RIHt ^RIHt ^R	IHt ^R
IHt ]! 4       t]]]3,          tR R lt R R lt!R ]! R4      R R 3R ]! R4      ] ]!3.t"]" U UUUu/ uF  w  rr#WbK
  	  upppp t#R R lt$R R lt%R R lt&R R lt'R"R R llt(R#R  R! llt)R# u upppp i )$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)Loggerc                0    V ^8  d   QhR\         R\        /# )   failurereturn)r   JSONDict)formats   "6/usr/lib/python3/dist-packages/twisted/logger/_json.py__annotate__r      s      7 x     c                    \        V P                  4       \        V P                  P                  V P                  P                  R7      R7      # )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   &r   failureAsJSONr$      s?     ||..\\**
 r   c                0    V ^8  d   QhR\         R\        /# )r   failureDictr   )r   r   )r   s   "r   r   r   .   s       g r   c                    \         P                  ! \         4      pV R,          p\        VR,          RV4      V R&   VP                  V 4       V# )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-   .   sE     	 A6"Hx
3RBKNN;Hr   c                 l    \        V \        4      ;'       d    \        \        V P                  R 4      V J # N)
isinstancer   getattrr   namelevels   &r   <lambda>r5   @   s0    um, = =%**d3u<=r   z$02E59486-F24D-46AD-8224-3ACDF2A5732Ac                 .    \        V P                  R 7      # ))r2   )r"   r2   r3   s   &r   r5   r5   E   s    d

+r   c                 2    \        \        V R ,          R4      # )r2   N)r1   r   r3   s   &r   r5   r5   F   s    ghft<r   c                 "    \        V \        4      # r/   )r0   r   )os   &r   r5   r5   I   s    *Q(r   z$E76887E2-20ED-49BF-A8F8-BA25CC586F2Dc                0    V ^8  d   QhR\         R\        /# )r   aDictr   )r   object)r   s   "r   r   r   T   s      ( v r   c                Z    RV 9   d$   \         \        V R,          4      ,          ! V 4      # V # )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   objectLoadHookr@   T   s,     5 D'7!89:5AALr   c                0    V ^8  d   QhR\         R\        /# )r   pythonObjectr   )r<   r   )r   s   "r   r   r   d   s     # # #H #r   c                z    \          F.  w  rr4V! V 4      '       g   K  V! V 4      p\        V4      VR&   Vu # 	  RR/# )am  
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   	predicateuuidsaverloaderresults   &     r   objectSaveHookrL   d   sI     +4&	\""<(F'*4yF#$M	 +4
 T""r   c                0    V ^8  d   QhR\         R\        /# )r   eventr   )r   rF   )r   s   "r   r   r   y   s     8 8x 8C 8r   c                >    R R lp\        V 4       \        WRR7      # )at  
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.
c                R    V ^8  d   QhR\         R\        \        \        3,          /# )r   unencodabler   )r<   r
   r   rF   )r   s   "r   r   !eventAsJSON.<locals>.__annotate__   s#     
+ 
+V 
+hm(< 
+r   c                f    \        V \        4      '       d   V P                  R4      # \        V 4      # )z
Serialize an object not otherwise serializable by L{dumps}.

@param unencodable: An unencodable object.

@return: C{unencodable}, serialized
charmap)r0   bytesdecoderL   )rQ   s   &r   defaulteventAsJSON.<locals>.default   s-     k5))%%i00k**r   T)rW   skipkeys)r   r   )rN   rW   s   & r   eventAsJSONrZ   y   s    
+ $77r   c                0    V ^8  d   QhR\         R\        /# )r   	eventTextr   )rF   r   )r   s   "r   r   r      s     H HS HX Hr   c                @    \        \        \        V \        R7      4      # )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   r   r   r@   )r\   s   &r   eventFromJSONr_      s     %	~FGGr   c                R    V ^8  d   QhR\         \        ,          R\        R\        /# )r   outFilerecordSeparatorr   )r   r   rF   r   )r   s   "r   r   r      s(      W'*r   c                $   a \        V V3R l4      # )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                 $   < S \        V 4       R 2# )
)rZ   )rN   rb   s   &r   r5   %jsonFileLogObserver.<locals>.<lambda>   s    /!2;u3E2FbIr   r   )ra   rb   s   &fr   jsonFileLogObserverrg      s    , I r   Nc          	          V ^8  d   QhR\         \        ,          R\        \        ,          R\        R\
        \        ,          /# )r   inFilerb   
bufferSizer   )r   r   r	   rF   intr   r   )r   s   "r   r   r      sC     _ _sG_c]_ _ h	_r   c              #    a"   R R lpR R loVf%   V! V P                  ^4      4      pVR8X  d   TpMRpM
V! V4      pRpVR8X  d   RpSpM	R	 V3R
 llp\        V4      p V P                  V4      pV'       g#   \        V4      ^ 8  d   V! V4      p	V	e   V	x  R# Ws! V4      ,          pVP                  V4      p
V
RR  F'  p\        V4      ^ 8  g   K  V! V4      p	V	f   K#  V	x  K)  	  V
R,          pK  5i)a!  
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}.
c                0    V ^8  d   QhR\         R\        /# )r   sr   )r   rU   )r   s   "r   r   +eventsFromJSONLogFile.<locals>.__annotate__   s     % %6 %e %r   c                 T    \        V \        4      '       d   V # V P                  R 4      # )utf-8)r0   rU   encode)rn   s   &r   asBytes&eventsFromJSONLogFile.<locals>.asBytes   s#    aH88G$$r   c                F    V ^8  d   QhR\         R\        \        ,          /# r   recordr   	bytearrayr	   r   )r   s   "r   r   ro      s      9 (1C r   c                     \        V 4      P                  R 4      p \        T4      #   \         d%    \        P	                  R\        T 4      R7        R# i ; i  \         d%    \        P	                  R\        T 4      R7        R# i ; i)rq   z2Unable to decode UTF-8 for JSON record: {record!r}rw   Nz&Unable to read JSON record: {record!r})rU   rV   UnicodeDecodeErrorlogerrorr_   
ValueError)rw   texts   & r   eventFromBytearray1eventsFromJSONLogFile.<locals>.eventFromBytearray   s    	=''0D	 && " 	IIDV}   	  	II>uV}IU	s    ( 
A +AA+B	B	N   r      
c                F    V ^8  d   QhR\         R\        \        ,          /# rv   rx   )r   s   "r   r   ro      s     	 	I 	(82D 	r   c                    < V R,          \        R4      8X  d	   S! V 4      # \        P                  R\        V 4      R7       R# )   re   z0Unable to read truncated JSON record: {record!r}r{   N)ordr}   r~   rU   )rw   r   s   &r   eventFromRecord.eventsFromJSONLogFile.<locals>.eventFromRecord   s>    bzSY&)&11		F =   r   r   )readry   lensplit)ri   rb   rj   rs   firstrecordSeparatorBytesr   buffernewDatarN   recordsrw   r   s   &&&         @r   eventsFromJSONLogFiler      s    (%  A'G#(  $'   '7s"$,	 	 uF
++j)6{Q'/$K''"",,34crlF6{Q'/$K	 # s   A8C8<AC8	C8%C8))Ni   )*__doc__jsonr   r   typingr   r   r   r   r   r	   r
   r   rH   r   
constantlyr   twisted.python.failurer   _filer   _flattenr   _interfacesr   _levelsr   _loggerr   r}   rF   r   r$   r-   rE   r?   r@   rL   rZ   r_   rg   r   )rG   rH   rI   rJ   s   0000r   <module>r      s   
  I I I  $ * " " !  h S>$$	
 	34+< 	)34		& FOOY!A)5YO #*8>H6_ _[ Ps   C
