§
    Ètºf¨4  ã                  óB  — d Z ddlmZ ddlmZ ddl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mZ d	dlmZ dZd8d„Zd9d„Zedfd:d„Zefd;d„Zd<d#„Z G d$„ d"e ¦  «        Z! G d%„ d&e	e"ef         ¦  «        Z#d=d*„Z$d8d+„Z%d>d.„Z&d8d/„Z'd0d0d0efd?d6„Z(d7S )@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%zÚeventr   ÚreturnÚstrc                ó(   — t          | ddd¬¦  «        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)r   s    úU/var/www/surfInsights/venv3-11/lib/python3.11/site-packages/twisted/logger/_format.pyÚformatEventr      s'   € õ ØØØØð	ñ ô ð ó    ÚerrorÚBaseExceptionc                ó  — 	 d                      | |¬¦  «        S # t          $ rg t          ¦   «         }d                     d„ |                      ¦   «         D ¦   «         ¦  «        }d                      t          |¦  «        ||¬¦  «        cY S w xY w)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   r   z, c              3  ó~   K  — | ]8\  }}d                       t          |¦  «        t          |¦  «        f¦  «        V — Œ9dS )z = N)Újoinr   )Ú.0ÚkeyÚvalues      r   ú	<genexpr>z+formatUnformattableEvent.<locals>.<genexpr>C   sY   è è € ð 
ð 
á��Uð �JŠJ�	 #™œ­	°%Ñ(8Ô(8Ð9Ñ:Ô:ð
ð 
ð 
ð 
ð 
ð 
r   zrMESSAGE LOST: unformattable object logged: {error}
Recoverable data: {text}
Exception during formatting:
{failure})r   ÚfailureÚtext)Úformatr    r   r#   Úitemsr   )r   r   r(   r)   s       r   ÚformatUnformattableEventr,   -   sÀ   € ð
Ø:×AÒAØ˜uð Bñ 
ô 
ð 	
øõ ð 
ð 
ð 
õ ‘)”)ˆà�yŠyð 
ð 
à#Ÿkšk™mœmð
ñ 
ô 
ñ 
ô 
ˆð6ç6<²fÝ Ñ&Ô&°¸dð 7=ñ 7ô 7ð	
ð 	
ð 	
ð
øøøs   ‚ ™A.B
Â	B
ú-ÚwhenúOptional[float]Ú
timeFormatúOptional[str]Údefaultc                ó¤   — |�| €|S t          j        | ¦  «        }t          j        | |¦  «        }t	          |                     |¦  «        ¦  «        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Úfromtimestampr   Ústrftime)r.   r0   r2   Útzr   s        r   Ú
formatTimer9   Q   sQ   € ð4 Ð˜T˜\Øˆå Ô3°DÑ9Ô9ˆÝÔ)¨$°Ñ3Ô3ˆÝ�8×$Ò$ ZÑ0Ô0Ñ1Ô1Ð1r   r9   ú Callable[[Optional[float]], str]c                ób   — t          | |¬¦  «        }|sdS |                     dd¦  «        }|dz   S )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.
    )r9   Nú
z
	)r   Úreplace)r   r9   Ú	eventTexts      r   ÚformatEventAsClassicLogTextr?   s   sD   € õ^ ˜E¨jÐ9Ñ9Ô9€IØð ØˆtØ×!Ò! $¨Ñ/Ô/€IØ�tÑÐr   r%   ÚgetterúCallable[[str], Any]ÚPotentialCallWrapperc                ó”   — |                       d¦  «        }|r
| dd…         n| } ||¦  «        }|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éþÿÿÿ)ÚendswithrB   )r%   r@   ÚcallitÚrealKeyr&   s        r   ÚkeycallrH   ©   sY   € ð �\Š\˜$ÑÔ€FØ Ð)ˆc�#�2�#Œhˆh c€GØˆF�7‰OŒO€EØð Ø�‘”ˆÝ Ñ&Ô&Ð&r   c                  óB   — e Zd ZdZdd„Zdd	„Zdd
„Zdd„Zdd„Zdd„Z	dS )rB   z
    Object wrapper that wraps C{getattr()} so as to process call-parentheses
    C{"()"} after a dotted attribute access.
    ÚwrappedÚobjectr   ÚNonec                ó   — || _         d S ©N)Ú_wrapped)ÚselfrJ   s     r   Ú__init__zPotentialCallWrapper.__init__Æ   s   € ØˆŒˆˆr   Únamer   c                ó6   — t          || j        j        ¦  «        S rN   )rH   rO   Ú__getattribute__)rP   rR   s     r   Ú__getattr__z PotentialCallWrapper.__getattr__É   s   € Ý�t˜Tœ]Ô;Ñ<Ô<Ð<r   c                ó:   — | j         |         }t          |¦  «        S rN   )rO   rB   )rP   rR   r&   s      r   Ú__getitem__z PotentialCallWrapper.__getitem__Ì   s   € ð ”˜dÔ#ˆÝ# EÑ*Ô*Ð*r   Úformat_specc                ó6   — | j                              |¦  «        S rN   )rO   Ú
