§
    ÈtºfØ?  ã                  ó  — d Z ddlm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 ddlmZ ddlmZ dd	lmZmZ dd
lmZmZ  G d„ de¦  «        Z G d„ d¦  «        Z G d„ d¦  «        Z G d„ d¦  «        Z e¦   «         Zdd„ZdS )z
Logger class.
é    )Úannotations)Útime)ÚTracebackType)ÚAnyÚCallableÚContextManagerÚOptionalÚProtocolÚcast)Úcurrentframe)ÚFailureé   )ÚILogObserverÚLogTrace)ÚInvalidLogLevelErrorÚLogLevelc                  óZ   — e Zd ZdZed	d„¦   «         Zed
d„¦   «         Zed	d„¦   «         ZdS )Ú	Operationz™
    An L{Operation} represents the success (or lack thereof) of code performed
    within the body of the L{Logger.failureHandler} context manager.
    ÚreturnÚboolc                ó   — dS )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    úU/var/www/surfInsights/venv3-11/lib/python3.11/site-packages/twisted/logger/_logger.pyÚ	succeededzOperation.succeeded   ó   € € € ó    úFailure | Nonec                ó   — dS )zj
        Did the operation raise an exception?  If so, this L{Failure} is that
        exception.
        Nr   r   s    r   ÚfailurezOperation.failure#   r   r   c                ó   — dS )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   ÚfailedzOperation.failed*   r   r   N©r   r   )r   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úpropertyr   r!   r#   r   r   r   r   r      s~   € € € € € ðð ð
 ðð ð ñ „Xðð ðð ð ñ „Xðð ðð ð ñ „Xðð ð r   r   c                  ó\   — e Zd ZU dZded<   dZded<   dd„Zedd„¦   «         Zdd„Z	dd„Z
dS )Ú_FailCtxMgrFr   r   Nr   r!   ÚfailúCallable[[Failure], None]r   ÚNonec                ó   — || _         d S ©N©Ú_fail©r   r,   s     r   Ú__init__z_FailCtxMgr.__init__7   ó   € ØˆŒ
ˆ
ˆ
r   c                ó   — | j         d uS r0   ©r!   r   s    r   r#   z_FailCtxMgr.failed:   s   € àŒ| 4Ð'Ð'r   r   c                ó   — | S r0   r   r   s    r   Ú	__enter__z_FailCtxMgr.__enter__>   s   € Øˆr   Úexc_typeútype[BaseException] | NoneÚ	exc_valueúBaseException | NoneÚ	tracebackúTracebackType | Nonec               ón   — |�+t          ¦   «         }|| _        |                      |¦  «         nd| _        dS ©NT)r   r!   r2   r   ©r   r:   r<   r>   r!   s        r   Ú__exit__z_FailCtxMgr.__exit__A   s;   € ð ÐÝ‘i”iˆGØ"ˆDŒLØ�JŠJ�wÑÔÐÐà!ˆDŒNØˆtr   ©r,   r-   r   r.   r$   )r   r   ©r:   r;   r<   r=   r>   r?   r   r   )r%   r&   r'   r   Ú__annotations__r!   r4   r)   r#   r9   rC   r   r   r   r+   r+   3   s”   € € € € € € Ø€IÐÐÐÑØ"€GÐ"Ð"Ð"Ñ"ðð ð ð ð ð(ð (ð (ñ „Xð(ðð ð ð ðð ð ð ð ð r   r+   c                  ó&   — e Zd Zdd„Zdd„Zdd„ZdS )Ú_FastFailCtxMgrr,   r-   r   r.   c                ó   — || _         d S r0   r1   r3   s     r   r4   z_FastFailCtxMgr.__init__R   r5   r   c                ó   — d S r0   r   r   s    r   r9   z_FastFailCtxMgr.__enter__U   s   € Øˆr   r:   r;   r<   r=   r>   r?   r   c               ó^   — |�*t          ¦   «         }|| _        |                      |¦  «         dS rA   )r   r!   r2   rB   s        r   rC   z_FastFailCtxMgr.__exit__X   s1   € ð ÐÝ‘i”iˆGØ"ˆDŒLØ�JŠJ�wÑÔÐØˆtr   NrD   )r   r.   rE   )r%   r&   r'   r4   r9   rC   r   r   r   rH   rH   Q   sP   € € € € € ðð ð ð ðð ð ð ðð ð ð ð ð r   rH   c                  óÎ   — e Zd ZdZed'd„¦   «         Z	 	 	 d(d)d„Zd*d+d„Zd'd„Z	 d*d,d„Z	de
j        fd-d„Zd*d.d„Zd*d.d„Zd*d.d„Zd*d.d „Zd*d.d!„Ze
j        fd/d#„Ze
j        fd0d&„ZdS )1ÚLoggera~  
    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.
    r   Ústrc                 ó€   — 	 t          t          t          d¦  «        j        d         ¦  «        S # t          $ r Y dS w xY w)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   rN   r   Ú	f_globalsÚKeyErrorr   r   r   Ú_namespaceFromCallingContextz#Logger._namespaceFromCallingContextq   sG   € ð	Ý��\¨!™_œ_Ô6°zÔBÑCÔCÐCøÝð 	ð 	ð 	Ø�;�;ð	øøøs   ‚,/ ¯
