%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/twisted/logger/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/twisted/logger/__pycache__/_json.cpython-312.pyc

�

Ϫ�f� �
���dZddlmZmZddlmZmZmZmZm	Z	m
Z
mZmZddl
mZddlmZddlmZddlmZdd	lmZdd
lmZddlmZddlmZe�ZeeefZd
edefd�Z dedefd�Z!d�ed�d�d�fd�ed�e e!fgZ"e"D����cic]
\}}}}||��c}}}}Z#dede$fd�Z%de$defd�Z&dedefd�Z'dedefd�Z(	d'd eed!edefd"�Z)		d(d$eed!e
ed%e*de	efd&�Z+y#cc}}}}w))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|j�t|jj|jj����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__rrr)rs �6/usr/lib/python3/dist-packages/twisted/logger/_json.py�
failureAsJSONr s?�������
��|�|�.�.��\�\�*�*�
����failureDictc�v�tjt�}|d}t|dd|�|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}
    rr�)r�__new__r�__dict__)r"�f�typeInfos   r�failureFromJSONr).s@��	���� �A��6�"�H��x�
�3�R��B�K����A�J��Hr!c�`�t|t�xrtt|jd�|uS�N)�
isinstancer�getattrr�name��levels r�<lambda>r1@s+���u�m�,�
=���%�*�*�d�3�u�<�r!z$02E59486-F24D-46AD-8224-3ACDF2A5732Ac�.�t|j��S)N)r.)rr.r/s rr1r1Es��d��
�
�+�r!c�*�tt|dd�S)Nr.)r-rr/s rr1r1Fs��g�h��f�
�t�<�r!c�"�t|t�Sr+)r,r)�os rr1r1Is
��*�Q��(�r!z$E76887E2-20ED-49BF-A8F8-BA25CC586F2D�aDictc�B�d|vrtt|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
)r6s r�objectLoadHookr:Ts,���5� ��D��'7�!8�9�:�5�A�A��Lr!�pythonObjectc�n�tD])\}}}}||�s�||�}t|�|d<|cSddiS)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.
    r8�
unpersistableT)�	classInfo�str)r;�	predicate�uuid�saver�loader�results      r�objectSaveHookrEdsO��+4��&�	�4����\�"��<�(�F�'*�4�y�F�#�$��M�	�

�T�"�"r!�eventc�n�dtdtttffd�}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.
    �unencodablerc�Z�t|t�r|jd�St|�S)z�
        Serialize an object not otherwise serializable by L{dumps}.

        @param unencodable: An unencodable object.

        @return: C{unencodable}, serialized
        �charmap)r,�bytes�decoderE)rHs r�defaultzeventAsJSON.<locals>.default�s*���k�5�)��%�%�i�0�0��k�*�*r!T)rM�skipkeys)�objectr�JSONDictr?rr)rFrMs  r�eventAsJSONrQys7��
+�V�
+��h��m�(<�
+�������$�7�7r!�	eventTextc�@�ttt|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rPrr:)rRs r�
eventFromJSONrU�s����%�	�~�F�G�Gr!�outFile�recordSeparatorc�"��t|�fd��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�
)rQ)rFrWs �rr1z%jsonFileLogObserver.<locals>.<lambda>�s���/�!2�;�u�3E�2F�b�I�r!r)rVrWs `r�jsonFileLogObserverr[�s���,��I��r!N�inFile�
bufferSizec#��K�dtdtfd�}dtdttfd��|�"||jd��}|dk(r|}n
d	}n
||�}d	}|d	k(rd
}�}ndtdttf�fd�}t|�}	|j|�}|st
|�dkDr||�}	|	�|	��y|||�z
}|j|�}
|
dd
D] }t
|�dkDs�||�}	|	��|	���"|
d
}�z�w)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}.
    �src�H�t|t�r|S|jd�S)N�utf-8)r,rK�encode)r_s r�asBytesz&eventsFromJSONLogFile.<locals>.asBytes�s ���a����H��8�8�G�$�$r!�recordc��	t|�jd�}	t|�S#t$r#tj	dt|���YywxYw#t$r#tj	dt|���YywxYw)Nraz2Unable to decode UTF-8 for JSON record: {record!r}�rdz&Unable to read JSON record: {record!r})rKrL�UnicodeDecodeError�log�errorrU�
ValueError)rd�texts  r�eventFromBytearrayz1eventsFromJSONLogFile.<locals>.eventFromBytearray�s���	���=�'�'��0�D�	� ��&�&��"�	��I�I�D��V�}�
�
��	���	��I�I�>�u�V�}�I�U��	�s �(�
A�)A�A�)B�BNr�r!�
c�x��|dtd�k(r�|�Stjdt|���y)N���rZz0Unable to read truncated JSON record: {record!r}rf)�ordrhrirK)rdrls �r�eventFromRecordz.eventsFromJSONLogFile.<locals>.eventFromRecord�s>����b�z�S��Y�&�)�&�1�1��	�	�F� ��=���r!rrp)rrK�	bytearrayr
r�read�len�split)
r\rWr]rc�first�recordSeparatorBytesrr�buffer�newDatarF�recordsrdrls
            @r�eventsFromJSONLogFiler|�sE�����(%�6�%�e�%��9���(�1C�� ������A��'���G��#(� �$'� � '��7�����s�"�$��,��	�I�	�(�8�2D�	��u�
�F�
��+�+�j�)����6�{�Q��'��/���$��K���'�'�"�"���,�,�3�4���c�r�l�	 �F��6�{�Q��'��/���$��K�		 �����'�s�C'D�+
D�6D)�)Ni),�__doc__�jsonrr�typingrrrrr	r
rrrAr
�
constantlyr�twisted.python.failurer�_filer�_flattenr�_interfacesr�_levelsr�_loggerrrhr?rPr r)r>r9rOr:rErQrUr[�intr|)r@rArBrCs0000r�<module>r�s���
��I�I�I��$�*�"�"�!����h����S��>���7��x��$

��

�g�

�$	
�	
�
3�4�+�<��	)��
3�4���	�
�	�&FO�O�O�!A�)�T�5�&��f��O��
�(�
�v�
� #��#�H�#�*8�x�8�C�8�>H�S�H�X�H�.4��
��W��'*����:&*��_��s�G�_��c�]�_��_��h��	_��[Ps�C-

Zerion Mini Shell 1.0