+
    üÐj¨4  ã                  óf  € R t ^ RIHt ^ RIHt ^ RIHtHtHtH	t	H
t
HtHt ^ RIHt ^ RIHt ^ RIHt ^ RIHt ^RIHtHt ^R	IHt R
tR R ltR R lt]R3R R llt]3R R lltR R lt ! R R] 4      t! ! R R]	]"]3,          4      t#R R lt$R R lt%R R lt&R  R! lt'R"R"R"]3R# R$ llt(R%# )&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               ó    € V ^8„  d   QhRRRR/# ©é   Úeventr   ÚreturnÚstr© )Úformats   "Ú8/usr/lib/python3/dist-packages/twisted/logger/_format.pyÚ__annotate__r      s   € ÷ ñ �xð  Cñ ó    c                ó    € \        V RRRR7      # )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)r   s   &r   ÚformatEventr"      s   € ô ØØØØô	ð r   c               ó$   € V ^8„  d   QhRRRRRR/# )r   r   r   ÚerrorÚBaseExceptionr   r   r   )r   s   "r   r   r   -   s!   € ÷ !
ñ !
 Hð !
°]ð !
Àsñ !
r   c                óâ   €  RP                  WR7      #   \         dP    \        4       pRP                  R T P	                  4        4       4      pRP                  \        T4      Y#R7      u # i ; i)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  óp   "  € T F,  w  rR P                  \        V4      \        V4      34      x € K.  	  R# 5i)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)r   r%   r   r(   Úitemsr   )r   r$   r.   r/   s   &&  r   ÚformatUnformattableEventr1   -   s�   € ð
Ø:×AÑAØð Bó 
ð 	
øô ô 
ô “)ˆà�y‰yñ 
à#Ÿk™kœmó
ó 
ˆð6ç6<±fÜ Ó&°ð 7=ó 7ò	
ð
ús   ‚ ”AA.Á-A.Ú-c               ó(   € V ^8„  d   QhRRRRRRRR/# )r   ÚwhenzOptional[float]Ú
timeFormatúOptional[str]Údefaultr   r   r   )r   s   "r   r   r   Q   s0   € ÷ 2ñ 2Ø
ð2àð2ð ð2ð 	ñ	2r   c                ó¢   € Ve   V f   V# \         P                  ! V 4      p\        P                  ! W4      p\	        VP                  V4      4      # )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)r4   r5   r7   Útzr   s   &&&  r   Ú
formatTimer>   Q   sI   € ð4 Ò˜Tš\Øˆä ×3Ò3°DÓ9ˆÜ×)Ò)¨$Ó3ˆÜ�8×$Ñ$ ZÓ0Ó1Ð1r   c               ó$   € V ^8„  d   QhRRRRRR/# )r   r   r   r>   z Callable[[Optional[float]], str]r   r6   r   )r   s   "r   r   r   s   s$   € ÷ 3ñ 3Øð3Ø!Að3àñ3r   c                ód   € \        WR7      pV'       g   R# VP                  RR4      pVR,           # )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.
)r>   NÚ
z
	)r!   Úreplace)r   r>   Ú	eventTexts   && r   ÚformatEventAsClassicLogTextrD   s   s2   € ô^ ˜EÔ9€IßÙØ×!Ñ! $¨Ó/€IØ�tÕÐr   c               ó$   € V ^8„  d   QhRRRRRR/# )r   r*   r   ÚgetterzCallable[[str], Any]r   ÚPotentialCallWrapperr   )r   s   "r   r   r   ©   s#   € ÷ 'ñ '�ð 'Ð2ð 'Ð7Kñ 'r   c                ó†   € V P                  R4      pV'       d   V RR MT pV! V4      pV'       d   V! 4       p\        V4      # )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éþÿÿÿ)ÚendswithrG   )r*   rF   ÚcallitÚrealKeyr+   s   &&   r   ÚkeycallrM   ©   s?   € ð �\‰\˜$Ó€Fß ˆc�#�2‰h c€GÙ�7‹O€EßÙ“ˆÜ Ó&Ð&r   c                  ób   € ] tR t^ÀtRtR R ltR R ltR R ltR R	 ltR
 R lt	R R lt
