ó
    Ö›‘h¨4  ã                  óv  • S r SSKJr  SSKJr  SSKJrJrJrJ	r	J
r
JrJr  SSKJr  SSKJr  SSKJr  SSKJr  S	S
KJrJr  S	SKJr  SrSS jrSS jr\S4       S S jjr\4     S!S jjrS"S jr " S S\ 5      r! " S S\	\"\4   5      r#S#S jr$SS jr%S$S jr&SS jr'SSS\4           S%S jjr(g)&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                ó   • [        U SSSS9$ )aE  
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    ÚZC:\Users\psant\Downloads\Noiseback\school\venv\Lib\site-packages\twisted/logger/_format.pyÚformatEventr      s   € ô ØØØØñ	ð ó    c                óÔ   •  SR                  XS9$ ! [         aL    [        5       nSR                  S U R	                  5        5       5      nSR                  [        U5      X#S9s $ f = f)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, c              3  óp   #   • U  H,  u  pS R                  [        U5      [        U5      45      v •  M.     g7f)z = N)Újoinr   )Ú.0ÚkeyÚvalues      r   Ú	<genexpr>Ú+formatUnformattableEvent.<locals>.<genexpr>C   s3   é € ð 
â+‘
�ð �J‰Jœ	 #›¬	°%Ó(8Ð9×:Ð:Ú+ùs   ‚46zrMESSAGE LOST: unformattable object logged: {error}
Recoverable data: {text}
Exception during formatting:
{failure})r   ÚfailureÚtext)ÚformatÚBaseExceptionr   r    Úitemsr   )r   r   r&   r'   s       r   ÚformatUnformattableEventr+   -   s�   € ð
Ø:×AÑAØð Bð 
ð 	
øô ó 
ô “)ˆà�y‰yñ 
à#Ÿk™kœmó
ó 
ˆð6ç6<±fÜ Ó&°ð 7=ð 7ò	
ð
ús   ‚ ‘AA'Á&A'Ú-c                óž   • Ub  U c  U$ [         R                  " U 5      n[        R                  " X5      n[	        UR                  U5      5      $ )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Útzr   s        r   Ú
formatTimer7   Q   sI   € ð4 Ñ˜T™\Øˆä ×3Ò3°DÓ9ˆÜ×)Ò)¨$Ó3ˆÜ�8×$Ñ$ ZÓ0Ó1Ð1r   c                óR   • [        XS9nU(       d  gUR                  SS5      nU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.
)r7   NÚ
z
	)r   Úreplace)r   r7   Ú	eventTexts      r   ÚformatEventAsClassicLogTextr<   s   s2   € ô^ ˜EÑ9€IÞØØ×!Ñ! $¨Ó/€IØ�tÑÐr   ÚPotentialCallWrapperc                ó‚   • U R                  S5      nU(       a  U SS OU nU" U5      nU(       a  U" 5       n[        U5      $ )aL  
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   ÚkeycallrD   ©   s?   € ð �\‰\˜$Ó€FÞ ˆc�#�2‰h c€GÙ�7‹O€EÞÙ“ˆÜ Ó&Ð&r   c                  óT   • \ rS rSrSrSS jrSS jrSS jrSS jrSS jr	SS jr
S	rg
)r=   éÀ   zs
Object wrapper that wraps C{getattr()} so as to process call-parentheses
C{"()"} after a dotted attribute access.
c                ó   • Xl         g ©N©Ú_wrapped)ÚselfÚwrappeds     r   Ú__init__ÚPotentialCallWrapper.__init__Æ   s   € Ø�r   c                ó$   ^ • [        UU 4S j5      $ )Nc                ó0   >• [        TR                  U 5      $ rH   )ÚgetattrrJ   )Úname_rK   s    €r   Ú<lambda>Ú2PotentialCallWrapper.__getattr__.<locals>.<lambda>Ê   s   ø€ ¬7°4·=±=À%Ô+Hr   )rD   )rK   Únames   ` r   Ú__getattr__Ú PotentialCallWrapper.__getattr__É   s   ø€ Ü�tÔHÓIÐIr   c                ó6   • U R                   U   n[        U5      $ rH   )rJ   r=   )rK   rU   r#   s      r   Ú__getitem__Ú PotentialCallWrapper.__getitem__Ì   s   € ð —‘˜dÑ#ˆÜ# EÓ*Ð*r   c                ó.   • [        U R                  U5      $ rH   )r(   rJ   )rK   Úformat_specs     r   Ú
__format__ÚPotentialCallWrapper.__format__Ò   s   € Ü�d—m‘m [Ó1Ð1r   c                ó,   • [        U R                  5      $ rH   )ÚreprrJ   ©rK   s    r   Ú__repr__ÚPotentialCallWrapper.__repr__Õ   s   € Ü�D—M‘MÓ"Ð"r   c                ó,   • [        U R                  5      $ rH   )r1   rJ   ra   s    r   Ú__str__ÚPotentialCallWrapper.__str__Ø   s   € Ü�4—=‘=Ó!Ð!r   rI   N)rL   ÚobjectÚreturnÚNone)rU   r1   rh   rg   )r\   r1   rh   r1   )rh   r1   )Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__rM   rV   rY   r]   rb   re   Ú__static_attributes__© r   r   r=   r=   À   s&   † ñô
 ôJô+ô2ô#÷"r   c                  ó@   • \ rS rSrSrS	S jrS
S jrSS jrSS jrSr	g)ÚCallMappingéÜ   z¨
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                ó   • Xl         g)zW
@param submapping: Another read-only mapping which will be used to look
    up items.
N©Ú_submapping)rK   Ú
submappings     r   rM   ÚCallMapping.__init__ä   s
   € ð
 &Õr   c                ó,   • [        U R                  5      $ rH   )Úiterrv   ra   s    r   Ú__iter__ÚCallMapping.__iter__ë   s   € Ü�D×$Ñ$Ó%Ð%r   c                ó,   • [        U R                  5      $ rH   )Úlenrv   ra   s    r   Ú__len__ÚCallMapping.__len__î   s   € Ü�4×#Ñ#Ó$Ð$r   c                ó@   • [        XR                  R                  5      $ )zd
Look up an item in the submapping for this L{CallMapping}, calling it
if C{key} ends with C{"()"}.
)rD   rv   rY   )rK   r"   s     r   rY   ÚCallMapping.__getitem__ñ   s   € ô
 �s×,Ñ,×8Ñ8Ó9Ð9r   ru   N)rw   úMapping[str, Any]rh   ri   )rh   zIterator[Any])rh   Úint)r"   r1   rh   r   )
rj   rk   rl   rm   rn   rM   r{   r   rY   ro   rp   r   r   rr   rr   Ü   s   † ñô&ô&ô%÷:r   rr   c           	     óV   • [        [        R                  " U S[        U5      5      5      $ )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.
rp   )r1   r   Úvformatrr   )ÚformatStringÚmappings     r   ÚformatWithCallr‰   ù   s#   € ô. Œz×!Ò! ,°´KÀÓ4HÓIÓJÐJr   c                óˆ  •  SU ;   a  [        U 5      $ [        [        [        [        [
        4      U R                  SS5      5      nUc  g[        U[        5      (       a  O6[        U[
        5      (       a  UR                  S5      nO[        SU< 35      e[        X5      $ ! [         a  n[        X5      s SnA$ SnAff = f)aI  
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
   r1   ÚbytesÚgetÚ
isinstanceÚdecodeÚ	TypeErrorr‰   r)   r+   )r   r(   Ú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Ó,Ð,øäó 2Ü'¨Ó1Õ1ûð2ús)   ‚B" “7B" ÁAB" Â"
CÂ,
B<Â6CÂ<Cc                ót   •  U R                  5       nU$ ! [         a  nS[        U5      -   n SnAU$ SnAff = f)aB  
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)   r1   )r&   Ú	tracebackr“   s      r   Ú_formatTracebackr˜   5  sF   € ðHØ×(Ñ(Ó*ˆ	ð Ðøô ó HØ>ÄÀQÃÑGŒ	ØÐûðHús   ‚ ”
7ž2²7c           	     ój  • [        [        [           U R                  SS5      5      nUci  [        [        [           U R                  SS5      5      nUc  SnOUR
                  nSR                  [        [        U R                  SS5      5      US9nU$  [        U5      nU$ ! [         a    Sn U$ f = f)	as  
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	   r1   r�   r   rU   r(   Ú	Exception)r   Úsystemrž   Ú	levelNames       r   Ú_formatSystemr£   G  s·   € ô ”(œ3‘- §¡¨<¸Ó!>Ó?€FØ�~Ü”XœmÑ,¨e¯i©i¸ÀTÓ.JÓKˆØ‰=Ø‰IàŸ
™
ˆIà&×-Ñ-Üœ3 §	¡	¨/¸3Ó ?Ó@Øð .ð 
ˆð €Mð		%Ü˜“[ˆFð €Møô ó 	%Ø$‰FØ€Mð	%ús   ÂB" Â"B2Â1B2Tc                óx  • [        U 5      nU(       a(  SU ;   a"  U S   n[        U5      nSR                  XW45      nU(       d  U$ SnU(       a7  SR                  U" [        [        U R                  SS5      5      5      S/5      nSn	U(       a  SR                  S[        U 5      SS/5      n	S	R                  UU	US
9$ )a  
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_failurer9   r�   Úlog_timeNÚ Ú[Ú]z{timeStamp}{system}{eventText})Ú	timeStampr¡   r;   )r”   r˜   r    r   Úfloatr�   r£   r(   )
r   r   r   r   r7   r;   Úfr—   rª   r¡   s
             r   r   r   f  s¿   € ô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ð ð r   N)r   r   rh   r1   )r   r   r   r)   rh   r1   )r3   zOptional[float]r4   úOptional[str]r5   r1   rh   r1   )r   r   r7   z Callable[[Optional[float]], str]rh   r­   )r"   r1   rA   zCallable[[str], Any]rh   r=   )r‡   r1   rˆ   rƒ   rh   r1   )r&   r   rh   r1   )r   r   r   Úboolr   r®   r   r®   r7   zCallable[[float], str]rh   r1   ))rn   Ú
__future__r   r   r/   Útypingr   r   r   r   r	   r
   r   Ú
constantlyr   Útwisted.python._tzhelperr   Útwisted.python.failurer   Útwisted.python.reflectr   Ú_flattenr   r   Ú_interfacesr   ÚtimeFormatRFC3339r   r+   r7   r<   rD   rg   r=   r1   rr   r‰   r”   r˜   r£   r   rp   r   r   Ú<module>r¸      s  ðñ
õ #å )ß J× JÑ Jå $å 8Ý *Ý ,ß ,Ý !à)Ð ôô(!
ðL !2Øð2Ø
ð2àð2ð ð2ð 	õ	2ðF EOð3Øð3Ø!Að3àõ3ôl'ô."˜6ô "ô8:�'˜#˜s˜(Ñ#ô :ô:Kô42ôDô$ðB "Ø!ØØ)3ð?Øð?àð?ð ð?ð ð	?ð
 'ð?ð 	ö?r   