
    h?                        S r SSKJ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  SSKJr  SSKJr  SS	KJrJr  SS
KJrJr   " S S\5      r " S S5      r " S S5      r " S S5      r\" 5       rSS jrg)z
Logger class.
    )annotations)time)TracebackType)AnyCallableContextManagerOptionalProtocolcast)currentframe)Failure   )ILogObserverLogTrace)InvalidLogLevelErrorLogLevelc                  T    \ rS rSrSr\SS j5       r\S	S j5       r\SS j5       rSr	g)
	Operation   z
An L{Operation} represents the success (or lack thereof) of code performed
within the body of the L{Logger.failureHandler} context manager.
c                    g)z
Did the operation succeed?  C{True} iff the code completed without
raising an exception; C{False} while the code is running and C{False}
if it raises an exception.
N selfs    ]/root/1688_scrapy/alibaba-scraper/venv/lib/python3.13/site-packages/twisted/logger/_logger.py	succeededOperation.succeeded           c                    g)zR
Did the operation raise an exception?  If so, this L{Failure} is that
exception.
Nr   r   s    r   failureOperation.failure#   r   r   c                    g)z
Did the operation fail?  C{True} iff the code raised an exception;
C{False} while the code is running and C{False} if it completed without
error.
Nr   r   s    r   failedOperation.failed*   r   r   r   Nreturnbool)r&   Failure | None)
__name__
__module____qualname____firstlineno____doc__propertyr   r    r#   __static_attributes__r   r   r   r   r      sC    
      r   r   c                  t    \ rS rSr% SrS\S'   SrS\S'   SS jr\SS	 j5       r	SS
 jr
        SS jrSrg)_FailCtxMgr3   Fr'   r   Nr(   r    c                    Xl         g N_failr   fails     r   __init___FailCtxMgr.__init__7       
r   c                    U R                   S L$ r4   r    r   s    r   r#   _FailCtxMgr.failed:   s    ||4''r   c                    U $ r4   r   r   s    r   	__enter___FailCtxMgr.__enter__>   s    r   c               \    Ub"  [        5       nX@l        U R                  U5        gSU l        gNT)r   r    r6   r   r   exc_type	exc_value	tracebackr    s        r   __exit___FailCtxMgr.__exit__A   s3     iG"LJJw  "DNr   )r6   r    r   r8   zCallable[[Failure], None]r&   Noner%   )r&   r   rE   ztype[BaseException] | NonerF   zBaseException | NonerG   zTracebackType | Noner&   r'   )r)   r*   r+   r,   r   __annotations__r    r9   r.   r#   r@   rH   r/   r   r   r   r1   r1   3   s_    It"G^" ( (, ( (	 
r   r1   c                  B    \ rS rSrSS jrSS jr        S	S jrSrg)
_FastFailCtxMgrQ   c                    Xl         g r4   r5   r7   s     r   r9   _FastFailCtxMgr.__init__R   r;   r   c                    g r4   r   r   s    r   r@   _FastFailCtxMgr.__enter__U   s    r   c               L    Ub!  [        5       nX@l        U R                  U5        grC   )r   r    r6   rD   s        r   rH   _FastFailCtxMgr.__exit__X   s%     iG"LJJwr   )r6   r    NrJ   )r&   rK   rL   )r)   r*   r+   r,   r9   r@   rH   r/   r   r   r   rO   rO   Q   s7    , ( (	 
r   rO   c                  b   \ rS rSrSr\SS j5       r   S       SS jjrSSS jjrSS jr	 S       SS jjr
S\R                  4         SS	 jjrSSS
 jjrSSS jjrSSS jjrSSS jjrSSS jjr\R                  4       SS jjr\R                  4     SS jjrSrg)Loggerf   ab  
A L{Logger} emits log messages to an observer.  You should instantiate it
as a class or module attribute, as documented in L{this module's
documentation <twisted.logger>}.