RtR# )rG   zs
Object wrapper that wraps C{getattr()} so as to process call-parentheses
C{"()"} after a dotted attribute access.
c               ó    € V ^8„  d   QhRRRR/# )r   ÚwrappedÚobjectr   ÚNoner   )r   s   "r   r   Ú!PotentialCallWrapper.__annotate__Æ   s   € ÷  ñ   ð  ¨4ñ  r   c                	ó   € Wn         R # ©N©Ú_wrapped)ÚselfrP   s   &&r   Ú__init__ÚPotentialCallWrapper.__init__Æ   s   € ØŽr   c               ó    € V ^8„  d   QhRRRR/# ©r   Únamer   r   rQ   r   )r   s   "r   r   rS   É   s   € ÷ Jñ J ð J¨ñ Jr   c                	ó$   a € \        VV 3R  l4      # )c                ó0   <€ \        SP                  V 4      # rU   )ÚgetattrrW   )Úname_rX   s   &€r   Ú<lambda>Ú2PotentialCallWrapper.__getattr__.<locals>.<lambda>Ê   s   ø€ ¬7°4·=±=À%Ô+Hr   )rM   )rX   r]   s   f&r   Ú__getattr__Ú PotentialCallWrapper.__getattr__É   s   ø€ Ü�tÔHÓIÐIr   c               ó    € V ^8„  d   QhRRRR/# r\   r   )r   s   "r   r   rS   Ì   s   € ÷ +ñ + ð +¨ñ +r   c                	ó>   € V P                   V,          p\        V4      # rU   )rW   rG   )rX   r]   r+   s   && r   Ú__getitem__Ú PotentialCallWrapper.__getitem__Ì   s   € ð —‘˜dÕ#ˆÜ# EÓ*Ð*r   c               ó    € V ^8„  d   QhRRRR/# )r   Úformat_specr   r   r   )r   s   "r   r   rS   Ò   s   € ÷ 2ñ 2 cð 2¨cñ 2r   c                	ó.   € \        V P                  V4      # rU   )r   rW   )rX   rk   s   &&r   Ú
__format__ÚPotentialCallWrapper.__format__Ò   s   € Ü�d—m‘m [Ó1Ð1r   c               ó   € V ^8„  d   QhRR/# ©r   r   r   r   )r   s   "r   r   rS   Õ   s   € ÷ #ñ #˜#ñ #r   c                	ó,   € \        V P                  4      # rU   )ÚreprrW   ©rX   s   &r   Ú__repr__ÚPotentialCallWrapper.__repr__Õ   s   € Ü�D—M‘MÓ"Ð"r   c               ó   € V ^8„  d   QhRR/# rp   r   )r   s   "r   r   rS   Ø   s   € ÷ "ñ "˜ñ "r   c                	ó,   € \        V P                  4      # rU   )r   rW   rs   s   &r   Ú__str__ÚPotentialCallWrapper.__str__Ø   s   € Ü�4—=‘=Ó!Ð!r   rV   N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__rY   rd   rh   rm   rt   rx   Ú__static_attributes__r   r   r   rG   rG   À   s+   † ñõ
 õJõ+õ2õ#÷"ñ "r   rG   c                  óJ   € ] tR t^ÜtRtR R ltR R ltR R ltR R	 ltR
t	R# )Ú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               ó    € V ^8„  d   QhRRRR/# )r   Ú
submappingúMapping[str, Any]r   rR   r   )r   s   "r   r   ÚCallMapping.__annotate__ä   s   € ÷ &ñ &Ð#4ð &¸ñ &r   c                ó   € Wn         R# )zW
@param submapping: Another read-only mapping which will be used to look
    up items.
N©Ú_submapping)rX   rƒ   s   &&r   rY   ÚCallMapping.__init__ä   s
   € ð
 &Ör   c               ó   € V ^8„  d   QhRR/# )r   r   zIterator[Any]r   )r   s   "r   r   r…   ë   s   € ÷ &ñ &˜-ñ &r   c                	ó,   € \        V P                  4      # rU   )Úiterrˆ   rs   s   &r   Ú__iter__ÚCallMapping.__iter__ë   s   € Ü�D×$Ñ$Ó%Ð%r   c               ó   € V ^8„  d   QhRR/# )r   r   Úintr   )r   s   "r   r   r…   î   s   € ÷ %ñ %˜ñ %r   c                	ó,   € \        V P                  4      # rU   )Úlenrˆ   rs   s   &r   Ú__len__ÚCallMapping.__len__î   s   € Ü�4×#Ñ#Ó$Ð$r   c               ó    € V ^8„  d   QhRRRR/# )r   r*   r   r   r   r   )r   s   "r   r   r…   ñ   s   € ÷ :ñ :˜sð : sñ :r   c                ó@   € \        WP                  P                  4      # )zd
