%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/twisted/python/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/twisted/python/__pycache__/log.cpython-312.pyc

�

Ϫ�f�W�	��dZddlZddlZddlZddlmZmZddlmZmZddl	m
Z
mZmZm
Z
mZddlmZddlmZmZmZmZmZmZmZmZddl m!Z!dd	l"m#Z$dd
l%m&Z&m'Z'm(Z(m)Z)ddl*m+Z+ee,e
fZ-Gd�d
�Z.Gd�de�Z/e&j`e.ddi�d�Z1d�Z2d9d�Z3e3Z4Gd�d�ZGd�d�Ze+e�de5�vrnd�Z6eeee��Z7e6e7jp�d��Z8e6e7jr�d��Z9e6e7jt�d��Z:e6e7jv�d��Z;d e,d!ee,e
fd"e,fd#�Z<d$e-d"e
e,fd%�Z=Gd&�d'e�Z>Gd(�d)e>�Z?Gd*�d+e>�Z@Gd,�d-�ZAd.�ZBd:d/�ZCGd0�d1�ZDd2�ZEd3e5�vrXee�ej�eGej�d4d��5�aIee�ej�eGej�d4d��5�ZLGd6�d7e>�ZMd8e5�vreM�ZNyy);z%
Logging and metrics infrastructure.
�N)�ABC�abstractmethod)�datetime�timezone)�Any�BinaryIO�Dict�Optional�cast)�	Interface)�LegacyLogObserverWrapper�Logger�LoggingFile�LogLevel�LogPublisher�STDLibLogObserver�globalLogBeginner�globalLogPublisher)�LogBeginner)�publishToNewObserver)�context�failure�reflect�util)�synchronizec��eZdZdZy)�ILogContextz�
    Actually, this interface is just a synonym for the dictionary interface,
    but it serves as a key for the default information in a log.

    I do not inherit from C{Interface} because the world is a cruel place.
    N)�__name__�
__module__�__qualname__�__doc__���4/usr/lib/python3/dist-packages/twisted/python/log.pyrr%s��r#rc� �eZdZdZdeddfd�Zy)�ILogObserverz�
    An observer which can do something with log events.

    Given that most log observers are actually bound methods, it's okay to not
    explicitly declare provision of this interface.
    �	eventDict�returnNc��y)a6
        Log an event.

        @param eventDict: A dictionary with arbitrary keys.  However, these
            keys are often available:
              - C{message}: A C{tuple} of C{str} containing messages to be
                logged.
              - C{system}: A C{str} which indicates the "system" which is
                generating this event.
              - C{isError}: A C{bool} indicating whether this event represents
                an error.
              - C{failure}: A L{failure.Failure} instance
              - C{why}: Used as header of the traceback in case of errors.
              - C{format}: A string format used in place of C{message} to
                customize the event.  The intent is for the observer to format
                a message by doing something like C{format % eventDict}.
        Nr")r's r$�__call__zILogObserver.__call__6��r#)rrr r!�	EventDictr*r"r#r$r&r&.s����I��$�r#r&�system�-c��tjt�j�}|j	|�tj
t|i|g|��i|��S�N)r�getr�copy�update�call)�ctx�func�args�kw�newCtxs     r$�callWithContextr:MsE��
�[�[��
%�
*�
*�
,�F�
�M�M�#���<�<��f�-�t�A�d�A�b�A�Ar#c���	|j�}	t	d|i|g|��i|��S#t$r�t$rd}t|��Y�5wxYw#t$r�t$rt|��YywxYw)z�
    Utility method which wraps a function in a try:/except:, logs a failure if
    one occurs, and uses the system's logPrefix.
    z(buggy logPrefix method))r-r-N)�	logPrefix�KeyboardInterrupt�
BaseException�errr:)�loggerr6r7r8�lps     r$�callWithLoggerrBSs��
�
�
�
�
�����"�~�t�A�d�A�b�A�A��
��
���
'���2����
��
����2���s �%�A� A�A�A,�+A,c��|�tj�}t|tj�rtd||dd�|��yt|t�r#tdtj|�|dd�|��ytt|�f|dd�|��y)a
    Write a failure to the log.

    The C{_stuff} and C{_why} parameters use an underscore prefix to lessen
    the chance of colliding with a keyword argument the application wishes
    to pass.  It is intended that they be supplied with arguments passed
    positionally, not by keyword.

    @param _stuff: The failure to log.  If C{_stuff} is L{None} a new
        L{Failure} will be created from the current exception state.  If
        C{_stuff} is an C{Exception} instance it will be wrapped in a
        L{Failure}.
    @type _stuff: L{None}, C{Exception}, or L{Failure}.

    @param _why: The source of this failure.  This will be logged along with
        C{_stuff} and should describe the context in which the failure
        occurred.
    @type _why: C{str}
    N�)r�why�isError)rErFr")r�Failure�
isinstance�msg�	Exception�repr)�_stuff�_whyr8s   r$r?r?gsv��(�~����"���&�'�/�/�*��6�F��a�6�2�6�	�F�I�	&��G�G�O�O�F�+��q�G�B�G��D��L�4�d�A�4��4r#c��eZdZdZd�Zy)rzM
    This represents a class which may 'own' a log. Used by subclassing.
    c��y)z�
        Override this method to insert custom logging behavior.  Its
        return value will be inserted in front of every line.  It may
        be called more times than the number of output lines.
        r.r"��selfs r$r<zLogger.logPrefix�s��r#N)rrr r!r<r"r#r$rr�s���r#rc�T�eZdZdZdgZdddefd�Zed��Zd�Z	d�Z
d�Zd	�Zd
�Z
y)rz5
    Class for singleton log message publishing.
    rINc�l�|�t�}|�|}|�
t�}||_||_g|_|�Gt�}|j	|�t|t
tt��tt�}||_||_|j|_|jj|_
yr0)�NewPublisher�_observerPublisher�_publishPublisher�_legacyObservers�addObserverrrr�NullFile�sys�warnings�_logBeginner�_warningsModule�showwarning�_oldshowwarning)rQ�observerPublisher�publishPublisher�logBeginner�warningsModule�beginnerPublishers      r$�__init__zLogPublisher.__init__�s����#�+�~�� �(�$4�!��$� ,���"3���!1��� "����� ,����)�)�*;�<�%�!�4��(�*�#=�s�H��K�(���-���-�9�9����,�,�8�8��r#c�T�|jD�cgc]}|j��c}Scc}w)z�
        Property returning all observers registered on this L{LogPublisher}.

        @return: observers previously added with L{LogPublisher.addObserver}
        @rtype: L{list} of L{callable}
        )rW�legacyObserver)rQ�xs  r$�	observerszLogPublisher.observers�s$��+/�*?�*?�@�Q�� � �@�@��@s�%c��t|�}|jj|�|jj	|gd|�y)a&
        Begin logging to the L{LogBeginner} associated with this
        L{LogPublisher}.

        @param other: the observer to log to.
        @type other: L{LogBeginner}

        @param setStdout: if true, send standard I/O to the observer as well.
        @type setStdout: L{bool}
        TN)r
rW�appendr\�beginLoggingTo)rQ�other�	setStdout�wrappeds    r$�
_startLoggingzLogPublisher._startLogging�s<��+�5�1�����$�$�W�-����(�(�'��D�)�Dr#c��|jj|jk(r|j|j_yy)z�
        Clean-up hook for fixing potentially global state.  Only for testing of
        this module itself.  If you want less global state, use the new
        warnings system in L{twisted.logger}.
        N)r]r^r_rPs r$�_stopLoggingzLogPublisher._stopLogging�s8�����+�+�t�/?�/?�?�/3�/C�/C�D� � �,�@r#c��t|�}|jj|�|jj	|�y)z�
        Add a new observer.

        @type other: Provider of L{ILogObserver}
        @param other: A callable object that will be called with each new log
            message (a dict).
        N)r
rWrkrUrX)rQrmros   r$rXzLogPublisher.addObserver�s6��+�5�1�����$�$�W�-����+�+�G�4r#c��|jD]I}|j|k(s�|jj|�|jj	|�yy)z%
        Remove an observer.
        N)rWrg�removerU�removeObserver)rQrm�observers   r$rvzLogPublisher.removeObserver�sR���-�-�	�H��&�&�%�/��%�%�,�,�X�6��'�'�6�6�x�@��		r#c��tttjt�xsij��}|j
|�||d<tj�|d<d|vrd|d<t|j|t�y)ac
        Log a new message.

        The message should be a native string, i.e. bytes on Python 2 and
        Unicode on Python 3. For compatibility with both use the native string
        syntax, for example::

            >>> log.msg('Hello, world.')

        You MUST avoid passing in Unicode on Python 2, and the form::

            >>> log.msg('Hello ', 'world.')

        This form only works (sometimes) by accident.

        Keyword arguments will be converted into items in the event
        dict that is passed to L{ILogObserver} implementations.
        Each implementation, in turn, can define keys that are used
        by it specifically, in addition to common keys listed at
        L{ILogObserver.__call__}.

        For example, to set the C{system} parameter while logging
        a message::

        >>> log.msg('Started', system='Foo')

        �message�timerFrN)rr,rr1rr2r3rz�_publishNewrV�textFromEventDict)rQryr8�actualEventDicts    r$rIzLogPublisher.msg�st��8�y�7�;�;�{�+C�+I�r�*O�*O�*Q�R�����r�"�%,��	�"�"&�)�)�+�����O�+�)*�O�I�&��D�*�*�O�=N�Or#)rrr r!�synchronizedr[re�propertyrirprrrXrvrIr"r#r$rr�sU����7�L�����9�8�A��A�
E�D�
5��#Pr#r�theLogPublisherc����fd�}|S)a�
        A decorator that returns its argument rather than the thing it is
        decorating.

        This allows the documentation generator to see an alias for a method or
        constant as an object with a docstring and thereby document it and
        allow references to it statically.

        @param something: An object to create an alias for.
        @type something: L{object}

        @return: a 1-argument callable that returns C{something}
        @rtype: L{object}
        c����Sr0r")�thingWithADocstring�	somethings �r$�decoratez_actually.<locals>.decorate,s	����r#r")r�r�s` r$�	_actuallyr�s��� 	��r#)r`rarbc��y)z�
        Add a log observer to the global publisher.

        @see: L{LogPublisher.addObserver}

        @param observer: a log observer
        @type observer: L{callable}
        Nr"�rws r$rXrX7r+r#c��y)z�
        Remove a log observer from the global publisher.

        @see: L{LogPublisher.removeObserver}

        @param observer: a log observer previously added with L{addObserver}
        @type observer: L{callable}
        Nr"r�s r$rvrvBr+r#c��y)a?
        Publish a message to the global log publisher.

        @see: L{LogPublisher.msg}

        @param message: the log message
        @type message: C{tuple} of L{str} (native string)

        @param event: fields for the log event
        @type event: L{dict} mapping L{str} (native string) to L{object}
        Nr")ry�events  r$rIrIMr+r#c��y)zw
        Publish a Python warning through the global log publisher.

        @see: L{LogPublisher.showwarning}
        Nr"r"r#r$r^r^[r+r#�	fmtString�fmtDictr(c��	||z}|S#t$r�t$r5d|�d|��}Y|S#t$rd|�d�}n#t$rd}YnwxYwYY|SwxYwwxYw)a�
    Try to format a string, swallowing all errors to always return a string.

    @note: For backward-compatibility reasons, this function ensures that it
        returns a native string, meaning L{bytes} in Python 2 and L{str} in
        Python 3.

    @param fmtString: a C{%}-format string
    @param fmtDict: string formatting arguments for C{fmtString}

    @return: A native string, formatted from C{fmtString} and C{fmtDict}.
    z>Invalid format string or unformattable object in log message: z, z-UNFORMATTABLE OBJECT WRITTEN TO LOG with fmt z, MESSAGE LOSTzJPATHOLOGICAL ERROR IN BOTH FORMAT STRING AND MESSAGE DETAILS, MESSAGE LOST)r=r>)r�r��texts   r$�_safeFormatr�ds���&��7�"��*�K��)��
