
    hy              	           S r SSK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Jr  SSKJr  SSKJrJr  \(       a  SS	KJr  \" \5       " S
 S5      5       rS\S\\\4   S\\\\4   /\\   4   SS4S jrg)z)
Integration with L{twisted.python.log}.
    )TYPE_CHECKINGAnyCallableDictOptional)implementer   )formatEvent)ILogObserverLogEvent)LogLevel)StringifiableFromEventfromStdlibLogLevelMapping)r   c                   B    \ rS rSrSrS
S jrS\4S jrS\SS4S jr	S	r
g)LegacyLogObserverWrapper   z
L{ILogObserver} that wraps a L{twisted.python.log.ILogObserver}.

Received (new-style) events are modified prior to forwarding to
the legacy observer to ensure compatibility with observers that
expect legacy events.
returnNc                     Xl         g)zZ
@param legacyObserver: a legacy observer to which this observer will
    forward events.
NlegacyObserver)selfr   s     ]/root/1688_scrapy/alibaba-scraper/venv/lib/python3.13/site-packages/twisted/logger/_legacy.py__init__!LegacyLogObserverWrapper.__init__    s
    
 -    c                      SR                  U S9$ )Nz0{self.__class__.__name__}({self.legacyObserver})r   )formatr   s    r   __repr__!LegacyLogObserverWrapper.__repr__'   s    AHHdHSSr   eventc                    SU;  a  SUS'   SU;  a  US   US'   SU;  a  UR                  SS5      US'   SU;  aQ  UR                  S	S
5      b>  SUS'   [        UR                  5       5      US'   [        US   [        5      (       d  SUS'   SU;   a.  SU;  a  US   US'   SU;  a  SUS'   SU;  a  [        U5      US'   O8SU;  a2  US   [        R                  [        R                  4;   a  SUS'   OSUS'   U R                  U5        g
)zk
Forward events to the legacy observer after editing them to
ensure compatibility.

@param event: an event
message timelog_timesystem
log_system-r   
log_formatNz%(log_legacy)s
log_legacylog_failurefailureisErrorr	   why	log_levelr   )
getr   copy
isinstancetupler
   r   errorcriticalr   )r   r!   s     r   __call__!LegacyLogObserverWrapper.__call__*   s0    E!!E)!*-E&M5 #iic:E(O 5 UYY|T%B%N /E(O"8"FE, eI.66#%i  E!%#(#7i %#$i E!*51ee#[!hnnh6G6G%HH#$i #$i E"r   r   )r   ILegacyLogObserverr   N)__name__
__module____qualname____firstlineno____doc__r   strr   r   r7   __static_attributes__r$   r   r   r   r      s-    -T# T0#h 0#4 0#r   r   observer	eventDicttextFromEventDictr   Nc                    SU;  a  US   US'   SU;  a  U" U5      nUb	  X1S'   SUS'   SU;  a]  SU;   a   [         US      nOBS	U;   a,  US	   (       a  [        R                  nO![        R                  nO[        R                  nUb  XAS'   S
U;  a  SUS
'   SU;  a  SU;   a  US   US'   U " U5        g! [         a    Sn N=f = f)a  
Publish an old-style (L{twisted.python.log}) event to a new-style
(L{twisted.logger}) observer.

@note: It's possible that a new-style event was sent to a
    L{LegacyLogObserverWrapper}, and may now be getting sent back to a
    new-style observer.  In this case, it's already a new-style event,
    adapted to also look like an old-style event, and we don't need to
    tweak it again to be a new-style event, hence this checks for
    already-defined new-style keys.

@param observer: A new-style observer to handle this event.
@param eventDict: An L{old-style <twisted.python.log>}, log event.
@param textFromEventDict: callable that can format an old-style event as a
    string.  Passed here rather than imported to avoid circular dependency.
r&   r%   r*   Nlog_textz
{log_text}r0   logLevelr.   log_namespacer+   r(   r'   )r   KeyErrorr   r6   info)rA   rB   rC   textlevels        r   publishToNewObserverrL   ]   s    , " )& 1	*9$ +$(j!&2Il#)#"1)J2GH )## )) MME%*k"i'%1	/"9$Y)>"+H"5	,Y'  s   B4 4CC)r>   typingr   r   r   r   r   zope.interfacer   _formatr
   _interfacesr   r   _levelsr   _stdlibr   r   twisted.python.logr9   r   r?   rL   r$   r   r   <module>rT      s   
 @ ? &   /  FE \C# C# C#L66CH~6  c3h 0(3- ?@6 
	6r   