Look up an item in the submapping for this L{CallMapping}, calling it
if C{key} ends with C{"()"}.
)rM   rˆ   rh   )rX   r*   s   &&r   rh   ÚCallMapping.__getitem__ñ   s   € ô
 �s×,Ñ,×8Ñ8Ó9Ð9r   r‡   N)
rz   r{   r|   r}   r~   rY   r�   r“   rh   r   r   r   r   r�   r�   Ü   s    † ñõ&õ&õ%÷:ñ :r   r�   c               ó$   € V ^8„  d   QhRRRRRR/# )r   ÚformatStringr   Úmappingr„   r   r   )r   s   "r   r   r   ù   s'   € ÷ Kñ K ð KÐ/@ð KÀSñ Kr   c           	     óV   € \        \        P                  ! V R\        V4      4      4      # )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   )r   r   Úvformatr�   )r™   rš   s   &&r   ÚformatWithCallr�   ù   s#   € ô. Œz×!Ò! ,°´KÀÓ4HÓIÓJÐJr   c               ó    € V ^8„  d   QhRRRR/# r   r   )r   s   "r   r   r     s   € ÷ 2ñ 2˜ð 2 Sñ 2r   c                ó¤  €  RV 9   d   \        V 4      # \        \        \        \        \
        3,          ,          V P                  RR4      4      pVf   R# \        V\        4      '       d   M7\        V\
        4      '       d   VP                  R4      pM\        RV: 24      h\        W4      #   \         d   p\        Y4      u Rp?# Rp?ii ; i)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	   r   ÚbytesÚgetÚ
isinstanceÚdecodeÚ	TypeErrorr�   r%   r1   )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/ ”A B/ ÁAB/ Â/CÂ:
C
ÃCÃ
Cc               ó    € V ^8„  d   QhRRRR/# )r   r.   r   r   r   r   )r   s   "r   r   r   5  s   € ÷ ñ ˜gð ¨#ñ r   c                ó~   €  V P                  4       pV#   \         d   pR\        T4      ,           p Rp?T# Rp?ii ; i)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%   r   )r.   Ú	tracebackr¨   s   &  r   Ú_formatTracebackr®   5  sF   € ðHØ×(Ñ(Ó*ˆ	ð Ðøô ô HØ>ÄÀQÃÕGŒ	ØÐûðHús   ‚ ”<Ÿ7·<c               ó    € V ^8„  d   QhRRRR/# r   r   )r   s   "r   r   r   G  s   € ÷ ñ ˜ð  cñ r   c           	     ó†  € \        \        \        ,          V P                  RR4      4      pVfr   \        \        \        ,          V P                  RR4      4      pVf   RpMVP
                  pRP                  \        \        V P                  RR4      4      VR7      pV#  \        V4      pV#   \         d    Rp T# i ; i)	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_levelr2   z{namespace}#{level}Úlog_namespace)Ú	namespaceÚlevelÚUNFORMATTABLE)r
   r   r   r¤   r   r]   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/ Â/C Â?C Tc               ó0   € V ^8„  d   QhRRRRRRRRRRR	R
/# )r   r   r   r   Úboolr   r    r>   zCallable[[float], str]r   r   r   )r   s   "r   r   r   f  sD   € ÷ ?ñ ?Øð?àð?ð ð?ð ð	?ð
 'ð?ð 	ñ?r   c                ó�  € \        V 4      pV'       d.   RV 9   d'   V R,          p\        V4      pRP                  WW34      pV'       g   V# RpV'       d8   RP                  V! \        \        V P                  RR4      4      4      R.4      pRp	V'       d   RP                  R\        V 4      RR.4      p	R	P                  VV	VR
7      # )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_failurerA   r¢   Úlog_timeNÚ Ú[Ú]z{timeStamp}{system}{eventText})Ú	timeStampr¸   rC   )r©   r®   r(   r
   Úfloatr¤   rº   r   )
r   r   r   r    r>   rC   Ú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~   Ú
__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"   r1   r>   rD   rM   rQ   rG   r   r�   r�   r©   r®   rº   r!   r   r   r   Ú<module>rÏ      s®   ðñ
õ #å )ß J× JÑ Jå $å 8Ý *Ý ,ß ,Ý !à)Ð õõ(!
ðL !2Ø÷2ðF EO÷3õl'ô."˜6ô "ô8:�'˜#˜s˜(Õ#ô :õ:Kõ42õDõ$ðB "Ø!ØØ)3÷?ñ ?r   