�
˺h�G��$�dZddlZddlZddlZddlmZddlmZmZm Z m
Z
mZ ddlZn#e
$rddlZYnwxYwGd�de��ZGd�d e��Zd
�Zd�Zdd�ZGd
�de��ZGd�deje��Zd�Zd�Zd�Zdd�Zd�ZdS)z�
requests.cookies
~~~~~~~~~~~~~~~~
Compatibility code to be able to use `cookielib.CookieJar` with requests.
requests.utils imports from here, so be careful with imports.
�N�)�to_native_string)� cookielib�urlparse�
urlunparse�Morsel�MutableMappingc��eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z d�Z
dd
�Zd�Zd�Z
d
�Zed���Zed���Zed���Zd S)�MockRequesta�Wraps a `requests.Request` to mimic a `urllib2.Request`.
The code in `cookielib.CookieJar` expects this interface in order to correctly
manage cookie policies, i.e., determine whether a cookie can be set, given the
domains of the request and the cookie.
The original request object is read-only. The client is responsible for collecting
the new headers via `get_new_headers()` and interpreting them appropriately. You
probably want `get_cookie_header`, defined below.
c�h�||_i|_t|jj��j|_dS�N)�_r�_new_headersr�url�scheme�type)�self�requests �p/builddir/build/BUILD/imunify360-venv-2.5.2/opt/imunify360/venv/lib/python3.11/site-packages/requests/cookies.py�__init__zMockRequest.__init__%s+���������T�W�[�)�)�0�� � � �c��|jSr
)r�rs r�get_typezMockRequest.get_type*s
���y�rc�>�t|jj��jSr
)rrr�netlocrs r�get_hostzMockRequest.get_host-s������$�$�+�+rc�*�|���Sr
�rrs r�get_origin_req_hostzMockRequest.get_origin_req_host0s���}�}���rc�(�|jj�d��s|jjSt |jjdd���}t|jj��}t
|j||j|j |j
|jg��S)N�Hostzutf-8)�encoding)r�headers�getrrrrr�path�params�query�fragment)r�host�parseds r�get_full_urlzMockRequest.get_full_url3s����w��"�"�6�*�*� ��7�;������� 7�'�J�J�J���$�'�+�&�&����M�4���f�m�V�\��O�
��� rc��dS�NT�rs r�is_unverifiablezMockRequest.is_unverifiableAs���trc�0�||jjvp||jvSr
)rr$r�r�names r�
has_headerzMockRequest.has_headerDs���t�w��&�C�$�$�2C�*C�CrNc�t�|jj�||j�||����Sr
)rr$r%r)rr3�defaults r�
get_headerzMockRequest.get_headerGs/���w��"�"�4��):�)>�)>�t�W�)M�)M�N�N�Nrc� �td���)zMcookielib has no legitimate use for this method; add it back if you find one.z=Cookie headers should be added with add_unredirected_header())�NotImplementedError)r�key�vals r�
add_headerzMockRequest.add_headerJs��!�"a�b�b�brc��||j|<dSr
�r�rr3�values r�add_unredirected_headerz#MockRequest.add_unredirected_headerNs��"'���$���rc��|jSr
r>rs r�get_new_headerszMockRequest.get_new_headersQs��� � rc�*�|���Sr
)r0rs r�unverifiablezMockRequest.unverifiableTs���#�#�%�%�%rc�*�|���Sr
)r rs r�origin_req_hostzMockRequest.origin_req_hostXs���'�'�)�)�)rc�*�|���Sr
rrs rr*zMockRequest.host\s���}�}���rr
)�__name__�
__module__�__qualname__�__doc__rrrr r,r0r4r7r<rArC�propertyrErGr*r/rrrrs#������ � �1�1�1�
���,�,�,����������D�D�D�O�O�O�O�c�c�c�(�(�(�!�!�!��&�&��X�&��*�*��X�*�����X���rrc�$�eZdZdZd�Zd�Zd�ZdS)�MockResponsez�Wraps a `httplib.HTTPMessage` to mimic a `urllib.addinfourl`.
...what? Basically, expose the parsed HTTP headers from the server response
the way `cookielib` expects to see them.
c��||_dS)z�Make a MockResponse for `cookielib` to read.
:param headers: a httplib.HTTPMessage or analogous carrying the headers
N��_headers)rr$s rrzMockResponse.__init__hs��
��
�
�
rc��|jSr
rQrs r�infozMockResponse.infoos
���}�rc�:�|j�|��dSr
)rR�
getheadersr2s rrVzMockResponse.getheadersrs���
� � ��&�&�&�&�&rN)rIrJrKrLrrTrVr/rrrOrOasK�������� � � ����'�'�'�'�'rrOc��t|d��r|jsdSt|��}t|jj��}|�||��dS)z�Extract the cookies from the response into a CookieJar.
:param jar: cookielib.CookieJar (not necessarily a RequestsCookieJar)
:param request: our own requests.Request object
:param response: urllib3.HTTPResponse object
�_original_responseN)�hasattrrXrrO�msg�extract_cookies)�jarr�response�req�ress r�extract_cookies_to_jarr`vsc��
�H�2�3�3���'����
�g�
�
�C�
�x�2�6�
7�
7�C�����S�!�!�!�!�!rc��t|��}|�|��|����d��S)zj
Produce an appropriate Cookie header string to be sent with `request`, or None.
:rtype: str
�Cookie)r�add_cookie_headerrCr%)r\r�rs r�get_cookie_headerre�sE�� �G���A����!���������"�"�8�,�,�,rc���g}|D]Q}|j|kr�|�||jkr�|�||jkr�*|�|j|j|jf���R|D]\}}}|�|||���dS)zkUnsets a cookie by name, by default over all domains and paths.
Wraps CookieJar.clear(), is O(n).
N)r3�domainr&�append�clear)� cookiejarr3rgr&�
clearables�cookies r�remove_cookie_by_namerm�s���
�J��E�E���;�$������&�F�M�"9�"9������� 3� 3�����6�=�&�+�v�{�C�D�D�D�D�(�,�,����d������d�+�+�+�+�,�,rc��eZdZdZdS)�CookieConflictErrorz�There are two cookies that meet the criteria specified in the cookie jar.
Use .get and .set and include domain and path args in order to be more specific.
N)rIrJrKrLr/rrroro�s���������rroc���eZdZdZdd�Zd�Zd�Zd�Zd�Zd�Z d �Z
d
�Zd�Zd�Z
d
�Zdd�Z�fd�Zd�Zd�Zd�Z�fd�Z�fd�Zdd�Zdd�Zd�Zd�Zd�Zd�Z�xZS)�RequestsCookieJara�Compatibility class; is a cookielib.CookieJar, but exposes a dict
interface.
This is the CookieJar we create by default for requests and sessions that
don't specify one, since some clients may expect response.cookies and
session.cookies to support dict operations.
Requests does not use the dict interface internally; it's just for
compatibility with external client code. All requests code should work
out of the box with externally provided instances of ``CookieJar``, e.g.
``LWPCookieJar`` and ``FileCookieJar``.
Unlike a regular CookieJar, this class is pickleable.
.. warning:: dictionary operations that are normally O(1) may be O(n).
Nc�V� |�|||��S#t$r|cYSwxYw)z�Dict-like get() that also supports optional domain and path args in
order to resolve naming collisions from using one cookie jar over
multiple domains.
.. warning:: operation is O(n), not O(1).
)�_find_no_duplicates�KeyError)rr3r6rgr&s rr%zRequestsCookieJar.get�sC�� ��+�+�D�&�$�?�?�?��� � � ��N�N�N� ���s��(�(c��|�;t|||�d��|�d�����dSt|t��rt |��}nt||fi|��}|�|��|S)z�Dict-like set() that also supports optional domain and path args in
order to resolve naming collisions from using one cookie jar over
multiple domains.
Nrgr&)rgr&)rmr%�
isinstancer�morsel_to_cookie�
create_cookie�
set_cookie)rr3r@�kwargs�cs r�setzRequestsCookieJar.set�s����=�!�$��V�Z�Z��5I�5I�PV�PZ�PZ�[a�Pb�Pb�c�c�c�c��F��e�V�$�$� 5� ��'�'�A�A��d�E�4�4�V�4�4�A���������rc#�@K�t|��D]}|jV��dS)z�Dict-like iterkeys() that returns an iterator of names of cookies
from the jar.
.. seealso:: itervalues() and iteritems().
N)�iterr3�rrls r�iterkeyszRequestsCookieJar.iterkeys�s8�����4�j�j� � �F��+����� � rc�D�t|�����S)z�Dict-like keys() that returns a list of names of cookies from the
jar.
.. seealso:: values() and items().
)�listr�rs r�keyszRequestsCookieJar.keys�s���D�M�M�O�O�$�$�$rc#�@K�t|��D]}|jV��dS)z�Dict-like itervalues() that returns an iterator of values of cookies
from the jar.
.. seealso:: iterkeys() and iteritems().
N)r~r@rs r�
itervalueszRequestsCookieJar.itervalues�s8�����4�j�j� � �F��,����� � rc�D�t|�����S)z�Dict-like values() that returns a list of values of cookies from the
jar.
.. seealso:: keys() and items().
)r�r�rs r�valueszRequestsCookieJar.values�s���D�O�O�%�%�&�&�&rc#�NK�t|��D]}|j|jfV��dS)z�Dict-like iteritems() that returns an iterator of name-value tuples
from the jar.
.. seealso:: iterkeys() and itervalues().
N)r~r3r@rs r� iteritemszRequestsCookieJar.iteritems�s?�����4�j�j� ,� ,�F��+�v�|�+�+�+�+�+� ,� ,rc�D�t|�����S)z�Dict-like items() that returns a list of name-value tuples from the
jar. Allows client-code to call ``dict(RequestsCookieJar)`` and get a
vanilla python dict of key value pairs.
.. seealso:: keys() and values().
)r�r�rs r�itemszRequestsCookieJar.itemss���D�N�N�$�$�%�%�%rc�t�g}t|��D]%}|j|vr|�|j���&|S)z2Utility method to list all the domains in the jar.�r~rgrh�r�domainsrls r�list_domainszRequestsCookieJar.list_domainssC�����4�j�j� .� .�F��}�G�+�+����v�}�-�-�-���rc�t�g}t|��D]%}|j|vr|�|j���&|S)z0Utility method to list all the paths in the jar.)r~r&rh)r�pathsrls r�
list_pathszRequestsCookieJar.list_pathssC�����4�j�j� *� *�F��{�%�'�'����V�[�)�)�)���rc��g}t|��D]/}|j�|j|vrdS|�|j���0dS)zvReturns True if there are multiple domains in the jar.
Returns False otherwise.
:rtype: bool
NTFr�r�s r�multiple_domainsz"RequestsCookieJar.multiple_domainssU�����4�j�j� *� *�F��}�(�V�]�g�-E�-E��t�t��N�N�6�=�)�)�)�)��urc��i}t|��D]+}|�|j|kr|�|j|kr|j||j<�,|S)z�Takes as an argument an optional domain and path and returns a plain
old Python dict of name-value pairs of cookies that meet the
requirements.
:rtype: dict
)r~rgr&r@r3)rrgr&�
dictionaryrls r�get_dictzRequestsCookieJar.get_dict+sU���
��4�j�j� 7� 7�F���6�=�F�#:�#:������!4�!4�*0�,�
�6�;�'���rc�x�� tt|���|��S#t$rYdSwxYwr.)�superrq�__contains__ro)rr3� __class__s �rr�zRequestsCookieJar.__contains__;sI��� ��*�D�1�1�>�>�t�D�D�D��"� � � ��4�4� ���s�'+�
9�9c�,�|�|��S)z�Dict-like __getitem__() for compatibility with client code. Throws
exception if there are more than one cookie with name. In that case,
use the more explicit get() method instead.
.. warning:: operation is O(n), not O(1).
)rsr2s r�__getitem__zRequestsCookieJar.__getitem__As���'�'��-�-�-rc�2�|�||��dS)z�Dict-like __setitem__ for compatibility with client code. Throws
exception if there is already a cookie of that name in the jar. In that
case, use the more explicit set() method instead.
N)r|r?s r�__setitem__zRequestsCookieJar.__setitem__Js��
����u�����rc�&�t||��dS)zlDeletes a cookie given a name. Wraps ``cookielib.CookieJar``'s
``remove_cookie_by_name()``.
N)rmr2s r�__delitem__zRequestsCookieJar.__delitem__Qs�� �d�D�)�)�)�)�)rc���t|jd��rT|j�d��r:|j�d��r |j�dd��|_tt|��j|g|�Ri|��S)N�
startswith�"z\"�)rYr@r��endswith�replacer�rqry)rrl�argsrzr�s �rryzRequestsCookieJar.set_cookieWs�����6�<��.�.� ;�6�<�3J�3J�3�3O�3O� ;�TZ�T`�Ti�Ti�jm�Tn�Tn� ;�!�<�/�/��r�:�:�F�L�8�u�&��-�-�8��Q�$�Q�Q�Q�&�Q�Q�Qrc����t|tj��r.|D])}|�t j|�����*dStt|���|��dS)zAUpdates this jar with cookies from another CookieJar or dict-likeN)rvr� CookieJarry�copyr�rq�update)r�otherrlr�s �rr�zRequestsCookieJar.update\sw����e�Y�0�1�1� 9��
3�
3������ �&� 1� 1�2�2�2�2�
3�
3�
�#�T�*�*�1�1�%�8�8�8�8�8rc��t|��D]0}|j|kr#|�|j|kr|�|j|kr |jcS�1td|�d|�d|�����)a�Requests uses this method internally to get cookie values.
If there are conflicting cookies, _find arbitrarily chooses one.
See _find_no_duplicates if you want an exception thrown if there are
conflicting cookies.
:param name: a string containing name of cookie
:param domain: (optional) string containing domain of cookie
:param path: (optional) string containing path of cookie
:return: cookie.value
N�name=� , domain=�, path=)r~r3rgr&r@rt)rr3rgr&rls r�_findzRequestsCookieJar._finddsx���4�j�j� ,� ,�F��{�d�"�"��>�V�]�f�%<�%<��|�v�{�d�':�':�%�|�+�+�+���h����f�f�f�d�d�K�L�L�Lrc���d}t|��D]B}|j|kr5|�|j|kr(|�|j|kr|�t d|z���|j}�C|r|St
d|�d|�d|�����)a�Both ``__get_item__`` and ``get`` call this function: it's never
used elsewhere in Requests.
:param name: a string containing name of cookie
:param domain: (optional) string containing domain of cookie
:param path: (optional) string containing path of cookie
:raises KeyError: if cookie is not found
:raises CookieConflictError: if there are multiple cookies
that match name and optionally domain and path
:return: cookie.value
Nz(There are multiple cookies with name, %rr�r�r�)r~r3rgr&ror@rt)rr3rgr&�toReturnrls rrsz%RequestsCookieJar._find_no_duplicatesxs������4�j�j� 0� 0�F��{�d�"�"��>�V�]�f�%<�%<��|�v�{�d�':�':�#�/�"5�6`�dh�6i�"j�"j�j�#)�<���� ��O��h����f�f�f�d�d�K�L�L�Lrc�b�|j���}|�d��|S)�4Unlike a normal CookieJar, this class is pickleable.�
_cookies_lock)�__dict__r��pop�r�states r�__getstate__zRequestsCookieJar.__getstate__�s,���
�"�"�$�$��
� � �/�"�"�"��rc��|j�|��d|jvrtj��|_dSdS)r�r�N)r�r�� threading�RLockr�r�s r�__setstate__zRequestsCookieJar.__setstate__�sC���
���U�#�#�#��$�-�/�/�!*��!2�!2�D����0�/rc��t��}|�|�����|�|��|S)z(Return a copy of this RequestsCookieJar.)rq�
set_policy�
get_policyr�)r�new_cjs rr�zRequestsCookieJar.copy�sB��"�$�$�����$�/�/�+�+�,�,�,��
�
�d�����
rc��|jS)z&Return the CookiePolicy instance used.)�_policyrs rr�zRequestsCookieJar.get_policy�s
���|�r)NNN�NN)rIrJrKrLr%r|r�r�r�r�r�r�r�r�r�r�r�r�r�r�ryr�r�rsr�r�r�r��
__classcell__)r�s@rrqrq�s����������"
�
�
�
����"���%�%�%����'�'�'�,�,�,�&�&�&�������������� �����.�.�.����*�*�*�R�R�R�R�R�
9�9�9�9�9�M�M�M�M�(M�M�M�M�2���3�3�3����������rrqc��|�dSt|d��r|���Stj|��}|���|D])}|�tj|�����*|S)Nr�)rYr�riry)r\�new_jarrls r�_copy_cookie_jarr��s{��
�{��t��s�F�����x�x�z�z���i��n�n�G��M�M�O�O�O��.�.�����4�9�V�,�,�-�-�-�-��Nrc���d||ddddddddddidd�
}t|��t|��z
}|r!d }t|t|��z���|�|��t |d
��|d<t |d��|d
<|d�d��|d<t |d��|d<t
jdi|��S)z�Make a cookie from underspecified parameters.
By default, the pair of `name` and `value` will be set for the domain ''
and sent on every request (this is sometimes called a "supercookie").
rNr��/FT�HttpOnly)
�versionr3r@�portrgr&�secure�expires�discard�comment�comment_url�rest�rfc2109z4create_cookie() got unexpected keyword arguments: %sr��port_specifiedrg�domain_specified�.�domain_initial_dotr&�path_specifiedr/)r|� TypeErrorr�r��boolr�rrb)r3r@rz�result�badargs�errs rrxrx�s��������������T�"����F� �&�k�k�C��K�K�'�G��-�D����d�7�m�m�+�,�,�,�
�M�M�&����#�F�6�N�3�3�F���!%�f�X�&6�!7�!7�F���#)�(�#3�#>�#>�s�#C�#C�F�� �#�F�6�N�3�3�F�����%�%�f�%�%�%rc��d}|dr^ ttj��t|d��z��}n]#t$rtd|dz���wxYw|dr/d}t jtj|d|����}t|dt|d��d|d||j |d dd
|didt|d��|j
|d
pd��
�
S)zBConvert a Morsel object into a Cookie containing the one k/v pair.Nzmax-agezmax-age: %s must be integerr�z%a, %d-%b-%Y %H:%M:%S GMTr�Frgr&r��httponlyr�r�r)
r�r�r�rgr�r3r&r�r�r�r�r@r�)�int�time�
ValueErrorr��calendar�timegm�strptimerxr�r:r@)�morselr��
time_templates rrwrw�s2���G�
�i��
� O��$�)�+�+��F�9�,=�(>�(>�>�?�?�G�G��� O� O� O��9�F�9�<M�M�N�N�N� O���� � � �
�3�
��/��M�&��+�]�;�;�
�
����y�!��� �*�+�+���h���
�Z�
�F�^�
��&��,�
-���F�8�$�%�%��l��y�!�&�Q����s�6A�#A&Tc��|�t��}|�@d�|D��}|D]1}|s||vr)|�t|||�����2|S)aCReturns a CookieJar from a key/value dictionary.
:param cookie_dict: Dict of key/values to insert into CookieJar.
:param cookiejar: (optional) A cookiejar to add the cookies to.
:param overwrite: (optional) If False, will not replace cookies
already in the jar with new ones.
:rtype: CookieJar
Nc��g|] }|j��
Sr/)r3)�.0rls r�
<listcomp>z'cookiejar_from_dict.<locals>.<listcomp> s��>�>�>�&�&�+�>�>�>r)rqryrx)�cookie_dictrj� overwrite�names_from_jarr3s r�cookiejar_from_dictr��s|����%�'�'� ���>�>�I�>�>�>��� M� M�D��
M�T��7�7��$�$�]�4��T�9J�%K�%K�L�L�L���rc�^�t|tj��std���t|t��rt||d���}n[t|tj��rA |�|��n*#t$r|D]}|�|���YnwxYw|S)z�Add cookies to cookiejar and returns a merged CookieJar.
:param cookiejar: CookieJar object to add the cookies to.
:param cookies: Dictionary or CookieJar object to be added.
:rtype: CookieJar
z!You can only merge into CookieJarF)rjr�) rvrr�r��dictr�r��AttributeErrorry)rj�cookies�
cookie_in_jars r�
merge_cookiesr�s����i��!4�5�5�>��<�=�=�=��'�4� � �4�'��y�E�;�;�;� � � �G�Y�0� 1� 1�4� 4����W�%�%�%�%��� 4� 4� 4�!(�
4�
4�
��$�$�]�3�3�3�3�
4�
4� 4�����s�-B�$B*�)B*r�r.)rLr�r�r��_internal_utilsr�compatrrrrr r��ImportError�dummy_threading�objectrrOr`rerm�RuntimeErrorror�rqr�rxrwr�r�r/rr�<module>rs�����������������-�-�-�-�-�-�K�K�K�K�K�K�K�K�K�K�K�K�K�K�(��������(�(�(�'�'�'�'�'�'�(����E�E�E�E�E�&�E�E�E�P'�'�'�'�'�6�'�'�'�*"�"�"�"-�-�-�,�,�,�,�&�����,����|�|�|�|�|� �+�^�|�|�|�~���!&�!&�!&�H���>����*����s�)� 5�5 |