���	�*3�G�=�
� �K���
	�	
�'0�2���!�
�4��
���K�
	��
�sD�	�A�&�	A�6�A�A�A�A�A�A�A�Ar'c���|d}|s�|drsd|vrott|jd��}|rtj|�}nd}	tt
j|d�j�}|dz|z}|Sd	|vrt|d	|�}|Syd
jttj|��}|S#t$r}dt|�z}Yd}~�gd}~wwxYw)a
    Extract text from an event dict passed to a log observer. If it cannot
    handle the dict, it returns None.

    The possible keys of eventDict are:
     - C{message}: by default, it holds the final text. It's required, but can
       be empty if either C{isError} or C{format} is provided (the first
       having the priority).
     - C{isError}: boolean indicating the nature of the event.
     - C{failure}: L{failure.Failure} instance, required if the event is an
       error.
     - C{why}: if defined, used as header of the traceback in case of errors.
     - C{format}: string format used in place of C{message} to customize
       the event. It uses all keys present in C{eventDict} to format
       the text.
    Other keys will be used when applying the C{format}, or ignored.
    ryrFrrEzUnhandled Errorz(unable to obtain traceback): N�
�format� )r�strr1r�safe_strrrG�getTracebackrJr��join�map)r'�edmrE�	traceback�er�s      r$r|r|�s���$�I�
�C���Y��I��$:��s�I�M�M�%�0�1�C���&�&�s�+��'��
F� ����)�I�2F�G�T�T�V�	���:�	�)�D��K���
"��y��2�I�>�D��K���x�x��G�,�,�c�2�3���K���
F�<�s�1�v�E�	��
F�s�+C�	C"�
C�C"c�:�eZdZdZededdfd��Zdd�Zdd�Zy)	�_GlobalStartStopObserverzB
    Mix-in for global log observers that can start and stop.
    r'r(Nc��y)zR
        Emit the given log event.

        @param eventDict: a log event
        Nr"�rQr's  r$�emitz_GlobalStartStopObserver.emit�r+r#c�.�t|j�y)z-
        Start observing log events.
        N)rXr�rPs r$�startz_GlobalStartStopObserver.start�s��	�D�I�I�r#c�.�t|j�y)z,
        Stop observing log events.
        N)rvr�rPs r$�stopz_GlobalStartStopObserver.stop�s��	�t�y�y�!r#)r(N)	rrr r!rr,r�r�r�r"r#r$r�r��s3�����i��D�����"r#r�c�H�eZdZUdZdZeeed<d�Zd�Z	d�Z
