HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //home/arjun/projects/env/lib/python3.10/site-packages/tornado/__pycache__/util.cpython-310.pyc
o

wey?�@s�dZddlZddlZddlZddlmZddlZddlZddlZddl	Z	ddlm
Z
mZmZm
Z
mZmZmZmZmZmZejrSddlZddlmZddlmZddlZeZeZeZzddlm Z Wne!yxdege"ffd	d
�Z#e#�Z Ynwej$Z$Gdd�deee
f�Z%Gd
d�de&�Z'dede
fdd�Z(	d7de
deee
fdeee
ee
fddfdd�Z)deee*ee+edfdej,fdd�Z-de+dee.fdd�Z/e0d�Z1deedefd d!�Z2e�3d"ej4�Z5d#edefd$d%�Z6Gd&d'�d'e&�Z7Gd(d)�d)e&�Z8d*d+�Z9d,ed-edefd.d/�Z:ej;�<d0��s"ej;�<d1�d2k�r%e:Z=nzdd3l>m?Z=Wne!�yCej;�<d1�d4k�r?�e:Z=Ynwd5d6�Z@dS)8a�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)�Union��
is_finalizing�returncs,g�t��fdd��dtf�fdd�}|S)Ncs
��d�S�N)�append���Lr�E/home/arjun/projects/env/lib/python3.10/site-packages/tornado/util.py�<lambda>8s
z-_get_emulated_is_finalizing.<locals>.<lambda>rcs�gkSrrrrrrr:sz2_get_emulated_is_finalizing.<locals>.is_finalizing)�atexit�register�boolrrrr�_get_emulated_is_finalizing6src@s8eZdZdZdedefdd�Zdededdfdd	�ZdS)
�
ObjectDictzFMakes a dictionary behave like an object, with attribute-style access.�namercCs"z||WStyt|��wr)�KeyError�AttributeError)�selfrrrr�__getattr__Ks

�zObjectDict.__getattr__�valueNcCs|||<dSrr)r!rr#rrr�__setattr__QszObjectDict.__setattr__)�__name__�
__module__�__qualname__�__doc__�strrr"r$rrrrrHsrc@sReZdZdZddd�Zddededefd	d
�Zedefdd��Z	defd
d�Z
dS)�GzipDecompressorz�Streaming gzip decompressor.

    The interface is like that of `zlib.decompressobj` (without some of the
    optional arguments, but it understands gzip headers and checksums.
    rNcCst�dtj�|_dS)N�)�zlib�
decompressobj�	MAX_WBITS�r!rrr�__init__\szGzipDecompressor.__init__rr#�
max_lengthcCs|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#r1rrrr2bszGzipDecompressor.decompresscCs|jjS)z(Returns the unconsumed portion left over)r-�unconsumed_tailr/rrrr3o�z GzipDecompressor.unconsumed_tailcCs
|j��S)z�Return 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/rrrr5ts
zGzipDecompressor.flush�rN)r)r%r&r'r(r0�bytes�intr2�propertyr3r5rrrrr*Us

r*rcCsp|�d�dkrt|�S|�d�}td�|dd��|dgd�}zt||d�WSty7td|d��w)aImports 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
    �.rN���)�fromlistzNo module named %s)�count�
__import__�split�join�getattrr �ImportError)r�parts�objrrr�
import_object}s
 �rE�code�glob�loccCs*t|t�r
t|dddd�}t|||�dS)Nz<string>�execT)�dont_inherit)�
isinstancer)�compilerI)rFrGrHrrr�exec_in�s
rM�exc_infor
cCs.z|ddur|d�|d��td��d}w)N��z'raise_exc_info called with no exception)NNN)�with_traceback�	TypeError)rNrrr�raise_exc_info�s
rS�ecCs$t|d�r|jS|jr|jdSdS)aLProvides 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.
    �errnorN)�hasattrrU�args)rTrrr�errno_from_exception�s