=¼=NÚ	namespaceúOptional[str]ÚsourceúOptional[object]ÚobserverúOptional['ILogObserver']r.   c                ó~   — |€|                       ¦   «         }|| _        || _        |€ddlm} || _        dS || _        dS )a3  
        @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)rS   rT   rV   Ú_globalr[   rX   )r   rT   rV   rX   r[   s        r   r4   zLogger.__init__}   sW   € ð  ÐØ×9Ò9Ñ;Ô;ˆIà"ˆŒØˆŒàÐØ3Ð3Ð3Ð3Ð3Ð3à*<ˆDŒMˆMˆMà$ˆDŒMˆMˆMr   ÚinstanceÚobjectÚownerúOptional[type]ú'Logger'c                ó�   — |€J ‚|€|}n|}|                       d                     |j        |j        g¦  «        || j        ¬¦  «        S )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}.
        Nú.)rX   )Ú	__class__Újoinr&   r%   rX   )r   r]   r_   rV   s       r   Ú__get__zLogger.__get__š   s^   € ð& Ð Ð Ð àÐØˆFˆFàˆFà�~Š~Ø�HŠH�eÔ&¨¬Ð7Ñ8Ô8ØØ”]ð ñ 
ô 
ð 	
r   c                ó2   — d| j         j        › d| j        ›d�S )Nú<ú ú>)rd   r%   rT   r   s    r   Ú__repr__zLogger.__repr__º   s"   € Ø@�4”>Ô*Ð@Ð@¨T¬^Ð@Ð@Ð@Ð@r   Úlevelr   ÚformatÚkwargsc           	     óœ  — |t          j        ¦   «         vr5|                      dt          t	          |¦  «        ¦  «        || ¬¦  «         dS |}|                     | || j        | j        |t          ¦   «         ¬¦  «         d|v r5t          t          |d         ¦  «                             | | j        f¦  «         |                      |¦  «         dS )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   ÚupdaterT   rV   r   r   r   ÚappendrX   )r   rl   rm   rn   Úevents        r   ÚemitzLogger.emit½   sà   € ð �Ô.Ñ0Ô0Ð0Ð0Ø�LŠLØLÝÕ,¨UÑ3Ô3Ñ4Ô4Ø"Øð	 ñ ô ð ð ˆFàˆØ�ŠØØØœ.Ø”{ØÝ‘V”Vð 	ñ 	
ô 	
ð 	
ð ˜%ÐÐÝ•˜5 Ô-Ñ.Ô.×5Ò5°t¸T¼]Ð6KÑLÔLÐLà�Š�eÑÔÐÐÐr   r!   úOptional[Failure]c                óH   — |€t          ¦   «         } | j        ||fd|i|¤Ž dS )am  
        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   rm   r!   rl   rn   s        r   r!   zLogger.failureä   s:   € ðd ˆ?Ý‘i”iˆGàˆŒ	�%˜Ð?Ð?¨WÐ?¸Ð?Ð?Ð?Ð?Ð?r   c                ó8   —  | j         t          j        |fi |¤Ž dS )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   rm   rn   s      r   r‚   zLogger.debug  ó(   € ð 	ˆŒ	•(”. &Ð3Ð3¨FÐ3Ð3Ð3Ð3Ð3r   c                ó8   —  | j         t          j        |fi |¤Ž dS )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†   zLogger.info*  ó(   € ð 	ˆŒ	•(”- Ð2Ð2¨6Ð2Ð2Ð2Ð2Ð2r   c                ó8   —  | j         t          j        |fi |¤Ž dS )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‰   zLogger.warn9  r‡   r   c                ó8   —  | j         t          j        |fi |¤Ž dS )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‹   zLogger.errorH  r„   r   c                ó8   —  | j         t          j        |fi |¤Ž dS )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�   zLogger.criticalW  s)   € ð 	ˆŒ	•(Ô# VÐ6Ð6¨vÐ6Ð6Ð6Ð6Ð6r   úContextManager[Operation]c                ó4   ‡ ‡‡‡— t          ˆˆˆˆ fd„¦  «        S )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                ó$   •—  ‰j         ‰| ‰fi ‰¤ŽS r0   r7   )Úfrm   rn   rl   r   s    €€€€r   ú<lambda>z(Logger.failuresHandled.<locals>.<lambda>�  s   ø€  \ T¤\°&¸!¸UÐ%MÐ%MÀfÐ%MÐ%M€ r   )r+   )r   rm   rl   rn   s   ````r   ÚfailuresHandledzLogger.failuresHandledf  s*   øøøø€ õT ÐMÐMÐMÐMÐMÐMÐMÑNÔNÐNr   ÚstaticMessageúContextManager[None]c                ó0   ‡ ‡‡— t          ˆˆ ˆfd„¦  «        S )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                ó2   •— ‰                      ‰| ‰¦  «        S r0   r7   )r‘   rl   r   r”   s    €€€r   r’   z'Logger.failureHandler.<locals>.<lambda>½  s   ø€ ¨¯ª°mÀQÈÑ)NÔ)N€ r   )rH   )r   r”   rl   s   ```r   ÚfailureHandlerzLogger.failureHandler’  s&   øøø€ õV ÐNÐNÐNÐNÐNÐNÑOÔOÐOr   )r   rN   )NNN)rT   rU   rV   rW   rX   rY   r   r.   r0   )r]   r^   r_   r`   r   ra   )rl   r   rm   rU   rn   r^   r   r.   )
rm   rN   r!   r~   rl   r   rn   r^   r   r.   )rm   rU   rn   r^   r   r.   )rm   rN   rl   r   rn   r^   r   rŽ   )r”   rN   rl   r   r   r•   )r%   r&   r'   r(   ÚstaticmethodrS   r4   rf   rk   r}   r   r�   r!   r‚   r†   r‰   r‹   r“   r˜   r   r   r   rM   rM   f   s©  € € € € € ðð ð ð	ð 	ð 	ñ „\ð	ð $(Ø#'Ø-1ð	%ð %ð %ð %ð %ð:
ð 
ð 
ð 
ð 
ð@Að Að Að Að 8<ð%ð %ð %ð %ð %ðT &*Ø"Ô+ð	5@ð 5@ð 5@ð 5@ð 5@ðn4ð 4ð 4ð 4ð 4ð3ð 3ð 3ð 3ð 3ð3ð 3ð 3ð 3ð 3ð4ð 4ð 4ð 4ð 4ð7ð 7ð 7ð 7ð 7ð  .6Ô->ð*Oð *Oð *Oð *Oð *Oð^ #Ô+ð+Pð +Pð +Pð +Pð +Pð +Pð +Pr   rM   Úobjr^   r   c                óB   — t                                | | j        ¦  «        S )z?
    Get a L{Logger} instance attached to the given class.
    )Ú_logrf   rd   )rš   s    r   Ú