deddfd	�Zy)
�FileLogObserverz�
    Log observer that writes to a file-like object.

    @type timeFormat: C{str} or L{None}
    @ivar timeFormat: If not L{None}, the format string passed to strftime().
    N�
timeFormatc�H�|j|_|j|_yr0)�write�flush)rQ�fs  r$rezFileLogObserver.__init__�s���W�W��
��W�W��
r#c���tj|tj�j	d��tj|�z
}|j
dz|jzS)a*
        Return the current local timezone offset from UTC.

        @type when: C{int}
        @param when: POSIX (ie, UTC) timestamp for which to find the offset.

        @rtype: C{int}
        @return: The number of seconds offset from UTC.  West is positive,
        east is negative.
        N��tzinfoi�Q)r�
fromtimestampr�utc�replace�days�seconds)rQ�when�offsets   r$�getTimezoneOffsetz!FileLogObserver.getTimezoneOffset�s[���'�'��h�l�l�;�C�C��D�
��"�"�4�(�)���{�{�l�+�f�n�n�<�<r#c
��|j�.tj|�j|j�S|j	|�}tj||zt
j�jd��}tt|dzdz��}tt|dzdz��}|dkrd}nd}d|j|j|j|j|j|j|||f	zS)a
        Format the given UTC value as a string representing that time in the
        local timezone.

        By default it's formatted as an ISO8601-like string (ISO8601 date and
        ISO8601 time separated by a space). It can be customized using the
        C{timeFormat} attribute, which will be used as input for the underlying
        L{datetime.datetime.strftime} call.

        @type when: C{int}
        @param when: POSIX (ie, UTC) timestamp for which to find the offset.

        @rtype: C{str}
        Nr��<rr.�+z%%d-%02d-%02d %02d:%02d:%02d%s%02d%02d)r�rr��strftimer�rr�r��abs�int�year�month�day�hour�minute�second)rQr��tzOffset�tzHour�tzMin�tzSigns      r$�
