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/lib64/python3.10/site-packages/tornado/__pycache__/escape.cpython-310.pyc
o

we�7�
@s�dZddlZddlZddlZddlZddlmZddlZddlm	Z	m
Z
mZmZm
Z
mZde	eefdefdd�Zde	eefdefd	d
�Zde
defdd�Zde	eefde
fd
d�Zdedefdd�Zd9de	eefdedefdd�Zejd9de	eefdddedefdd��Zej	d:de	eefdededefdd��Z	d:de	eefdeedede	eeffdd�Z	d;de	eefdededeee
effdd �Zeed�fZejdedefd!d"��Zejdedefd#d"��Zejd<d$d"��Zde	deefdeefd%d"�Zeed�fZejdedefd&d'��Zejdedefd(d'��Zejd<d)d'��Zde	deefdeefd*d'�ZeZ eZ!eZ"d+e
de
fd,d-�Z#e�$ed.��Z%dd/dd0d1gfd2e	eefd3ed4e	eeegeffd5ed6e
edefd7d8�Z&dS)=a�Escaping/unescaping methods for HTML, JSON, URLs, and others.

Also includes a few other miscellaneous string manipulation functions that
have crept in over time.

Many functions in this module have near-equivalents in the standard library
(the differences mainly relate to handling of bytes and unicode strings,
and were more relevant in Python 2). In new code, the standard library
functions are encouraged instead of this module where applicable. See the
docstrings on each function for details.
�N)�unicode_type)�Union�Any�Optional�Dict�List�Callable�value�returncC�t�t|��S)a�Escapes a string so it is valid within HTML or XML.

    Escapes the characters ``<``, ``>``, ``"``, ``'``, and ``&``.
    When used in attribute values the escaped strings must be enclosed
    in quotes.

    Equivalent to `html.escape` except that this function always returns
    type `str` while `html.escape` returns `bytes` if its input is `bytes`.

    .. versionchanged:: 3.2

       Added the single quote to the list of escaped characters.

    .. versionchanged:: 6.4

       Now simply wraps `html.escape`. This is equivalent to the old behavior
       except that single quotes are now escaped as ``&#x27;`` instead of
       ``&#39;`` and performance may be different.
    )�html�escape�
to_unicode�r	�r�G/home/arjun/projects/env/lib/python3.10/site-packages/tornado/escape.py�xhtml_escape'srcCr)aZUn-escapes an XML-escaped string.

    Equivalent to `html.unescape` except that this function always returns
    type `str` while `html.unescape` returns `bytes` if its input is `bytes`.

    .. versionchanged:: 6.4

       Now simply wraps `html.unescape`. This changes behavior for some inputs
       as required by the HTML 5 specification
       https://html.spec.whatwg.org/multipage/parsing.html#numeric-character-reference-end-state

       Some invalid inputs such as surrogates now raise an error, and numeric
       references to certain ISO-8859-1 characters are now handled correctly.
    )r�unescaperrrrr�xhtml_unescape>srcCst�|��dd�S)z�JSON-encodes the given Python object.

    Equivalent to `json.dumps` with the additional guarantee that the output
    will never contain the character sequence ``</`` which can be problematic
    when JSON is embedded in an HTML ``<script>`` tag.
    z</z<\/)�json�dumps�replacerrrr�json_encodeSs
rcCs
t�|�S)z~Returns Python objects for the given JSON string.

    Supports both `str` and `bytes` inputs. Equvalent to `json.loads`.
    )r�loadsrrrr�json_decodecs
rcCst�dd|���S)z>Replace all sequences of whitespace chars with a single space.z[\x00-\x20]+� )�re�sub�striprrrr�squeezeksrT�pluscCs|rtjjntjj}||�S)a}Returns a URL-encoded version of the given value.

    Equivalent to either `urllib.parse.quote_plus` or `urllib.parse.quote` depending on the ``plus``
    argument.

    If ``plus`` is true (the default), spaces will be represented as ``+`` and slashes will be
    represented as ``%2F``.  This is appropriate for query strings. If ``plus`` is false, spaces
    will be represented as ``%20`` and slashes are left as-is. This is appropriate for the path
    component of a URL. Note that the default of ``plus=True`` is effectively the
    reverse of Python's urllib module.

    .. versionadded:: 3.1
        The ``plus`` argument
    )�urllib�parse�
quote_plus�quote)r	r r$rrr�
url_escapepsr%�encodingcC�dS�Nr�r	r&r rrr�url_unescape��r*�utf-8cCr'r(rr)rrrr*�scCsL|dur|rt|��dd�}tj�|�S|rtjjntjj}|t|�|d�S)aODecodes the given value from a URL.

    The argument may be either a byte or unicode string.

    If encoding is None, the result will be a byte string and this function is equivalent to
    `urllib.parse.unquote_to_bytes` if ``plus=False``.  Otherwise, the result is a unicode string in
    the specified encoding and this function is equivalent to either `urllib.parse.unquote_plus` or
    `urllib.parse.unquote` except that this function also accepts `bytes` as input.

    If ``plus`` is true (the default), plus signs will be interpreted as spaces (literal plus signs
    must be represented as "%2B").  This is appropriate for query strings and form-encoded values
    but not for the path component of a URL.  Note that this default is the reverse of Python's
    urllib module.

    .. versionadded:: 3.1
       The ``plus`` argument
    N�+r)r&)�
to_basestringrr!r"�unquote_to_bytes�unquote_plus�unquote)r	r&r r1rrrr*�sF�qs�keep_blank_values�strict_parsingcCsVt|t�r
|�d�}tjj|||ddd�}i}|��D]
\}}dd�|D�||<q|S)a/Parses a query string like urlparse.parse_qs,
    but takes bytes and returns the values as byte strings.

    Keys still become type str (interpreted as latin1 in python3!)
    because it's too painful to keep them as byte strings in
    python3 and in practice they're nearly always ascii anyway.
    �latin1�strict)r&�errorscSsg|]}|�d��qS)r5)�encode��.0�irrr�
<listcomp>�sz"parse_qs_bytes.<locals>.<listcomp>)�
isinstance�bytes�decoder!r"�parse_qs�items)r2r3r4�result�encoded�k�vrrr�parse_qs_bytes�s


�rFcCr'r(rrrrr�utf8�r+rGcCr'r(rrrrrrG�r+cCr'r(rrrrrrG�r+cC�2t|t�r|St|t�stdt|���|�d�S)z�Converts a string argument to a byte string.

    If the argument is already a byte string or None, it is returned unchanged.
    Otherwise it must be a unicode string and is encoded as utf8.
    �(Expected bytes, unicode, or None; got %rr,)r=�_UTF8_TYPESr�	TypeError�typer8rrrrrG��



cCr'r(rrrrrr�r+rcCr'r(rrrrrr�r+cCr'r(rrrrrr�r+cCrH)z�Converts a string argument to a unicode string.

    If the argument is already a unicode string or None, it is returned
    unchanged.  Otherwise it must be a byte string and is decoded as utf8.
    rIr,)r=�_TO_UNICODE_TYPESr>rKrLr?rrrrr�rM�objcCsnt|t�rtdd�|��D��St|t�rtdd�|D��St|t�r,tdd�|D��St|t�r5t|�S|S)zvWalks a simple data structure, converting byte strings to unicode.

    Supports lists, tuples, and dictionaries.
    css$�|]
\}}t|�t|�fVqdSr(��recursive_unicode)r:rDrErrr�	<genexpr>s�
�z$recursive_unicode.<locals>.<genexpr>cs��|]}t|�VqdSr(rPr9rrrrR��csrSr(rPr9rrrrRrT)r=�dictrA�list�tupler>r)rOrrrrQs
�


rQz�\b((?:([\w-]+):(/{1,3})|www[.])(?:(?:(?:[^\s&()]|&amp;|&quot;)*(?:[^!"#$%&'()*+,.:;<=>?@\[\]^`{|}~\s]))|(?:\((?:[^\s&()]|&amp;|&quot;)*\)))+)��http�https�text�shorten�extra_params�require_protocol�permitted_protocolscsN�rt��sd����dtjdtf����fdd�}tt|��}t�||�S)a�Converts plain text into HTML with links.

    For example: ``linkify("Hello http://tornadoweb.org!")`` would return
    ``Hello <a href="http://tornadoweb.org">http://tornadoweb.org</a>!``

    Parameters:

    * ``shorten``: Long urls will be shortened for display.

    * ``extra_params``: Extra text to include in the link tag, or a callable
      taking the link as an argument and returning the extra text
      e.g. ``linkify(text, extra_params='rel="nofollow" class="external"')``,
      or::

          def extra_params_cb(url):
              if url.startswith("http://example.com"):
                  return 'class="internal"'
              else:
                  return 'class="external" rel="nofollow"'
          linkify(text, extra_params=extra_params_cb)

    * ``require_protocol``: Only linkify urls which include a protocol. If
      this is False, urls such as www.facebook.com will also be linkified.

    * ``permitted_protocols``: List (or set) of protocols which should be
      linkified, e.g. ``linkify(text, permitted_protocols=["http", "ftp",
      "mailto"])``. It is very unsafe to include protocols such as
      ``javascript``.
    r�mr
c
s||�d�}|�d�}�r|s|S|r|�vr|S|�d�}|s#d|}t��r0d�|���}n�}d}�r�t|�|kr�|}|rPt|�dt|�d�pLd�}nd}||d��d	�}t|�dkr|d|�|dd	|ddd
��d�d�d�d}t|�|d
kr�|d|�}||kr�|�d�}	|	|dkr�|d|	�}|d7}t|�t|�kr�|}n|d|7}d|||fS)N��zhttp://r��rXr�/��?�.g�?�&�z...z title="%s"z<a href="%s"%s>%s</a>)�group�callabler�len�split�rfind)
r`�url�proto�href�params�max_len�before_clip�	proto_len�parts�amp�r]r_r^r\rr�	make_linkTsN


 
��"��
zlinkify.<locals>.make_link)	rlr�typing�Match�str�_unicoder�_URL_REr)r[r\r]r^r_rzrryr�linkify-s
$>r�)T)r,T)FF)r	Nr
N)'�__doc__rrr�urllib.parser!�tornado.utilrr{rrrrrrr}r>rrrrr�boolr%�overloadr*rFrLrJrGrNrr~�
native_strr.rQ�compilerr�rrrr�<module>s�  &�
�����
���

��
���
� 
 ��	�
������