@ivar namespace: the namespace for this logger
@ivar source: The object which is emitting events via this logger
@ivar observer: The observer that this logger will send events to.
c                 p     [        [        [        S5      R                  S   5      $ ! [         a     gf = f)z{
Derive a namespace from the module containing the caller's caller.

@return: the fully qualified python name of a module.
   r)   z	<unknown>)r   strr   	f_globalsKeyErrorr   r   r   _namespaceFromCallingContext#Logger._namespaceFromCallingContextq   s5    	\!_66zBCC 		s   %( 
55Nc                n    Uc  U R                  5       nXl        X l        Uc  SSKJn  X@l        gX0l        g)a  
@param namespace: The namespace for this logger.  Uses a dotted
    notation, as used by python modules.  If not L{None}, then the name
    of the module of the caller is used.
@param source: The object which is emitting events via this
    logger; this is automatically set on instances of a class
    if this L{Logger} is an attribute of that class.
@param observer: The observer that this logger will send events to.
    If L{None}, use the L{global log publisher <globalLogPublisher>}.
Nr   )globalLogPublisher)r_   	namespacesource_globalrb   observer)r   rc   rd   rf   rb   s        r   r9   Logger.__init__}   s5      99;I"3*<M$Mr   c                    Uc   eUc  UnOUnU R                  SR                  UR                  UR                  /5      UU R                  S9$ )a  
When used as a descriptor, i.e.::

    # File: athing.py
    class Something:
        log = Logger()
        def hello(self):
            self.log.info("Hello")

a L{Logger}'s namespace will be set to the name of the class it is
declared on.  In the above example, the namespace would be
C{athing.Something}.

Additionally, its source will be set to the actual object referring to
the L{Logger}.  In the above example, C{Something.log.source} would be
C{Something}, and C{Something().log.source} would be an instance of
C{Something}.
.)rf   )	__class__joinr*   r)   rf   )r   instanceownerrd   s       r   __get__Logger.__get__   s[    &    FF~~HHe&&78]]  
 	
r   c                R    SU R                   R                   SU R                  < S3$ )N< >)rj   r)   rc   r   s    r   __repr__Logger.__repr__   s'    4>>**+1T^^,>a@@r   c           	     l   U[         R                  " 5       ;  a%  U R                  S[        [	        U5      5      UU S9  gUnUR                  U UU R                  U R                  U[        5       S9  SU;   a-  [        [        US   5      R                  X R                  45        U R                  U5        g)a  
Emit a log event to all log observers at the given level.

@param level: a L{LogLevel}
@param format: a message format using new-style (PEP 3101)
    formatting.  The logging event (which is a L{dict}) is
    used to render this format string.
@param kwargs: additional key/value pairs to include in the event.
    Note that values which are later mutated may result in
    non-deterministic behavior from observers that schedule work for
    later execution.
z:Got invalid log level {invalidLevel!r} in {logger}.emit().)invalidLevelloggerN)
log_logger	log_levellog_namespace
log_source
log_formatlog_time	log_trace)r   iterconstantsr    r   r   updaterc   rd   r   r   r   appendrf   )r   levelformatkwargsevents        r   emitLogger.emit   s     ..00LLL,U34"	   ..{{V 	 	
 %5-.55t]]6KLer   c                H    Uc
  [        5       nU R                  " X14SU0UD6  g)au  
Log a failure and emit a traceback.

For example::

    try:
        frob(knob)
    except Exception:
        log.failure("While frobbing {knob}", knob=knob)

or::

    d = deferredFrob(knob)
    d.addErrback(lambda f: log.failure("While frobbing {knob}",
                                       f, knob=knob))

This method is meant to capture unexpected exceptions in code; an
exception that is caught and handled somehow should be logged, if
appropriate, via L{Logger.error} instead.  If some unknown exception
occurs and your code doesn't know how to handle it, as in the above
example, then this method provides a means to describe the failure.
This is done at L{LogLevel.critical} by default, since no corrective
guidance can be offered to an user/administrator, and the impact of the
condition is unknown.

@param format: a message format using new-style (PEP 3101) formatting.
    The logging event (which is a L{dict}) is used to render this
    format string.

@param failure: a L{Failure} to log.  If L{None}, a L{Failure} is
    created from the exception in flight.

@param level: a L{LogLevel} to use.

@param kwargs: additional key/value pairs to include in the event.
    Note that values which are later mutated may result in
    non-deterministic behavior from observers that schedule work for
    later execution.

@see: L{Logger.failureHandler}

@see: L{Logger.failuresHandled}
Nlog_failure)r   r   )r   r   r    r   r   s        r   r    Logger.failure   s'    d ?iG		%?W??r   c                H    U R                   " [        R                  U40 UD6  g)a  
Emit a log event at log level L{LogLevel.debug}.

