
    Mh=                     |   d Z ddlZddlZddlmZ ddlZddlZddlZddlZddlm	Z	m
Z
mZmZmZmZmZmZmZmZ ej        rddlZddlmZ ddlmZ ddlZeZeZeZej        Z G d deee	f                   Z G d	 d
          Z dede	fdZ!	 d+de	deee	f         de
e
eee	f                           ddfdZ"dee
e#         e
e$         e
d         f         dej%        fdZ&de$de
e'         fdZ( e)d          Z*dee         defdZ+ ej,        dej-                  Z.dedefdZ/ G d d          Z0 G d d           Z1d! Z2d"ed#edefd$Z3ej4        5                    d%          sej4        5                    d&          d'k    re3Z6n4	 dd(l7m8Z6 n,# e9$ r$ ej4        5                    d&          d)k    r e3Z6Y nw xY wd* Z:dS ),a  Miscellaneous utility functions and classes.

This module is used internally by Tornado.  It is not necessarily expected
that the functions and classes defined here will be useful to other
applications, but they are documented here in case they are.

The one public-facing part of this module is the `Configurable` class
and its `~Configurable.configure` method, which becomes a part of the
interface of its subclasses, including `.AsyncHTTPClient`, `.IOLoop`,
and `.Resolver`.
    N)getfullargspec)
AnyOptionalDictMappingListTupleMatchCallableTypeSequence)TracebackType)Unionc                   6    e Zd ZdZdedefdZdededdfdZdS )
ObjectDictzFMakes a dictionary behave like an object, with attribute-style access.namereturnc                 N    	 | |         S # t           $ r t          |          w xY wN)KeyErrorAttributeError)selfr   s     L/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/tornado/util.py__getattr__zObjectDict.__getattr__:   s:    	': 	' 	' 	' &&&	's   
 $valueNc                     || |<   d S r    )r   r   r   s      r   __setattr__zObjectDict.__setattr__@   s    T


    )__name__
__module____qualname____doc__strr   r   r   r   r   r   r   r   7   se        PP' ' ' ' ' ' C D      r   r   c                   X    e Zd ZdZddZddededefdZedefd	            Z	defd
Z
dS )GzipDecompressorzStreaming gzip decompressor.

    The interface is like that of `zlib.decompressobj` (without some of the
    optional arguments, but it understands gzip headers and checksums.
    r   Nc                 R    t          j        dt           j        z             | _        d S )N   )zlibdecompressobj	MAX_WBITSr   s    r   __init__zGzipDecompressor.__init__K   s$     "/T^0CDDr   r   r   
max_lengthc                 8    | j                             ||          S )a  Decompress a chunk, returning newly-available data.

        Some data may be buffered for later processing; `flush` must
        be called when there is no more input data to ensure that
        all data was processed.

        If ``max_length`` is given, some input data may be left over
        in ``unconsumed_tail``; you must retrieve this value and pass
        it back to a future call to `decompress` if it is not empty.
        )r*   
decompress)r   r   r.   s      r   r0   zGzipDecompressor.decompressQ   s     !,,UJ???r   c                     | j         j        S )z(Returns the unconsumed portion left over)r*   unconsumed_tailr,   s    r   r2   z GzipDecompressor.unconsumed_tail^   s     !11r   c                 4    | j                                         S )zReturn any remaining buffered data not yet returned by decompress.

        Also checks for errors such as truncated input.
        No other methods may be called on this object after `flush`.
        )r*   flushr,   s    r   r4   zGzipDecompressor.flushc   s     !'')))r   r   N)r   )r    r!   r"   r#   r-   bytesintr0   propertyr2   r4   r   r   r   r&   r&   D   s         E E E E@ @ @3 @u @ @ @ @ 2 2 2 2 X2*u * * * * * *r   r&   r   r   c                 \   |                      d          dk    rt          |           S |                     d          }t          d                    |dd                   |d         g          }	 t	          ||d                   S # t
          $ r t          d|d         z            w xY w)a  Imports an object by name.

    ``import_object('x')`` is equivalent to ``import x``.
    ``import_object('x.y.z')`` is equivalent to ``from x.y import z``.

    >>> import tornado.escape
    >>> import_object('tornado.escape') is tornado.escape
    True
    >>> import_object('tornado.escape.utf8') is tornado.escape.utf8
    True
    >>> import_object('tornado') is tornado
    True
    >>> import_object('tornado.missing_module')
    Traceback (most recent call last):
        ...
    ImportError: No module named missing_module
    .r   N)fromlistzNo module named %s)count
