HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //usr/lib/python3/dist-packages/twisted/logger/__pycache__/_format.cpython-38.pyc
U

\�[�0�@s�dZddlmZddlmZddlmZddlmZddl	m
Z
ddlmZm
Z
d	Zd
d�Zdd
�Zedfdd�Zefdd�ZGdd�de�Zdd�Zdd�Zdd�Zdd�Zdddefdd�Zd S)!z&
Tools for formatting logging events.
�)�datetime)�unicode)�Failure)�	safe_repr)�FixedOffsetTimeZone�)�
flatFormat�
aFormatterz%Y-%m-%dT%H:%M:%S%zcCst|dddd�S)�
    Formats an event as a L{unicode}, 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.
    @type event: L{dict}

    @return: A formatted string.
    @rtype: L{unicode}
    F)�includeTraceback�includeTimestamp�
includeSystem)�eventAsText)�event�r�8/usr/lib/python3/dist-packages/twisted/logger/_format.py�formatEvents�rcCs\zdj||d�WStk
rVt�}d�dd�|��D��}djt|�||d�YSXdS)	a(
    Formats an event as a L{unicode} that describes the event generically and a
    formatting error.

    @param event: A logging event.
    @type event: L{dict}

    @param error: The formatting error.
    @type error: L{Exception}

    @return: A formatted string.
    @rtype: L{unicode}
    z)Unable to format event {event!r}: {error})r�errorz, css(|] \}}d�t|�t|�f�VqdS)z = N)�joinr)�.0�key�valuerrr�	<genexpr>Is�z+formatUnformattableEvent.<locals>.<genexpr>zrMESSAGE LOST: unformattable object logged: {error}
Recoverable data: {text}
Exception during formatting:
{failure})r�failure�textN)�format�
BaseExceptionrr�itemsr)rrrrrrr�formatUnformattableEvent.s"��
���r�-cCs<|dks|dkr|St�|�}t�||�}t|�|��SdS)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.
    @type then: L{float}

    @param timeFormat: A time format.
    @type timeFormat: L{unicode} or L{None}

    @param default: Text to return if C{when} or C{timeFormat} is L{None}.
    @type default: L{unicode}

    @return: A formatted time.
    @rtype: L{unicode}
    N)rZfromLocalTimeStamp�DateTimeZ
fromtimestampr�strftime)ZwhenZ
timeFormat�defaultZtzrrrr�
formatTimeWs

r#cCs(t||d�}|sdS|�dd�}|dS)a�
    Format an event as a line of human-readable text for, e.g. traditional log
    file output.

    The output format is C{u"{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{u"#"}.  Each
          defaults to C{u"-"} is not set.

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

    Example::

        >>> from __future__ import print_function
        >>> from time import time
        >>> from twisted.logger import formatEventAsClassicLogText
        >>> from twisted.logger import LogLevel
        >>>
        >>> formatEventAsClassicLogText(dict())  # No format, returns None
        >>> formatEventAsClassicLogText(dict(log_format=u"Hello!"))
        u'- [-#-] Hello!\n'
        >>> formatEventAsClassicLogText(dict(
        ...     log_format=u"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=u"Hello!",
        ...     log_time=time(),
        ...     log_system="my_system",
        ... ))
        u'2013-11-11T17:22:06-0800 [my_system] Hello!\n'
        >>>

    @param event: an event.
    @type event: L{dict}

    @param formatTime: A time formatter
    @type formatTime: L{callable} that takes an C{event} argument and returns
        a L{unicode}

    @return: A formatted event, or L{None} if no output is appropriate.
    @rtype: L{unicode} or L{None}
    )r#N�
z
	)r�replace)rr#�	eventTextrrr�formatEventAsClassicLogText|s
3r'c@s eZdZdZdd�Zdd�ZdS)�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}.
    cCs
||_dS)zo
        @param submapping: Another read-only mapping which will be used to look
            up items.
        N)�_submapping)�selfZ