@param format: a message format using new-style (PEP 3101) formatting.
    The logging event (which is a L{dict}) is used to render this
    format string.

@param kwargs: additional key/value pairs to include in the event.
    Note that values which are later mutated may result in
    non-deterministic behavior from observers that schedule work for
    later execution.
N)r   r   debugr   r   r   s      r   r   Logger.debug       			(..&3F3r   c                H    U R                   " [        R                  U40 UD6  g)a  
Emit a log event at log level L{LogLevel.info}.

@param format: a message format using new-style (PEP 3101) formatting.
    The logging event (which is a L{dict}) is used to render this
    format string.

@param kwargs: additional key/value pairs to include in the event.
    Note that values which are later mutated may result in
    non-deterministic behavior from observers that schedule work for
    later execution.
N)r   r   infor   s      r   r   Logger.info*       			(--262r   c                H    U R                   " [        R                  U40 UD6  g)a  
Emit a log event at log level L{LogLevel.warn}.

@param format: a message format using new-style (PEP 3101) formatting.
    The logging event (which is a L{dict}) is used to render this
    format string.

@param kwargs: additional key/value pairs to include in the event.
    Note that values which are later mutated may result in
    non-deterministic behavior from observers that schedule work for
    later execution.
N)r   r   warnr   s      r   r   Logger.warn9  r   r   c                H    U R                   " [        R                  U40 UD6  g)a  
Emit a log event at log level L{LogLevel.error}.

@param format: a message format using new-style (PEP 3101) formatting.
    The logging event (which is a L{dict}) is used to render this
    format string.

@param kwargs: additional key/value pairs to include in the event.
    Note that values which are later mutated may result in
    non-deterministic behavior from observers that schedule work for
    later execution.
N)r   r   errorr   s      r   r   Logger.errorH  r   r   c                H    U R                   " [        R                  U40 UD6  g)a  
Emit a log event at log level L{LogLevel.critical}.

@param format: a message format using new-style (PEP 3101) formatting.
    The logging event (which is a L{dict}) is used to render this
    format string.

@param kwargs: additional key/value pairs to include in the event.
    Note that values which are later mutated may result in
    non-deterministic behavior from observers that schedule work for
    later execution.