__import__splitjoingetattrr   ImportError)r   partsobjs      r   import_objectrE   l   s    $ zz#!$JJsOOE
SXXeCRCj))U2YK
@
@
@C<sE"I&&& < < <.r:;;;<s   2B #B+codegloblocc                 x    t          | t                    rt          | ddd          } t          | ||           d S )Nz<string>execT)dont_inherit)
isinstancer$   compilerJ   )rF   rG   rH   s      r   exec_inrN      sG     $ D tZdCCCtSr   exc_infor   c                     	 | d         !| d                              | d                   t          d          # d} w xY w)N      z'raise_exc_info called with no exception)NNN)with_traceback	TypeError)rO   s    r   raise_exc_inforU      sP    &A;"1+,,Xa[999EFFF &%%%%s   8: >ec                 \    t          | d          r| j        S | j        r| j        d         S dS )aL  Provides the errno from an Exception object.

    There are cases that the errno attribute was not set so we pull
    the errno out of the args but if someone instantiates an Exception
    without any args you will get a tuple error. So this function
    abstracts all that behavior to give you a safe way to get the
    errno.
    errnor   N)hasattrrX   args)rV   s    r   errno_from_exceptionr[      s8     q' w	
 vaytr   >abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789matchc                 ~    |                      d          }|d         t          v rt          d|d         z            |S )NrQ   r   zcannot unescape '\\%s')group	_alphanum
ValueError)r]   r_   s     r   _re_unescape_replacementrb      s=    KKNNEQx93eAh>???Lr   z\\(.)sc                 B    t                               t          |           S )zUnescape a string escaped by `re.escape`.

    May raise ``ValueError`` for regular expressions which could not
    have been produced by `re.escape` (for example, strings containing
    ``\d`` cannot be unescaped).

    .. versionadded:: 4.4
    )_re_unescape_patternsubrb   )rc   s    r   re_unescaperg      s      ##$<a@@@r   c                        e Zd ZdZdZdZdededef fdZed             Z	ed             Z
dd	ZeZ	 ed
             Zed             Zed             Zed             Z xZS )Configurablea*  Base class for configurable interfaces.

    A configurable interface is an (abstract) class whose constructor
    acts as a factory function for one of its implementation subclasses.
    The implementation subclass as well as optional keyword arguments to
    its initializer can be set globally at runtime with `configure`.

    By using the constructor as the factory method, the interface
    looks like a normal class, `isinstance` works as usual, etc.  This
    pattern is most useful when the choice of implementation is likely
    to be a global decision (e.g. when `~select.epoll` is available,
    always use it instead of `~select.select`), or when a
    previously-monolithic class has been split into specialized
    subclasses.

    Configurable subclasses must define the class methods
    `configurable_base` and `configurable_default`, and use the instance
    method `initialize` instead of ``__init__``.

    .. versionchanged:: 5.0

       It is now possible for configuration to be specified at
       multiple levels of a class hierarchy.

    NrZ   kwargsr   c                 n   |                                  }i }| |u r6|                                 }|j        r|                    |j                   n| }|                    |           |                                 |ur ||i |S t	                                          |          } |j        |i | |S r   )configurable_baseconfigured_class_Configurable__impl_kwargsupdatesuper__new__
initialize)clsrZ   rj   baseinit_kwargsimplinstance	__class__s          r   rq   zConfigurable.__new__   s    $$&&$;;''))D! 7""4#5666D6"""!!##4//4----77??4(( 	T1[111r   c                     t                      )zReturns the base class of a configurable hierarchy.

        This will normally return the class in which it is defined.
        (which is *not* necessarily the same as the ``cls`` classmethod
        parameter).

        NotImplementedErrorrs   s    r   rl   zConfigurable.configurable_base  s     "###r   c                     t                      )zBReturns the implementation class to be used if none is configured.rz   r|   s    r   configurable_defaultz!Configurable.configurable_default  s     "###r   c                     d S r   r   r,   s    r   _initializezConfigurable._initialize  s    r   c                     |                                  }t          |t                    r2t          j        t
          t                   t          |                    }|"t          ||           st          d| z            ||_
        ||_        dS )zSets the class to use when the base class is instantiated.

        Keyword arguments will be saved and added to the arguments passed
        to the constructor.  This can be used to set global defaults for
        some parameters.
        NzInvalid subclass of %s)rl   rL   r$   typingcastr   ri   rE   