rX�>abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789�matchcCs*|�d�}|dtvrtd|d��|S)NrOrzcannot unescape '\\%s')�group�	_alphanum�
ValueError)rZr[rrr�_re_unescape_replacement�s
r^z\\(.)�scCst�t|�S)z�Unescape 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�subr^)r_rrr�re_unescape�s	rbcs�eZdZdZdZdZdededef�fdd�Zedd	��Z	ed
d��Z
ddd
�ZeZ	edd��Z
edd��Zedd��Zedd��Z�ZS)�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.

    NrW�kwargsrcs||��}i}||ur|��}|jr|�|j�n|}|�|�|��|ur,||i|��Stt|��|�}|j|i|��|Sr)�configurable_base�configured_class�_Configurable__impl_kwargs�update�superrc�__new__�
initialize)�clsrWrd�base�init_kwargs�impl�instance��	__class__rrrjs�
zConfigurable.__new__cC�t��)z�Returns 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�rlrrrres
zConfigurable.configurable_basecCrs)zBReturns the implementation class to be used if none is configured.rtrvrrr�configurable_default#sz!Configurable.configurable_defaultcCsdSrrr/rrr�_initialize)szConfigurable._initializecKsT|��}t|t�rt�ttt|��}|dur"t||�s"t	d|��||_
||_dS)z�Sets 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.
        NzInvalid subclass of %s)rerKr)�typing�castrrcrE�
issubclassr]�_Configurable__impl_classrg)rlrordrmrrr�	configure5s	

zConfigurable.configurecCs:|��}|j�d�dur|��|_|jdur|jStd��)z'Returns the currently configured class.r|Nzconfigured class not found)re�__dict__�getrwr|r]�rlrmrrrrfFs

zConfigurable.configured_classcCs|��}|j|jfSr�rer|rgr�rrr�_save_configurationVsz Configurable._save_configurationcCs |��}|d|_|d|_dS)NrrOr�)rl�savedrmrrr�_restore_configuration\s
z#Configurable._restore_configurationr6)r%r&r'r(r|rgrrj�classmethodrerwrxrkr}rfr�r��
__classcell__rrrqrrc�s("





rcc
@s�eZdZdZdededdfdd�Zdedeefdd	�Z	dd
e	e
deee
fde
de
fd
d�Zde
d
e	e
deee
fde
e
e	e
eee
fffdd�ZdS)�ArgReplacerz�Replaces 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.
    �funcrrNcCs:||_z|�|��|�|_WdStyd|_YdSwr)r�_getargnames�index�arg_posr])r!r�rrrrr0ls�zArgReplacer.__init__cCsBzt|�jWSty t|d�r|j}|jd|j�YS�w)N�	func_code)rrWrRrVr��co_varnames�co_argcount)r!r�rFrrrr�ts
�zArgReplacer._getargnamesrWrd�defaultcCs0|jdurt|�|jkr||jS|�|j|�S)z�Returns the old value of the named argument without replacing it.

        Returns ``default`` if the argument is not present.
        N)r��lenrr)r!rWrdr�rrr�
get_old_value�s
zArgReplacer.get_old_value�	new_valuecCsV|jdurt|�|jkr||j}t|�}|||j<n|�|j�}|||j<|||fS)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``.
        N)r�r��listrr)r!r�rWrd�	old_valuerrr�replace�s


zArgReplacer.replacer)r%r&r'r(r
r)r0rr�rrrr�rr�rrrrr�ds.��
��
���
��r�cCs|��S)z@Equivalent to ``td.total_seconds()`` (introduced in Python 2.7).)�
total_seconds)�tdrrr�timedelta_to_seconds�r4r��mask�datacCsJt�d|�}t�d|�}tt|��D]}||||dA||<q|��S)aQWebsocket 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�irrr�_websocket_mask_python�s
	r��TORNADO_NO_EXTENSION�TORNADO_EXTENSION�0)�websocket_mask�1cCsddl}|��S)Nr)�doctest�DocTestSuite)r�rrr�doctests�sr�r)Ar(r��asyncior�inspectr�os�reryr,rrrrrrr	r
rr�
TYPE_CHECKING�datetime�typesr
r�unittestr7�
bytes_typer)�unicode_type�basestring_type�sysrrBrr�TimeoutErrorr�objectr*rErM�type�
BaseException�NoReturnrSr8rX�	frozensetr\r^rL�DOTALLr`rbrcr�r�r��environr�_websocket_mask�tornado.speedupsr�r�rrrr�<module>s~0


�
(��
��
�
�
�C �