__format__)rP   rX   s     r   rZ   zPotentialCallWrapper.__format__Ò   s   € ØŒ}×'Ò'¨Ñ4Ô4Ð4r   c                ó4   — | j                              ¦   «         S rN   )rO   Ú__repr__©rP   s    r   r\   zPotentialCallWrapper.__repr__Õ   s   € ØŒ}×%Ò%Ñ'Ô'Ð'r   c                ó4   — | j                              ¦   «         S rN   )rO   Ú__str__r]   s    r   r_   zPotentialCallWrapper.__str__Ø   s   € ØŒ}×$Ò$Ñ&Ô&Ð&r   N)rJ   rK   r   rL   )rR   r   r   rK   )rX   r   r   r   )r   r   )
Ú__name__Ú
__module__Ú__qualname__Ú__doc__rQ   rU   rW   rZ   r\   r_   © r   r   rB   rB   À   s–   € € € € € ðð ð
 ð  ð  ð  ð=ð =ð =ð =ð+ð +ð +ð +ð5ð 5ð 5ð 5ð(ð (ð (ð (ð'ð 'ð 'ð 'ð 'ð 'r   c                  ó2   — e Zd ZdZdd„Zdd„Zdd
„Zdd„ZdS )Ú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}.
    Ú
submappingúMapping[str, Any]r   rL   c                ó   — || _         dS )zo
        @param submapping: Another read-only mapping which will be used to look
            up items.
        N)Ú_submapping)rP   rg   s     r   rQ   zCallMapping.__init__ä   s   € ð
 &ˆÔÐÐr   úIterator[Any]c                ó*   — t          | j        ¦  «        S rN   )Úiterrj   r]   s    r   Ú__iter__zCallMapping.__iter__ë   s   € Ý�DÔ$Ñ%Ô%Ð%r   Úintc                ó*   — t          | j        ¦  «        S rN   )Úlenrj   r]   s    r   Ú__len__zCallMapping.__len__î   s   € Ý�4Ô#Ñ$Ô$Ð$r   r%   r   r   c                ó6   — t          || j        j        ¦  «        S )z|
        Look up an item in the submapping for this L{CallMapping}, calling it
        if C{key} ends with C{"()"}.
        )rH   rj   rW   )rP   r%   s     r   rW   zCallMapping.__getitem__ñ   s   € õ
 �s˜DÔ,Ô8Ñ9Ô9Ð9r   N)rg   rh   r   rL   )r   rk   )r   ro   )r%   r   r   r   )r`   ra   rb   rc   rQ   rn   rr   rW   rd   r   r   rf   rf   Ü   sn   € € € € € ðð ð&ð &ð &ð &ð&ð &ð &ð &ð%ð %ð %ð %ð:ð :ð :ð :ð :ð :r   rf   ÚformatStringÚmappingrh   c           	     ób   — t          t          j        | dt          |¦  «        ¦  «        ¦  «        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.
    rd   )r   r   Úvformatrf   )rt   ru   s     r   ÚformatWithCallrx   ù   s)   € õ. �zÔ! ,°µKÀÑ4HÔ4HÑIÔIÑJÔJÐJr   c                óÒ  — 	 d| v rt          | ¦  «        S t          t          t          t          t
          f                  |                      dd¦  «        ¦  «        }|€dS t          |t          ¦  «        rn=t          |t
          ¦  «        r|                     d¦  «        }nt          d|›�¦  «        ‚t          || ¦  «        S # t          $ r}t          | |¦  «        cY d}~S d}~ww xY w)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Ú zutf-8zLog format must be str, not )r   r   r	   r
   r   ÚbytesÚgetÚ
isinstanceÚdecodeÚ	TypeErrorrx   r    r,   )r   r*   Úes      r   Ú_formatEventrƒ     sø   € ð2Ø˜eÐ#Ð#Ý˜eÑ$Ô$Ð$å•h�u¥S­% ZÔ0Ô1°5·9²9¸\È4Ñ3PÔ3PÑQÔQˆØˆ>Ø�2õ �f�cÑ"Ô"ð 	GØÝ˜¥Ñ&Ô&ð 	GØ—]’] 7Ñ+Ô+ˆFˆFåÐE¸6ÐEÐEÑFÔFÐFå˜f eÑ,Ô,Ð,øåð 2ð 2ð 2Ý'¨¨qÑ1Ô1Ð1Ð1Ð1Ð1Ð1Ð1øøøøð2øøøs*   ‚C •AC ÁA"C Ã
C&ÃC!ÃC&Ã!C&r(   r   c                ó„   — 	 |                       ¦   «         }n)# t          $ r}dt          |¦  «        z   }Y d}~nd}~ww xY w|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.

    @return: The formatted traceback.
    z((UNABLE TO OBTAIN TRACEBACK FROM EVENT):N)ÚgetTracebackr    r   )r(   Ú	tracebackr‚   s      r   Ú_formatTracebackr‡   5  s^   € ðHØ×(Ò(Ñ*Ô*ˆ	ˆ	øÝð Hð Hð HØ>ÅÀQÁÄÑGˆ	ˆ	ˆ	ˆ	ˆ	ˆ	øøøøðHøøøàÐs   ‚ —
=¡8¸=c           	     ó¶  — t          t          t                   |                      dd¦  «        ¦  «        }|€t          t          t                   |                      dd¦  «        ¦  «        }|€d}n|j        }d                     t          t          |                      dd¦  «        ¦  «        |¬¦  «        }n#	 t          |¦  «        }n# t          $ r d}Y nw xY w|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{"#"}.
    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)r   r	   r   r~   r   rR   r*   Ú	Exception)r   Úsystemr�   Ú	levelNames       r   Ú_formatSystemr’   G  sÔ   € õ •(�3”- §¢¨<¸Ñ!>Ô!>Ñ?Ô?€FØ€~Ý•X�mÔ,¨e¯iªi¸ÀTÑ.JÔ.JÑKÔKˆØˆ=ØˆIˆIàœ
ˆIà&×-Ò-Ý�3 §	¢	¨/¸3Ñ ?Ô ?Ñ@Ô@Øð .ñ 
ô 
ˆˆð
	%Ý˜‘[”[ˆFˆFøÝð 	%ð 	%ð 	%Ø$ˆFˆFˆFð	%øøøà€Ms   Â7C ÃCÃCTr   Úboolr   r   úCallable[[float], str]c                óª  — t          | ¦  «        }|r2d| v r.| d         }t          |¦  «        }d                     ||f¦  «        }|s|S d}|rGd                      |t          t          |                      dd¦  «        ¦  «        ¦  «        dg¦  «        }d}	|r&d                     dt          | ¦  «        ddg¦  «        }	d	                     ||	|¬
¦  «        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_failurer<   r|   Úlog_timeNú ú[ú]z{timeStamp}{system}{eventText})Ú	timeStampr�   r>   )rƒ   r‡   r#   r   Úfloatr~   r’   r*   )
r   r   r   r   r9   r>   Úfr†   r›   r�   s
             r   r   r   f  sü   € õT ˜UÑ#Ô#€IØð 6˜M¨UÐ2Ð2Ø�-Ô ˆÝ$ QÑ'Ô'ˆ	Ø—I’I˜y¨)Ð4Ñ5Ô5ˆ	àð ØÐà€IØð YØ—G’G˜Z˜Z­­U°E·I²I¸jÈ$Ñ4OÔ4OÑ(PÔ(PÑQÔQÐSVÐWÑXÔXˆ	à€FØð @Ø—’˜#�}¨UÑ3Ô3°S¸#Ð>Ñ?Ô?ˆà+×2Ò2ØØØð 3ñ ô ð r   N)r   r   r   r   )r   r   r   r    r   r   )r.   r/   r0   r1   r2   r   r   r   )r   r   r9   r:   r   r1   )r%   r   r@   rA   r   rB   )rt   r   ru   rh   r   r   )r(   r   r   r   )r   r   r   r“   r   r“   r   r“   r9   r”   r   r   ))rc   Ú
__future__r   r   r5   Útypingr   r   r   r   r	   r
   r   Ú
constantlyr   Útwisted.python._tzhelperr   Útwisted.python.failurer   Útwisted.python.reflectr   Ú_flattenr   r   Ú_interfacesr   ÚtimeFormatRFC3339r   r,   r9   r?   rH   rK   rB   r   rf   rx   rƒ   r‡   r’   r   rd   r   r   ú<module>r§      sG  ðð
ð ð #Ð "Ð "Ð "Ð "Ð "à )Ð )Ð )Ð )Ð )Ð )Ø JÐ JÐ JÐ JÐ JÐ JÐ JÐ JÐ JÐ JÐ JÐ JÐ JÐ JÐ JÐ JÐ JÐ Jà $Ð $Ð $Ð $Ð $Ð $à 8Ð 8Ð 8Ð 8Ð 8Ð 8Ø *Ð *Ð *Ð *Ð *Ð *Ø ,Ð ,Ð ,Ð ,Ð ,Ð ,Ø ,Ð ,Ð ,Ð ,Ð ,Ð ,Ð ,Ð ,Ø !Ð !Ð !Ð !Ð !Ð !à)Ð ðð ð ð ð(!
ð !
ð !
ð !
ðL !2Øð2ð 2ð 2ð 2ð 2ðF EOð3ð 3ð 3ð 3ð 3ðl'ð 'ð 'ð 'ð.'ð 'ð 'ð 'ð '˜6ñ 'ô 'ð 'ð8:ð :ð :ð :ð :�'˜#˜s˜(Ô#ñ :ô :ð :ð:Kð Kð Kð Kð42ð 2ð 2ð 2ðDð ð ð ð$ð ð ð ðB "Ø!ØØ)3ð?ð ?ð ?ð ?ð ?ð ?ð ?r   