formatTimezFileLogObserver.formatTime�s����?�?�&��)�)�$�/�8�8����I�I��*�*�4�0�0���%�%�d�X�o�x�|�|�D�L�L��M�
���S��B���+�,�-���C��2�
��*�+�,���a�<��F��F�6��I�I��J�J��H�H��I�I��K�K��K�K����
:
�

�
	
r#r'r(c��t|�}|�y|j|d�}|d|jdd�d�}td|�}t	j
|j|dz|z�t	j
|j�y)	z|
        Format the given log event as text and write it to the output file.

        @param eventDict: a log event
        Nrzr-r�z
	)r-r�z[%(system)s] %(text)s
r�)r|r�r�r�r�untilConcludesr�r�)rQr'r��timeStrr��msgStrs      r$r�zFileLogObserver.emits��!��+���<���/�/�)�F�"3�4��&�x�0�$�,�,�t�V�:T�U���6��@�����D�J�J��#�
��(>�?����D�J�J�'r#)
rrr r!r�r
r��__annotations__rer�r�r,r�r"r#r$r�r��s:���!%�J���
�$��
=� &
�P(�i�(�D�(r#r�c�(�eZdZdZdd�Zdeddfd�Zy)�PythonLoggingObserveraL
    Output twisted messages to Python standard library L{logging} module.

    WARNING: specific logging configurations (example: network) can lead to
    a blocking system. Nothing is done here to prevent that, so be sure to not
    use this: code within Twisted, such as twisted.web, assumes that logging
    does not block.
    c�$�t|�|_y)zi
        @param loggerName: identifier used for getting logger.
        @type loggerName: C{str}
        N)�NewSTDLibLogObserver�_newObserver)rQ�
loggerNames  r$rezPythonLoggingObserver.__init__6s��
1��<��r#r'r(Nc�D�d|vrt|j|t�yy)a(
        Receive a twisted log entry, format it and bridge it to python.

        By default the logging level used is info; log.err produces error
        level, and you can customize the level by using the C{logLevel} key::

            >>> log.msg('debugging', logLevel=logging.DEBUG)
        �
log_formatN)r{r�r|r�s  r$r�zPythonLoggingObserver.emit=s$���9�$���)�)�9�6G�H�%r#)�twisted)rrr r!rer,r�r"r#r$r�r�,s"���=�
I�i�
I�D�
Ir#r�c�\�eZdZdZdZdZdZdZd
d�Zd�Z	d�Z
d	�Zd
�ZeZ
eZeZeZd�Zd�Zy)�StdioOnnaStickaP
    Class that pretends to be stdout/err, and turns writes into log messages.

    @ivar isError: boolean indicating whether this is stderr, in which cases
                   log messages will be logged as errors.

    @ivar encoding: unicode encoding used to encode any unicode strings
                    written to this object.
    r�wbz