N)r   r   criticalr   s      r   r   Logger.criticalW  s     			(##V6v6r   c                .   ^ ^^^ [        UUUU 4S j5      $ )a?  
Run some application code, logging a failure and emitting a traceback
in the event that any of it fails, but continuing on.  For example::

    log = Logger(...)

    def frameworkCode() -> None:
        with log.failuresHandled("While frobbing {knob}:", knob=knob) as op:
            frob(knob)
        if op.succeeded:
            log.info("frobbed {knob} successfully", knob=knob)

This method is meant to capture unexpected exceptions from application
code; an exception that is caught and handled somehow should be logged,
if appropriate, via L{Logger.error} instead.  If some unknown exception
occurs and your code doesn't know how to handle it, as in the above
example, then this method provides a means to describe the failure.
This is done at L{LogLevel.critical} by default, since no corrective
guidance can be offered to an user/administrator, and the impact of the
condition is unknown.

@param format: a message format using new-style (PEP 3101) formatting.
    The logging event (which is a L{dict}) is used to render this
    format string.

@param level: a L{LogLevel} to use.

@param kwargs: additional key/value pairs to include in the event, if
    it is emitted.  Note that values which are later mutated may result
    in non-deterministic behavior from observers that schedule work for
    later execution.

@see: L{Logger.failure}
@see: L{Logger.failureHandler}

@return: A context manager which yields an L{Operation} which will have
    either its C{succeeded} or C{failed} attribute set to C{True} upon
    completion of the code within the code within the C{with} block.
c                .   > TR                   " TU T40 TD6$ r4   r=   )fr   r   r   r   s    r   <lambda>(Logger.failuresHandled.<locals>.<lambda>  s    T\\&!U%Mf%Mr   )r1   )r   r   r   r   s   ````r   failuresHandledLogger.failuresHandledf  s    T MNNr   c                *   ^ ^^ [        UU U4S j5      $ )a  
For performance-sensitive frameworks that needs to handle potential
failures from frequently-called application code, and do not need to
include detailed structured information about the failure nor inspect
the result of the operation, this method returns a context manager that
will log exceptions and continue, that can be shared across multiple
invocations.  It should be instantiated at module scope to avoid
additional object creations.

For example::

    log = Logger(...)
    ignoringFrobErrors = log.failureHandler("while frobbing:")

    def hotLoop() -> None:
        with ignoringFrobErrors:
            frob()

This method is meant to capture unexpected exceptions from application
code; an exception that is caught and handled somehow should be logged,
if appropriate, via L{Logger.error} instead.  If some unknown exception
occurs and your code doesn't know how to handle it, as in the above
example, then this method provides a means to describe the failure in
nerd-speak.  This is done at L{LogLevel.critical} by default, since no
corrective guidance can be offered to an user/administrator, and the
impact of the condition is unknown.

@param format: a message format using new-style (PEP 3101) formatting.
    The logging event (which is a L{dict}) is used to render this
    format string.

@param level: a L{LogLevel} to use.

@see: L{Logger.failure}

@return: A context manager which does not return a value, but will
    always exit from exceptions.
c                *   > TR                  TU T5      $ r4   r=   )r   r   r   staticMessages    r   r   'Logger.failureHandler.<locals>.<lambda>  s    mQ)Nr   )rO   )r   r   r   s   ```r   failureHandlerLogger.failureHandler  s    V NOOr   )rc   rf   rd   )r&   r\   )NNN)rc   Optional[str]rd   zOptional[object]rf   zOptional['ILogObserver']r&   rK   r4   )rl   objectrm   zOptional[type]r&   z'Logger')r   r   r   r   r   r   r&   rK   )
r   r\   r    zOptional[Failure]r   r   r   r   r&   rK   )r   r   r   r   r&   rK   )r   r\   r   r   r   r   r&   zContextManager[Operation])r   r\   r   r   r&   zContextManager[None])r)   r*   r+   r,   r-   staticmethodr_   r9   rn   rt   r   r   r   r    r   r   r   r   r   r   r/   r   r   r   rX   rX   f   sW    	 	 $(#'-1	% % !% +	%
 
%:
@A 8<%%'4%GM%	%T &*"++	5@5@ #5@ 	5@
 5@ 
5@n43347  .6->->*O*O"**OJP*O	"*O^ #+++P+P +P 
	+P +Pr   rX   c                @    [         R                  X R                  5      $ )z7
Get a L{Logger} instance attached to the given class.
)_logrn   rj   )objs    r   
_loggerForr     s     <<]]++r   N)r   r   r&   rX   )r-   
__future__r   r   typesr   typingr   r   r   r	   r
   r   twisted.python.compatr   twisted.python.failurer   _interfacesr   r   _levelsr   r   r   r1   rO   rX   r   r   r   r   r   <module>r      sd   
 #   J J . * / 3 < < *WP WPt
 x,r   