issubclassra   _Configurable__impl_classrn   )rs   rv   rj   rt   s       r   	configurezConfigurable.configure$  s     $$&&dC   	H;tL1=3F3FGGDJtS$9$95;<<< #r   c                     |                                  }|j                            d          |                                 |_        |j        |j        S t          d          )z'Returns the currently configured class.r   Nzconfigured class not found)rl   __dict__getr~   r   ra   rs   rt   s     r   rm   zConfigurable.configured_class5  se     $$&& =899A # 8 8 : :D($$ 9:::r   c                 F    |                                  }|j        |j        fS r   rl   r   rn   r   s     r   _save_configurationz Configurable._save_configurationE  s&     $$&&!4#566r   c                 b    |                                  }|d         |_        |d         |_        d S )Nr   rQ   r   )rs   savedrt   s      r   _restore_configurationz#Configurable._restore_configurationK  s3     $$&&!!H"1Xr   r5   )r    r!   r"   r#   r   rn   r   rq   classmethodrl   r~   r   rr   r   rm   r   r   __classcell__)rx   s   @r   ri   ri      s+        D LMC 3 3      ( 	$ 	$ [	$ $ $ [$
    J $ $ [$  ; ; [; 7 7 [7
 & & [& & & & &r   ri   c                       e Zd ZdZdededdfdZdedee         fdZ	 dde	e
         d	eee
f         d
e
de
fdZde
de	e
         d	eee
f         dee
e	e
         eee
f         f         fdZdS )ArgReplacerzReplaces one value in an ``args, kwargs`` pair.

    Inspects the function signature to find an argument by name
    whether it is passed by position or keyword.  For use in decorators
    and similar wrappers.
    funcr   r   Nc                     || _         	 |                     |                              |          | _        d S # t          $ r d | _        Y d S w xY wr   )r   _getargnamesindexarg_posra   )r   r   r   s      r   r-   zArgReplacer.__init__[  s]    		 ,,T2288>>DLLL 	  	  	 DLLLL	 s   -8 AAc                     	 t          |          j        S # t          $ r/ t          |d          r|j        }|j        d |j                 cY S  w xY w)N	func_code)r   rZ   rT   rY   r   co_varnamesco_argcount)r   r   rF   s      r   r   zArgReplacer._getargnamesc  sn    	!$'',, 
	 
	 
	t[)) < ~'(:$*:(:;;;;
	s    5AArZ   rj   defaultc                     | j         %t          |          | j         k    r|| j                  S |                    | j        |          S )zReturns the old value of the named argument without replacing it.

        Returns ``default`` if the argument is not present.
        )r   lenr   r   )r   rZ   rj   r   s       r   get_old_valuezArgReplacer.get_old_valuer  sA     <#D		DL(@(@%%::di111r   	new_valuec                     | j         ?t          |          | j         k    r'|| j                  }t          |          }||| j         <   n$|                    | j                  }||| j        <   |||fS )a  Replace the named argument in ``args, kwargs`` with ``new_value``.

        Returns ``(old_value, args, kwargs)``.  The returned ``args`` and
        ``kwargs`` objects may not be the same as the input objects, or
        the input objects may be mutated.

        If the named argument was not found, ``new_value`` will be added
        to ``kwargs`` and None will be returned as ``old_value``.
        )r   r   listr   r   )r   r   rZ   rj   	old_values        r   replacezArgReplacer.replace~  sr     <#D		DL(@(@T\*I::D!*D 

49--I )F49$&&r   r   )r    r!   r"   r#   r   r$   r-   r   r   r   r   r   r   r	   r   r   r   r   r   r   S  s         X  S  T         d3i      KO
2 
2SM
2+/S>
2DG
2	
2 
2 
2 
2''$,SM';?S>'	sHSM4S>1	2' ' ' ' ' 'r   r   c                 *    |                                  S )z@Equivalent to ``td.total_seconds()`` (introduced in Python 2.7).)total_seconds)tds    r   timedelta_to_secondsr     s     r   maskdatac                     t          j         d|           }t          j         d|          }t          t          |                    D ]}||         ||dz           z  ||<   |                                S )aQ  Websocket masking function.

    `mask` is a `bytes` object of length 4; `data` is a `bytes` object of any length.
    Returns a `bytes` object of the same length as `data` with the mask applied
    as specified in section 5.3 of RFC 6455.

    This pure-python implementation may be replaced by an optimized version when available.
    B   )arrayranger   tobytes)r   r   mask_arrunmasked_arris        r   _websocket_mask_pythonr     sq     {3%%H;sD))L3t99 < <&q/HQUO;Q!!!r   TORNADO_NO_EXTENSIONTORNADO_EXTENSION0)websocket_mask1c                  2    dd l } |                                 S )Nr   )doctestDocTestSuite)r   s    r   doctestsr     s    NNN!!!r   r   );r#   r   asyncioinspectr   osrer   r)   r   r   r   r   r   r	   r
   r   r   r   TYPE_CHECKINGdatetimetypesr   r   unittestr6   
bytes_typer$   unicode_typebasestring_typeTimeoutErrorr   r&   rE   rN   typeBaseExceptionNoReturnrU   r7   r[   	frozensetr`   rb   rM   DOTALLre   rg   ri   r   r   r   environr   _websocket_masktornado.speedupsr   rB   r   r   r   r   <module>r      s1  
 
   " " " " " " 				 				                          
  OOO######OOO
 

 #
 
 
 
 
c3h 
 
 
%* %* %* %* %* %* %* %*P< < < < < << SW 
#s(^*28GCH<M3N*O	   &HTNH]$;Xo=VVW&_& & & &M hsm    $ IVWW	E#J 3     "rz(BI66 	A3 	A3 	A 	A 	A 	AD& D& D& D& D& D& D& D&N@' @' @' @' @' @' @' @'F  " "e " " " " "  :>>()) 
1RZ^^<O-P-PTW-W-W -OO1FFFFFFF 1 1 1:>>-..#5501" " " " "s   F &F65F6