<stdio (log)>Nc�Z�||_|�tj�}||_d|_y)N�)rFrZ�getdefaultencoding�encoding�buf)rQrFr�s   r$rezStdioOnnaStick.__init__Zs+��������-�-�/�H� ��
���r#c��yr0r"rPs r$�closezStdioOnnaStick.closea���r#c��y)N���r"rPs r$�filenozStdioOnnaStick.filenods��r#c��yr0r"rPs r$r�zStdioOnnaStick.flushgr�r#c��td��)Nzcan't read from the log!)�OSErrorrPs r$�readzStdioOnnaStick.readjs���0�1�1r#c��|j|zjd�}|d|_|dd}|D]}t|d|j���y)Nr�r�rrD��printedrF)r��splitrIrF)rQ�data�d�messagesrys     r$r�zStdioOnnaStick.writersO��
�X�X��_�#�#�D�)���R�5����Q�r�7���	:�G����D�L�L�9�	:r#c�B�|D]}t|d|j���y)NrDr�)rIrF)rQ�lines�lines   r$�
writelineszStdioOnnaStick.writelinesys!���	7�D���a����6�	7r#)rN)rrr r!�closed�	softspace�mode�namerer�r�r�r��readline�	readlines�seek�tellr�r�r"r#r$r�r�JsV����F��I��D��D��
��
�2��H��I��D��D�:�7r#r�c�p�t|t�ryt|�}t|jg|��i|��|S)z�
    Initialize logging to a specified file.

    @return: A L{FileLogObserver} if a new observer is added, None otherwise.
    N)rHrr��startLoggingWithObserverr�)�file�ar8�flos    r$�startLoggingr~s6���$��$��
�$�
�C��S�X�X�0��0�R�0��Jr#c�F�tj||�td�y)z�
    Initialize logging to a specified observer. If setStdout is true
    (defaults to yes), also redirect sys.stdout and sys.stderr
    to the specified file.
    zLog opened.N)r�rprI)rwrns  r$r�r��s���!�!�(�I�6��
�r#c�,�eZdZdZdZd�Zd�Zd�Zd�Zy)rYz6
    A file-like object that discards everything.
    rc��y�z
        Do nothing.
        Nr"rPs r$r�z
NullFile.read�r+r#c��y)zW
        Do nothing.

        @param bytes: data
        @type bytes: L{bytes}
        Nr")rQ�bytess  r$r�zNullFile.write�r+r#c��yrr"rPs r$r�zNullFile.flush�r+r#c��yrr"rPs r$r�zNullFile.close�r+r#N)	rrr r!r�r�r�r�r�r"r#r$rYrY�s"����I��
��
r#rYc��t�ay)zC
    Discard messages logged via the global C{logfile} object.
    N)rY�logfiler"r#r$�discardLogsr
�s��
�j�Gr#rr�)r@�levelr�c�8�eZdZdZej
Zdeddfd�Zy)�DefaultObserverz�
    Default observer.

    Will ignore all non-error messages and send error messages to sys.stderr.
    Will be removed when startLogging() is called for the first time.
    r'r(Nc��|drCt|�}|�|jj|�|jj�yy)zN
        Emit an event dict.

        @param eventDict: an event dict
        rFN)r|�stderrr�r�)rQr'r�s   r$r�zDefaultObserver.emit�sC���Y��$�Y�/�D������!�!�$�'��K�K����	 r#)rrr r!rZrr,r�r"r#r$rr�s%����Z�Z�F�
 �i�
 �D�
 r#r�defaultObserver)NN)rD)Or!rZrzr[�abcrrrr�typingrrr	r
r�zope.interfacer�twisted.loggerr
r�	NewLoggerrr�NewLogLevelrrTrr�r�newGlobalLogBeginnerr�newGlobalLogPublisher�twisted.logger._globalr�twisted.logger._legacyrr{�twisted.pythonrrrr�twisted.python.threadablerr�r,rr&�
setDefaultr:rBr?�deferr�globalsr�r�rXrvrIr^r�r|r�r�r�r�rr�rYr
�info�getattr�stdoutr�errorr�logerrrrr"r#r$�<module>r(si��
�
���#�'�6�6�$�	�	�	�/�F�:�:�1���c��N�	����9��8����;��3��0�B��(5�<

����~P�~P�B�L���G�I�%��*#�/�.�(��O���*�*�+��,����-�-�.��/����"�"�#��$����*�*�+��,��)�3�)��c�3�h��)�C�)�X&��&�x��}�&�R"�s�"�4V(�.�V(�rI�4�I�<17�17�h
����>�
�G�I����{��������Z��6��G�
��{��������Z��6��F� �.� �.�G�I�%�%�'�O�&r#

Zerion Mini Shell 1.0