_loggerForr�   Ã  s   € õ �<Š<˜˜Sœ]Ñ+Ô+Ð+r   N)rš   r^   r   rM   )r(   Ú
__future__r   r   Útypesr   Útypingr   r   r   r	   r
   r   Útwisted.python.compatr   Útwisted.python.failurer   Ú_interfacesr   r   Ú_levelsr   r   r   r+   rH   rM   rœ   r�   r   r   r   ú<module>r¥      s©  ðð
ð ð #Ð "Ð "Ð "Ð "Ð "à Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð Ø JÐ JÐ JÐ JÐ JÐ JÐ JÐ JÐ JÐ JÐ JÐ JÐ JÐ JÐ JÐ Jà .Ð .Ð .Ð .Ð .Ð .Ø *Ð *Ð *Ð *Ð *Ð *Ø /Ð /Ð /Ð /Ð /Ð /Ð /Ð /Ø 3Ð 3Ð 3Ð 3Ð 3Ð 3Ð 3Ð 3ðð ð ð ð �ñ ô ð ð<ð ð ð ð ñ ô ð ð<ð ð ð ð ñ ô ð ð*WPð WPð WPð WPð WPñ WPô WPð WPðt
 €v�x„x€ð,ð ,ð ,ð ,ð ,ð ,r   