%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__/_format.cpython-312.pyc

�

Ϫ�f�4��\�dZddlmZddlmZddlmZmZmZm	Z	m
Z
mZmZddl
mZddlmZddlmZddlmZd	d
lmZmZd	dlmZdZdd
�Zdd�Zedf							d d�Zef					d!d�Zd"d�ZGd�de �Z!Gd�de	e"ef�Z#d#d�Z$dd�Z%d$d�Z&dd�Z'dddef											d%d�Z(y)&z&
Tools for formatting logging events.
�)�annotations)�datetime)�Any�Callable�Iterator�Mapping�Optional�Union�cast)�
NamedConstant)�FixedOffsetTimeZone)�Failure)�	safe_repr�)�
aFormatter�
flatFormat)�LogEventz%Y-%m-%dT%H:%M:%S%zc� �t|ddd��S)aa
    Formats an event as text, using the format in C{event["log_format"]}.

    This implementation should never raise an exception; if the formatting
    cannot be done, the returned string will describe the event generically so
    that a useful message is emitted regardless.

    @param event: A logging event.

    @return: A formatted string.
    F)�includeTraceback�includeTimestamp�
includeSystem)�eventAsText)�events �8/usr/lib/python3/dist-packages/twisted/logger/_format.py�formatEventrs���
����	��c���	dj||��S#t$rPt�}djd�|j	�D��}djt|�||��cYSwxYw)z�
    Formats an event as text that describes the event generically and a
    formatting error.

    @param event: A logging event.
    @param error: The formatting error.

    @return: A formatted string.
    z)Unable to format event {event!r}: {error})r�errorz, c3�lK�|],\}}djt|�t|�f����.y�w)z = N)�joinr)�.0�key�values   r�	<genexpr>z+formatUnformattableEvent.<locals>.<genexpr>Cs3����
���U�
�J�J�	�#��	�%�(8�9�:�
�s�24zrMESSAGE LOST: unformattable object logged: {error}
Recoverable data: {text}
Exception during formatting:
{failure})r�failure�text)�format�
BaseExceptionrr �itemsr)rrr%r&s    r�formatUnformattableEventr*-s���
�:�A�A��u�B�
�	
���
��)���y�y�
�#�k�k�m�
�
��
6�6<�f���&��d�7=�7�	
�
�s��AA.�-A.�-c��|�|�|Stj|�}tj||�}t	|j|��S)a�
    Format a timestamp as text.

    Example::

        >>> from time import time
        >>> from twisted.logger import formatTime
        >>>
        >>> t = time()
        >>> formatTime(t)
        u'2013-10-22T14:19:11-0700'
        >>> formatTime(t, timeFormat="%Y/%W")  # Year and week number
        u'2013/42'
        >>>

    @param when: A timestamp.
    @param timeFormat: A time format.
    @param default: Text to return if C{when} or C{timeFormat} is L{None}.

    @return: A formatted time.
    )r
�fromLocalTimeStamp�DateTime�
fromtimestamp�str�strftime)�when�
timeFormat�default�tzrs     r�
formatTimer6QsK��4��T�\���
 �
3�
3�D�
9���)�)�$��3���8�$�$�Z�0�1�1rc�P�t||��}|sy|jdd�}|dzS)a&
    Format an event as a line of human-readable text for, e.g. traditional log
    file output.

    The output format is C{"{timeStamp} [{system}] {event}\n"}, where:

        - C{timeStamp} is computed by calling the given C{formatTime} callable
          on the event's C{"log_time"} value

        - C{system} is the event's C{"log_system"} value, if set, otherwise,
          the C{"log_namespace"} and C{"log_level"}, joined by a C{"#"}.  Each
          defaults to C{"-"} is not set.

        - C{event} is the event, as formatted by L{formatEvent}.

    Example::

        >>> from time import time
        >>> from twisted.logger import formatEventAsClassicLogText
        >>> from twisted.logger import LogLevel
        >>>
        >>> formatEventAsClassicLogText(dict())  # No format, returns None
        >>> formatEventAsClassicLogText(dict(log_format="Hello!"))
        u'- [-#-] Hello!\n'
        >>> formatEventAsClassicLogText(dict(
        ...     log_format="Hello!",
        ...     log_time=time(),
        ...     log_namespace="my_namespace",
        ...     log_level=LogLevel.info,
        ... ))
        u'2013-10-22T17:30:02-0700 [my_namespace#info] Hello!\n'
        >>> formatEventAsClassicLogText(dict(
        ...     log_format="Hello!",
        ...     log_time=time(),
        ...     log_system="my_system",
        ... ))
        u'2013-11-11T17:22:06-0800 [my_system] Hello!\n'
        >>>

    @param event: an event.
    @param formatTime: A time formatter

    @return: A formatted event, or L{None} if no output is appropriate.
    )r6N�
z
	)r�replace)rr6�	eventTexts   r�formatEventAsClassicLogTextr;ss4��^�E�j�9�I����!�!�$��/�I��t��r�PotentialCallWrapperc�n�|jd�}|r|ddn|}||�}|r|�}t|�S)at
    Check to see if C{key} ends with parentheses ("C{()}"); if not, wrap up the
    result of C{get} in a L{PotentialCallWrapper}.  Otherwise, call the result
    of C{get} first, before wrapping it up.

    @param key: The last dotted segment of a formatting key, as parsed by
        L{Formatter.vformat}, which may end in C{()}.

    @param getter: A function which takes a string and returns some other
        object, to be formatted and stringified for a log.

    @return: A L{PotentialCallWrapper} that will wrap up the result to allow
        for subsequent usages of parens to defer execution to log-format time.
    z()N���)�endswithr<)r"�getter�callit�realKeyr#s     r�keycallrC�s?���\�\�$�
�F� �c�#�2�h�c�G��7�O�E�
������&�&rc�@�eZdZdZd	d�Zd
d�Zd
d�Zdd�Zdd�Zdd�Z	y)
r<z
    Object wrapper that wraps C{getattr()} so as to process call-parentheses
    C{"()"} after a dotted attribute access.
    c��||_y�N)�_wrapped)�self�wrappeds  r�__init__zPotentialCallWrapper.__init__�s	����
rc�B�t||jj�SrF)rCrG�__getattribute__)rH�names  r�__getattr__z PotentialCallWrapper.__getattr__�s���t�T�]�]�;�;�<�<rc�6�|j|}t|�SrF)rGr<)rHrMr#s   r�__getitem__z PotentialCallWrapper.__getitem__�s���
�
�d�#��#�E�*�*rc�8�|jj|�SrF)rG�
__format__)rH�format_specs  rrRzPotentialCallWrapper.__format__�s���}�}�'�'��4�4rc�6�|jj�SrF)rG�__repr__�rHs rrUzPotentialCallWrapper.__repr__�s���}�}�%�%�'�'rc�6�|jj�SrF)rG�__str__rVs rrXzPotentialCallWrapper.__str__�s���}�}�$�$�&�&rN)rI�object�return�None)rMr0rZrY)rSr0rZr0)rZr0)
�__name__�
__module__�__qualname__�__doc__rJrNrPrRrUrX�rrr<r<�s%���
 �=�+�5�(�'rc�0�eZdZdZdd�Zdd�Zd	d�Zd
d�Zy)�CallMappingz�
    Read-only mapping that turns a C{()}-suffix in key names into an invocation
    of the key rather than a lookup of the key.

    Implementation support for L{formatWithCall}.
    c��||_y)zo
        @param submapping: Another read-only mapping which will be used to look
            up items.
        N)�_submapping)rH�
submappings  rrJzCallMapping.__init__�s��
&��rc�,�t|j�SrF)�iterrdrVs r�__iter__zCallMapping.__iter__�s���D�$�$�%�%rc�,�t|j�SrF)�lenrdrVs r�__len__zCallMapping.__len__�s���4�#�#�$�$rc�B�t||jj�S)z|
        Look up an item in the submapping for this L{CallMapping}, calling it
        if C{key} ends with C{"()"}.
        )rCrdrP)rHr"s  rrPzCallMapping.__getitem__�s��
�s�D�,�,�8�8�9�9rN)re�Mapping[str, Any]rZr[)rZz
Iterator[Any])rZ�int)r"r0rZr)r\r]r^r_rJrhrkrPr`rrrbrb�s���&�&�%�:rrbc	�T�ttj|dt|���S)a�
    Format a string like L{str.format}, but:

        - taking only a name mapping; no positional arguments

        - with the additional syntax that an empty set of parentheses
          correspond to a formatting item that should be called, and its result
          C{str}'d, rather than calling C{str} on the element directly as
          normal.

    For example::

        >>> formatWithCall("{string}, {function()}.",
        ...                dict(string="just a string",
        ...                     function=lambda: "a function"))
        'just a string, a function.'

    @param formatString: A PEP-3101 format string.
    @param mapping: A L{dict}-like object to format.

    @return: The string with formatted values interpolated.
    r`)r0r�vformatrb)�formatString�mappings  r�formatWithCallrs�s#��.�z�!�!�,��K��4H�I�J�Jrc�n�	d|vrt|�Sttttt
f|j
dd��}|�yt|t�rn0t|t
�r|jd�}ntd|����t||�S#t$r}t||�cYd}~Sd}~wwxYw)ae
    Formats an event as a string, using the format in C{event["log_format"]}.

    This implementation should never raise an exception; if the formatting
    cannot be done, the returned string will describe the event generically so
    that a useful message is emitted regardless.

    @param event: A logging event.

    @return: A formatted string.
    �
log_flattened�
log_formatN�zutf-8zLog format must be str, not )
rrr	r
r0�bytes�get�
isinstance�decode�	TypeErrorrsr(r*)rr'�es   r�_formatEventr~s���2��e�#��e�$�$��h�u�S�%�Z�0�1�5�9�9�\�4�3P�Q���>���f�c�"��
���
&��]�]�7�+�F��:�6�*�E�F�F��f�e�,�,���2�'��q�1�1��2�s)�B�6B�AB�	B4�B/�)B4�/B4c�r�	|j�}|S#t$r}dt|�z}Yd}~|Sd}~wwxYw)a^
    Format a failure traceback, assuming UTF-8 and using a replacement
    strategy for errors.  Every effort is made to provide a usable
    traceback, but should not that not be possible, a message and the
    captured exception are logged.

    @param failure: The failure to retrieve a traceback from.

    @return: The formatted traceback.
    z((UNABLE TO OBTAIN TRACEBACK FROM EVENT):N)�getTracebackr(r0)r%�	tracebackr}s   r�_formatTracebackr�5sF��H��(�(�*�	�����H�>��Q��G�	����H�s��	6�1�6c	�j�ttt|jdd��}|�kttt|jdd��}|�d}n|j
}dj
tt|jdd��|��}|S	t|�}|S#t$rd}Y|SwxYw)	a�
    Format the system specified in the event in the "log_system" key if set,
    otherwise the C{"log_namespace"} and C{"log_level"}, joined by a C{"#"}.
    Each defaults to C{"-"} is not set.  If formatting fails completely,
    "UNFORMATTABLE" is returned.

    @param event: The event containing the system specification.

    @return: A formatted string representing the "log_system" key.
    �
log_systemN�	log_levelr+z{namespace}#{level}�
log_namespace)�	namespace�level�
UNFORMATTABLE)rr	r0ryrrMr'�	Exception)r�systemr��	levelNames    r�
_formatSystemr�Gs����(�3�-����<��!>�
?�F�
�~��X�m�,�e�i�i��T�.J�K���=��I��
�
�I�&�-�-��3��	�	�/�3� ?�@��.�
���M�		%���[�F��M���	%�$�F��M�	%�s�B#�#B2�1B2Tc�T�t|�}|r'd|vr#|d}t|�}dj||f�}|s|Sd}|r7dj|tt|jdd���dg�}d}	|rdjdt
|�ddg�}	d	j||	|�
�S)ah
    Format an event as text.  Optionally, attach timestamp, traceback, and
    system information.

    The full output format is:
    C{"{timeStamp} [{system}] {event}\n{traceback}\n"} where:

        - C{timeStamp} is the event's C{"log_time"} value formatted with
          the provided C{formatTime} callable.

        - C{system} is the event's C{"log_system"} value, if set, otherwise,
          the C{"log_namespace"} and C{"log_level"}, joined by a C{"#"}.  Each
          defaults to C{"-"} is not set.

        - C{event} is the event, as formatted by L{formatEvent}.

        - C{traceback} is the traceback if the event contains a
          C{"log_failure"} key.  In the event the original traceback cannot
          be formatted, a message indicating the failure will be substituted.

    If the event cannot be formatted, and no traceback exists, an empty string
    is returned, even if includeSystem or includeTimestamp are true.

    @param event: A logging event.
    @param includeTraceback: If true and a C{"log_failure"} key exists, append
        a traceback.
    @param includeTimestamp: If true include a formatted timestamp before the
        event.
    @param includeSystem:  If true, include the event's C{"log_system"} value.
    @param formatTime: A time formatter

    @return: A formatted string with specified options.

    @since: Twisted 18.9.0
    �log_failurer8rw�log_timeN� �[�]z{timeStamp}{system}{eventText})�	timeStampr�r:)r~r�r r�floatryr�r')
rrrrr6r:�fr�r�r�s
          rrrfs���T�U�#�I��M�U�2��-� ��$�Q�'�	��I�I�y�)�4�5�	�����I���G�G�Z��U�E�I�I�j�$�4O�(P�Q�SV�W�X�	�
�F�����#�}�U�3�S�#�>�?��+�2�2����3��rN)rrrZr0)rrrr(rZr0)r2zOptional[float]r3�
Optional[str]r4r0rZr0)rrr6z Callable[[Optional[float]], str]rZr�)r"r0r@zCallable[[str], Any]rZr<)rqr0rrrmrZr0)r%rrZr0)rrr�boolrr�rr�r6zCallable[[float], str]rZr0))r_�
__future__rrr.�typingrrrrr	r
r�
constantlyr�twisted.python._tzhelperr
�twisted.python.failurer�twisted.python.reflectr�_flattenrr�_interfacesr�timeFormatRFC3339rr*r6r;rCrYr<r0rbrsr~r�r�rr`rr�<module>r�s��
�#�)�J�J�J�$�8�*�,�,�!�)���(!
�L!2��2�
�2��2��2�	�	2�FEO�3��3�!A�3��3�l'�.'�6�'�8:�'�#�s�(�#�:�:K�42�D�$�B"�!��)3�?��?��?��?��	?�
'�?�	�
?r

Zerion Mini Shell 1.0