submappingrrr�__init__�szCallMapping.__init__cCs6|�d�}|r|dd�n|}|j|}|r2|�}|S)z|
        Look up an item in the submapping for this L{CallMapping}, calling it
        if C{key} ends with C{"()"}.
        z()N���)�endswithr))r*rZcallitZrealKeyrrrr�__getitem__�s

zCallMapping.__getitem__N)�__name__�
__module__�__qualname__�__doc__r+r.rrrrr(�sr(cCstt�|dt|���S)a0
    Format a string like L{unicode.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.
    @type formatString: L{unicode}

    @param mapping: A L{dict}-like object to format.

    @return: The string with formatted values interpolated.
    @rtype: L{unicode}
    r)rr	Zvformatr()ZformatString�mappingrrr�formatWithCall�s�r4c
Cs�zfd|krt|�WS|�dd�}|dkr.WdSt|t�rD|�d�}nt|t�s\td�|���t||�WSt	k
r�}zt
||�WY�Sd}~XYnXdS)r
Z
log_flattenedZ
log_formatN��utf-8z.Log format must be unicode or bytes, not {0!r})r�get�
isinstance�bytes�decoder�	TypeErrorrr4rr)rr�errr�_formatEvent�s


�r=c
CsXz$|��}t|t�r"|jddd�}Wn.tk
rR}zdt|�}W5d}~XYnX|S)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.
    @type failure: L{twisted.python.failure.Failure}

    @return: The formatted traceback.
    @rtype: L{unicode}
    r6r%)�errorsz((UNABLE TO OBTAIN TRACEBACK FROM EVENT):N)ZgetTracebackr8r9r:rr)r�	tracebackr<rrr�_formatTracebacks


�r@cCsv|�dd�}|dkrL|�dd�}|dkr.d}n|j}dj|�dd�|d�}n&zt|�}Wntk
rpd}YnX|S)	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{u"#"}.
    Each defaults to C{u"-"} is not set.  If formatting fails completely,
    "UNFORMATTABLE" is returned.

    @param event: The event containing the system specification.
    @type event: L{dict}

    @return: A formatted string representing the "log_system" key.
    @rtype: L{unicode}
    Z
log_systemNZ	log_levelrz{namespace}#{level}Z
log_namespace)�	namespace�levelZ
UNFORMATTABLE)r7�namerr�	Exception)r�systemrBZ	levelNamerrr�
_formatSystem4s

�
rFTc
Cs�t|�}|r2d|kr2|d}t|�}d�||f�}|s:|Sd}|r\d�||�dd��dg�}d}	|rzd�dt|�ddg�}	d	j||	|d
�S)aw
    Format an event as a unicode string.  Optionally, attach timestamp,
    traceback, and system information.

    The full output format is:
    C{u"{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{u"#"}.  Each
          defaults to C{u"-"} 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.
    @type event: L{dict}

    @param includeTraceback: If true and a C{"log_failure"} key exists, append
        a traceback.
    @type includeTraceback: L{bool}

    @param includeTimestamp: If true include a formatted timestamp before the
        event.
    @type includeTimestamp: L{bool}

    @param includeSystem:  If true, include the event's C{"log_system"} value.
    @type includeSystem: L{bool}

    @param formatTime: A time formatter
    @type formatTime: L{callable} that takes an C{event} argument and returns
        a L{unicode}

    @return: A formatted string with specified options.
    @rtype: L{unicode}

    @since: Twisted 18.9.0
    Zlog_failurer$r5Zlog_timeN� �[�]z{timeStamp}{system}{eventText})�	timeStamprEr&)r=r@rr7rFr)
rrrr
r#r&�fr?rJrErrrrVs.5��rN)r2rr Ztwisted.python.compatrZtwisted.python.failurerZtwisted.python.reflectrZtwisted.python._tzhelperrZ_flattenrr	ZtimeFormatRFC3339rrr#r'�objectr(r4r=r@rFrrrrr�<module>s*)%; '$