AlkantarClanX12

Your IP : 18.219.207.11


Current Path : /opt/alt/python311/lib64/python3.11/http/__pycache__/
Upload File :
Current File : //opt/alt/python311/lib64/python3.11/http/__pycache__/cookiejar.cpython-311.pyc

�

c��f�.����dZgd�ZddlZddlZddlZddlZddlZddlZddl	Zddl
ZddlZ
ddlmZdZdad�ZdZdZee
jj��Zejd	��Zd
ZdZd�Zd
Zd�Zgd�Z gd�Z!d�e!D��Z"dLd�Z#dLd�Z$ddddd�Z%ejdej&��Z'd�Z(d�Z)ejdej&��Z*ejdej+ej&z��Z,ejdej-ej&z��Z.d�Z/ejdej-ej&z��Z0d�Z1d�Z2ejd��Z3ejd ��Z4ejd!��Z5ejd"��Z6d#�Z7ejd$��Z8d%�Z9d&�Z:d'�Z;ejd(ej&��Z<d)�Z=d*�Z>d+�Z?d,�Z@ejd-ej&��ZAd.�ZBd/�ZCd0�ZDd1�ZEd2ZFejd3��ZGd4�ZHd5�ZId6�ZJd7�ZKGd8�d9��ZLGd:�d;��ZMGd<�d=eM��ZNd>�ZOGd?�d@��ZPGdA�dB��ZQGdC�dDeR��ZSGdE�dFeQ��ZTdG�ZUGdH�dIeT��ZVGdJ�dKeT��ZWdS)Ma�HTTP cookie handling for web clients.

This module has (now fairly distant) origins in Gisle Aas' Perl module
HTTP::Cookies, from the libwww-perl library.

Docstrings, comments and debug strings in this code refer to the
attributes of the HTTP cookie system as cookie-attributes, to distinguish
them clearly from Python attributes.

Class diagram (note that BSDDBCookieJar and the MSIE* classes are not
distributed with the Python standard library, but are available from
http://wwwsearch.sf.net/):

                        CookieJar____
                        /     \      \
            FileCookieJar      \      \
             /    |   \         \      \
 MozillaCookieJar | LWPCookieJar \      \
                  |               |      \
                  |   ---MSIEBase |       \
                  |  /      |     |        \
                  | /   MSIEDBCookieJar BSDDBCookieJar
                  |/
               MSIECookieJar

)�Cookie�	CookieJar�CookiePolicy�DefaultCookiePolicy�
FileCookieJar�LWPCookieJar�	LoadError�MozillaCookieJar�N)�timegmFc�p�tsdStsddl}|�d��atj|�S)Nr
zhttp.cookiejar)�debug�logger�logging�	getLogger)�argsrs  �5/opt/alt/python311/lib64/python3.11/http/cookiejar.py�_debugr,sA�������5������"�"�#3�4�4���<�����HTTPOnlyz
#HttpOnly_z#( Netscape)? HTTP Cookie FilezQa filename was not supplied (nor was the CookieJar instance initialised with one)zr# Netscape HTTP Cookie File
# http://curl.haxx.se/rfc/cookie_spec.html
# This is a generated file!  Do not edit.

c���ddl}ddl}ddl}|���}|�d|��|���}|�d|zd���dS)Nr
zhttp.cookiejar bug!
%s�)�
stacklevel)�io�warnings�	traceback�StringIO�	print_exc�getvalue�warn)rrr�f�msgs     r�_warn_unhandled_exceptionr"Bsz��#�"�"�"�"�"�"�"�"�"�"�"�
���
�
�A�
����a� � � �
�*�*�,�,�C��M�M�+�c�1�a�M�@�@�@�@�@ri�c��|dd�\}}}}}}|tkr_d|cxkrdkrRnnOd|cxkrdkrBnn?d|cxkrdkr2nn/d|cxkrdkr"nnd|cxkrdkrnnt|��SdS)	N����r
��;�=)�
EPOCH_YEARr)�tt�year�month�mday�hour�min�secs       r�_timegmr3Qs���(*�2�A�2��%�D�%��t�S�#�	
��	�	�!�u�"2�"2�"2�"2��"2�"2�"2�"2�"2��d�����b������	
�d�����b������q�C�~�~�~�~�2�~�~�~�~�~�A��N�N�N�N��N�N�N�N�N��b�z�z���tr)�Mon�Tue�Wed�Thu�Fri�Sat�Sun)�Jan�Feb�Mar�Apr�May�Jun�Jul�Aug�Sep�Oct�Nov�Decc�6�g|]}|�����S�)�lower)�.0r.s  r�
<listcomp>rK\s ��2�2�2�%����
�
�2�2�2rc���|�tj���}ntj�|��}d|j|j|j|j|j|jfzS)aHReturn a string representing time in seconds since epoch, t.

    If the function is called without an argument, it will use the current
    time.

    The format of the returned string is like "YYYY-MM-DD hh:mm:ssZ",
    representing Universal Time (UTC, aka GMT).  An example of this format is:

    1994-11-24 08:49:37Z

    Nz%04d-%02d-%02d %02d:%02d:%02dZ)	�datetime�utcnow�utcfromtimestampr-r.�dayr0�minute�second��t�dts  r�	time2isozrV^sc��	�y�
�
�
%�
%�
'�
'���
�
�
/�
/��
2�
2��+�
����2�6�2�7�B�I�r�y�/B�B�Brc�,�|�tj���}ntj�|��}dt|���|jt|jdz
|j|j	|j
|jfzS)z�Return a string representing time in seconds since epoch, t.

    If the function is called without an argument, it will use the current
    time.

    The format of the returned string is like this:

    Wed, DD-Mon-YYYY HH:MM:SS GMT

    Nz#%s, %02d-%s-%04d %02d:%02d:%02d GMTr%)rMrNrO�DAYS�weekdayrP�MONTHSr.r-r0rQrRrSs  r�
time2netscaper[qsy��	�y�
�
�
%�
%�
'�
'���
�
�
/�
/��
2�
2��0��R�Z�Z�\�\��B�F�F�2�8�A�:�$6�
����"�)�R�Y�40�0�0r)�GMT�UTC�UT�Zz^([-+])?(\d\d?):?(\d\d)?$c�V�d}|tvrd}n�t�|��}|r~dt|�d����z}|�d��r(|dt|�d����zz}|�d��dkr|}|S)Nr
ir��<r%�-)�	UTC_ZONES�TIMEZONE_RE�search�int�group)�tz�offset�ms   r�offset_from_tz_stringrl�s���
�F�	�Y���������r�"�"���	!��C�����
�
�O�O�+�F��w�w�q�z�z�
7��"�s�1�7�7�1�:�:���"6�6���w�w�q�z�z�S� � � ����Mrc	�.�t|��}|tjkrdS	t�|�����dz}nI#t$r<	t|��}n#t$rYYdSwxYwd|cxkrdkrnn|}nYdSYnwxYw|�d}|�d}|�d}t|��}t|��}t|��}t|��}|dkrctjtj����d}|dz}	|}
||z|	z
}|	|
z
}	t|	��dkr|	dkr|dz}n|dz
}t|||||||f��}|�0|�d}|���}t|��}|�dS||z
}|S)Nr%r&r
i��d�2r])
rgrM�MAXYEAR�MONTHS_LOWER�indexrI�
ValueError�time�	localtime�absr3�upperrl)
rP�mon�yr�hrr1r2ri�imon�cur_yrrk�tmprTrjs
             r�	_str2timer~�s���	�R���B�	�H�����t��� � ������-�-�a�/�����	�	�	�	��s�8�8�D�D���	�	�	��4�4�4�	������?�?�?�?��?�?�?�?�?��C�C��4�4�
�C�	����
�z��2�
�{�!�C�
�{�!�C�

�c�(�(�C�	�R���B�

�c�(�(�C�

�c�(�(�C�	�D�y�y����	���,�,�Q�/���S�L����
�&�[�1�_��
��G���q�6�6�B�;�;��1�u�u�2��8�b�b��C�x�"�	��S�#�r�3��R�0�1�1�A��}�
�:��B�
�X�X�Z�Z��&�r�*�*���>��4�
��J���Hs5�/A�
B�A.�-B�.
A=�8B�<A=�=B�BzV^[SMTWF][a-z][a-z], (\d\d) ([JFMASOND][a-z][a-z]) (\d\d\d\d) (\d\d):(\d\d):(\d\d) GMT$z+^(?:Sun|Mon|Tue|Wed|Thu|Fri|Sat)[a-z]*,?\s*a�^
    (\d\d?)            # day
       (?:\s+|[-\/])
    (\w+)              # month
        (?:\s+|[-\/])
    (\d+)              # year
    (?:
          (?:\s+|:)    # separator before clock
       (\d\d?):(\d\d)  # hour:min
       (?::(\d\d))?    # optional seconds
    )?                 # optional clock
       \s*
    (?:
       ([-+]?\d{2,4}|(?![APap][Mm]\b)[A-Za-z]+) # timezone
       \s*
    )?
    (?:
       \(\w+\)         # ASCII representation of timezone in parens.
       \s*
    )?$c	���t�|��}|r�|���}t�|d�����dz}t
|d��|t
|d��t
|d��t
|d��t|d��f}t|��S|�	��}t�d|d��}dgd	z\}}}}}}	}
t�|��}|�|���\}}}}}}	}
ndSt||||||	|
��S)
a�Returns time in seconds since epoch of time represented by a string.

    Return value is an integer.

    None is returned if the format of str is unrecognized, the time is outside
    the representable range, or the timezone string is not recognized.  If the
    string contains no timezone, UTC is assumed.

    The timezone in the string may be numerical (like "-0800" or "+0100") or a
    string timezone (like "UTC", "GMT", "BST" or "EST").  Currently, only the
    timezone strings equivalent to UTC (zero offset) are known to the function.

    The function loosely parses the following formats:

    Wed, 09 Feb 1994 22:23:32 GMT       -- HTTP format
    Tuesday, 08-Feb-94 14:15:29 GMT     -- old rfc850 HTTP format
    Tuesday, 08-Feb-1994 14:15:29 GMT   -- broken rfc850 HTTP format
    09 Feb 1994 22:23:32 GMT            -- HTTP format (no weekday)
    08-Feb-94 14:15:29 GMT              -- rfc850 format (no weekday)
    08-Feb-1994 14:15:29 GMT            -- broken rfc850 format (no weekday)

    The parser ignores leading and trailing whitespace.  The time may be
    absent.

    If the year is given with only 2 digits, the function will select the
    century that makes the year closest to the current date.

    r%rr
ra���N�)�STRICT_DATE_RErf�groupsrqrrrIrg�floatr3�lstrip�
WEEKDAY_RE�sub�LOOSE_HTTP_DATE_REr~)�textrk�grxr,rPryrzr1r2ris           r�	http2timer��s:��<	���d�#�#�A���
�H�H�J�J��� � ��1������.�.��2���!�A�$�i�i��c�!�A�$�i�i��!�A�$�i�i��Q�q�T���E�!�A�$�K�K�1���r�{�{��
�;�;�=�=�D��>�>�"�d�A�&�&�D�'+�V�A�X�"�C��b�"�c�3��	�!�!�$�'�'�A��}�)*�����&��S�"�b�#�s�B�B��t��S�#�r�2�s�C��4�4�4ra�^
    (\d{4})              # year
       [-\/]?
    (\d\d?)              # numerical month
       [-\/]?
    (\d\d?)              # day
   (?:
         (?:\s+|[-:Tt])  # separator before clock
      (\d\d?):?(\d\d)    # hour:min
      (?::?(\d\d(?:\.\d*)?))?  # optional seconds (and fractional)
   )?                    # optional clock
      \s*
   (?:
      ([-+]?\d\d?:?(:?\d\d)?
       |Z|z)             # timezone  (Z is "zero meridian", i.e. GMT)
      \s*
   )?$c	���|���}dgdz\}}}}}}}t�|��}|�|���\}}}}}}}}	ndSt	|||||||��S)av
    As for http2time, but parses the ISO 8601 formats:

    1994-02-03 14:15:29 -0100    -- ISO 8601 format
    1994-02-03 14:15:29          -- zone is optional
    1994-02-03                   -- only date
    1994-02-03T14:15:29          -- Use T as separator
    19940203T141529Z             -- ISO 8601 compact format
    19940203                     -- only date

    Nr�)r��ISO_DATE_RErfr�r~)
r�rPrxryrzr1r2rirk�_s
          r�iso2timer�2s����;�;�=�=�D�'+�V�A�X�"�C��b�"�c�3��	���4� � �A��}�-.�H�H�J�J�)��C��b�#�s�B����t��S�#�r�2�s�C��4�4�4rc�p�|�d��\}}|jd|�|j|d�zS)z)Return unmatched part of re.Match object.r
N)�span�string)�match�start�ends   r�	unmatchedr�Ss6�����A���J�E�3��<�������S�T�T� 2�2�2rz^\s*([^=\s;,]+)z&^\s*=\s*\"([^\"\\]*(?:\\.[^\"\\]*)*)\"z^\s*=\s*([^\s;,]*)z\\(.)c��t|t��rJ�g}|D�]�}|}g}|�r�t�|��}|r�t	|��}|�d��}t�|��}|r@t	|��}|�d��}t�d|��}nWt�|��}|r9t	|��}|�d��}|�
��}nd}|�||f��n�|����
d��r6|���dd�}|r|�|��g}n4tjdd|��\}}	|	dksJd|�d	|�d
|�����|}|���|r|�|�����|S)amParse header values into a list of lists containing key,value pairs.

    The function knows how to deal with ",", ";" and "=" as well as quoted
    values after "=".  A list of space separated tokens are parsed as if they
    were separated by ";".

    If the header_values passed as argument contains multiple values, then they
    are treated as if they were a single value separated by comma ",".

    This means that this function is useful for parsing header fields that
    follow this syntax (BNF as from the HTTP/1.1 specification, but we relax
    the requirement for tokens).

      headers           = #header
      header            = (token | parameter) *( [";"] (token | parameter))

      token             = 1*<any CHAR except CTLs or separators>
      separators        = "(" | ")" | "<" | ">" | "@"
                        | "," | ";" | ":" | "\" | <">
                        | "/" | "[" | "]" | "?" | "="
                        | "{" | "}" | SP | HT

      quoted-string     = ( <"> *(qdtext | quoted-pair ) <"> )
      qdtext            = <any TEXT except <">>
      quoted-pair       = "\" CHAR

      parameter         = attribute "=" value
      attribute         = token
      value             = token | quoted-string

    Each header is represented by a list of key/value pairs.  The value for a
    simple token (not part of a parameter) is None.  Syntactically incorrect
    headers will not necessarily be parsed as you would want.

    This is easier to describe with some examples:

    >>> split_header_words(['foo="bar"; port="80,81"; discard, bar=baz'])
    [[('foo', 'bar'), ('port', '80,81'), ('discard', None)], [('bar', 'baz')]]
    >>> split_header_words(['text/html; charset="iso-8859-1"'])
    [[('text/html', None), ('charset', 'iso-8859-1')]]
    >>> split_header_words([r'Basic realm="\"foo\bar\""'])
    [[('Basic', None), ('realm', '"foobar"')]]

    r%z\1N�,z^[=\s;]*r�r
zsplit_header_words bug: 'z', 'z', )�
isinstance�str�HEADER_TOKEN_RErfr�rh�HEADER_QUOTED_VALUE_RE�HEADER_ESCAPE_REr��HEADER_VALUE_RE�rstrip�appendr��
startswith�re�subn)
�
header_values�resultr��	orig_text�pairsrk�name�value�non_junk�
nr_junk_charss
          r�split_header_wordsr�\s���Z�-��-�-�-�-�-�
�F��#'�#'���	����	 ��&�&�t�,�,�A��
 � ��|�|���w�w�q�z�z��*�1�1�$�7�7���%�$�Q�<�<�D��G�G�A�J�J�E�,�0�0���>�>�E�E�'�.�.�t�4�4�A��%�(��|�|�� !����
�
�� %�������!%�����d�E�]�+�+�+�+������)�)�#�.�.�
 ��{�{�}�}�Q�R�R�(���.�&�-�-��.�.�.����+-�'�+�r�4�*H�*H�'��-�$�q�(�(�(�(��Y�Y����e�e�-�)�(�(� ��?�	 �@�&�&�-�-��&�&�&���Mr�([\"\\])c�H�g}|D]�}g}|D]X\}}|�<tjd|��s t�d|��}d|z}|�d|��}|�|���Y|r(|�d�|������d�|��S)a�Do the inverse (almost) of the conversion done by split_header_words.

    Takes a list of lists of (key, value) pairs and produces a single header
    value.  Attribute values are quoted if needed.

    >>> join_header_words([[("text/plain", None), ("charset", "iso-8859-1")]])
    'text/plain; charset="iso-8859-1"'
    >>> join_header_words([[("text/plain", None)], [("charset", "iso-8859-1")]])
    'text/plain, charset="iso-8859-1"'

    Nz^\w+$�\\\1z"%s"�=�; �, )r�rf�HEADER_JOIN_ESCAPE_REr�r��join)�lists�headersr��attr�k�vs      r�join_header_wordsr��s����G��	1�	1�����	�	�D�A�q��}��y��1�-�-�#�-�1�1�'�1�=�=�A���
�A� �q�q�!�!�$���K�K��N�N�N�N��0�����	�	�$���0�0�0���9�9�W���rc��|�d��r
|dd�}|�d��r
|dd�}|S)N�"r%���)r��endswith�r�s r�strip_quotesr��sI�����s�����A�B�B�x���}�}�S�����C�R�C�y���Krc��d}g}|D�]6}g}d}t|�d����D]�\}}|���}|�d��\}}	}
|���}|s	|dkrn��Q|	r|
���nd}
|dkrX|���}||vr|}|dkr|
�t|
��}
d}n$|d	kr|
�t
t|
����}
|�||
f����|r,|s|�d
��|�|����8|S)a5Ad-hoc parser for Netscape protocol cookie-attributes.

    The old Netscape cookie format for Set-Cookie can for instance contain
    an unquoted "," in the expires field, so we have to use this ad-hoc
    parser instead of split_header_words.

    XXX This may not make the best possible effort to parse all the crap
    that Netscape Cookie headers contain.  Ronald Tschalar's HTTPClient
    parser is probably better, so could do worse than following that if
    this ever gives any trouble.

    Currently, this is also used for parsing RFC 2109 cookies.

    )�expires�domain�path�secure�version�port�max-ageF�;r�r
Nr�Tr�)r��0)�	enumerate�split�strip�	partitionrIr�r�r�)�
ns_headers�known_attrsr��	ns_headerr��version_set�ii�param�key�sep�val�lcs            r�parse_ns_headersr��sw��1�K��F��+!�+!�	�����#�9�?�?�3�#7�#7�8�8�	%�	%�I�B���K�K�M�M�E�!�O�O�C�0�0�M�C��c��)�)�+�+�C��
���7�7��E��"%�.�#�)�)�+�+�+�$�C��Q�w�w��Y�Y�[�[����$�$��C��)�#�#���*�3�/�/��"&�K�K��I�%�%���'��S�(9�(9�:�:���L�L�#�s��$�$�$�$��	!��
/����-�.�.�.��M�M�%� � � ���Mrz\.\d+$c��t�|��rdS|dkrdS|ddks|ddkrdSdS)z*Return True if text is a host domain name.Fr�r
�.r�T��IPV4_RErfr�s r�is_HDNr�sN���~�~�d�����u��r�z�z��u��A�w�#�~�~��b��S����u��4rc�.�|���}|���}||krdSt|��sdS|�|��}|dks|dkrdS|�d��sdSt|dd���sdSdS)a�Return True if domain A domain-matches domain B, according to RFC 2965.

    A and B may be host domain names or IP addresses.

    RFC 2965, section 1:

    Host names can be specified either as an IP address or a HDN string.
    Sometimes we compare one host name with another.  (Such comparisons SHALL
    be case-insensitive.)  Host A's name domain-matches host B's if

         *  their host name strings string-compare equal; or

         * A is a HDN string and has the form NB, where N is a non-empty
            name string, B has the form .B', and B' is a HDN string.  (So,
            x.y.com domain-matches .Y.com but not Y.com.)

    Note that domain-match is not a commutative operation: a.b.c.com
    domain-matches .c.com, but not the reverse.

    TFr�r
r�r%N)rIr��rfindr�)�A�B�is   r�domain_matchr�&s���.	
���	�	�A�	���	�	�A��A�v�v��t��!�9�9���u�	����
�
�A��B�w�w�!�q�&�&��u��<�<������u��!�A�B�B�%�=�=���u��4rc�>�t�|��rdSdS)zdReturn True if text is a sort-of-like a host domain name.

    For accepting/blocking domains.

    FTr�r�s r�liberal_is_HDNr�Ms"���~�~�d�����u��4rc��|���}|���}t|��rt|��s
||krdSdS|�d��}|r|�|��rdS|s||krdSdS)z\For blocking/accepting domains.

    A and B may be host domain names or IP addresses.

    TFr�)rIr�r�r�)r�r��initial_dots   r�user_domain_matchr�Ws���	
���	�	�A�	���	�	�A��1����.��"3�"3����6�6��4��u��,�,�s�#�#�K���q�z�z�!�}�}���t���1��6�6��t��5rz:\d+$c��|���}tj�|��d}|dkr|�dd��}t
�d|d��}|���S)z�Return request-host, as defined by RFC 2965.

    Variation from RFC: returned value is lowercased, for convenient
    comparison.

    r%r��Host)�get_full_url�urllib�parse�urlparse�
get_header�cut_port_rer�rI)�request�url�hosts   r�request_hostr�lsr���
�
�
 �
 �C��<� � ��%�%�a�(�D��r�z�z��!�!�&�"�-�-���?�?�2�t�Q�'�'�D��:�:�<�<�rc��t|��x}}|�d��dkrt�|��s|dz}||fS)zzReturn a tuple (request-host, effective request-host name).

    As defined by RFC 2965, except both are lowercased.

    r�r��.local)r��findr�rf)r��erhn�req_hosts   r�eff_request_hostr�|sR��#�7�+�+�+�D�8��}�}�S���R������x�(@�(@���(�"���T�>�rc���|���}tj�|��}t	|j��}|�d��sd|z}|S)z6Path component of request-URI, as defined by RFC 2965.�/)r�r�r��urlsplit�escape_pathr�r�)r�r��partsr�s    r�request_pathr�sY��
�
�
�
 �
 �C��L�!�!�#�&�&�E��u�z�"�"�D��?�?�3�����T�z���Krc���|j}|�d��}|dkr?||dzd�}	t|��n(#t$rt	d|��YdSwxYwt
}|S)N�:r
r%znonnumeric port: '%s')r�r�rgrsr�DEFAULT_HTTP_PORT)r�r�r�r�s    r�request_portr�s����<�D��	�	�#���A��A�v�v��A�a�C�D�D�z��	���I�I�I�I���	�	�	��*�D�1�1�1��4�4�	����!���Ks�A�A�Az%/;:@&=+$,!~*'()z%([0-9a-fA-F][0-9a-fA-F])c�V�d|�d�����zS)Nz%%%sr%)rhrw)r�s r�uppercase_escaped_charr	�s#���E�K�K��N�N�(�(�*�*�*�*rc��tj�|t��}t�t|��}|S)zEEscape any invalid characters in HTTP URL, and uppercase all escapes.)r�r��quote�HTTP_PATH_SAFE�ESCAPED_CHAR_REr�r	)r�s rrr�s6���<���d�N�3�3�D����5�t�<�<�D��Krc��|�d��}|dkrB||dzd�}|�d��}t|��r|dks|dkrd|zS|S)aBReturn reach of host h, as defined by RFC 2965, section 1.

    The reach R of a host name H is defined as follows:

       *  If

          -  H is the host domain name of a host; and,

          -  H has the form A.B; and

          -  A has no embedded (that is, interior) dots; and

          -  B has at least one embedded dot, or B is the string "local".
             then the reach of H is .B.

       *  Otherwise, the reach of H is H.

    >>> reach("www.acme.com")
    '.acme.com'
    >>> reach("acme.com")
    'acme.com'
    >>> reach("acme.local")
    '.local'

    r�r
r%N�local)r�r�)�hr��bs   r�reachr�sh��4	
���s���A��A�v�v�
�a��c�d�d�G��
�F�F�3�K�K���!�9�9�	�!�q�&�&�A��L�L��q�5�L��Hrc�l�t|��}t|t|j����sdSdS)z�

    RFC 2965, section 3.3.6:

        An unverifiable transaction is to a third-party host if its request-
        host U does not domain-match the reach R of the request-host O in the
        origin transaction.

    TF)r�r�r�origin_req_host)r�r�s  r�is_third_partyr�s8���G�$�$�H���%��(?�"@�"@�A�A���t��urc�D�eZdZdZ	dd�Zd�Zdd�Zd�Zdd�Zd	�Z	d
�Z
dS)
ra�HTTP Cookie.

    This class represents both Netscape and RFC 2965 cookies.

    This is deliberately a very simple class.  It just holds attributes.  It's
    possible to construct Cookie instances that don't comply with the cookie
    standards.  CookieJar.make_cookies is the factory function for Cookie
    objects -- it deals with cookie parsing, supplying defaults, and
    normalising to the representation used in this class.  CookiePolicy is
    responsible for checking them to see whether they should be accepted from
    and returned to the server.

    Note that the port may be present in the headers, but unspecified ("Port"
    rather than"Port=80", for example); if this is the case, port is None.

    Fc���|�t|��}|�tt|����}|�|durtd���||_||_||_||_||_|���|_	||_
||_|	|_|
|_
||_||_|
|_||_||_||_t)j|��|_dS)NTz-if port is None, port_specified must be false)rgr�rsr�r�r�r��port_specifiedrIr��domain_specified�domain_initial_dotr��path_specifiedr�r��discard�comment�comment_url�rfc2109�copy�_rest)�selfr�r�r�r�rr�rrr�rr�r�rrr�restrs                  r�__init__zCookie.__init__�s�����#�g�,�,����#�e�G�n�n�*=�*=���<�N�d�2�2��L�M�M�M������	���
���	�,����l�l�n�n��� 0���
#5�����	�,���������������&�������Y�t�_�_��
�
�
rc��||jvS�N�r!)r"r�s  r�has_nonstandard_attrzCookie.has_nonstandard_attr#s���t�z�!�!rNc�8�|j�||��Sr&)r!�get)r"r��defaults   r�get_nonstandard_attrzCookie.get_nonstandard_attr%s���z�~�~�d�G�,�,�,rc��||j|<dSr&r')r"r�r�s   r�set_nonstandard_attrzCookie.set_nonstandard_attr's�� ��
�4���rc�X�|�tj��}|j�
|j|krdSdS�NTF)rtr�)r"�nows  r�
is_expiredzCookie.is_expired*s/���;�d�i�k�k���L�$�4�<�3�+>�+>��4��urc��|j�d}n
d|jz}|j|z|jz}|j�|j�d|j��}n|j}d|�d|�d�S)Nr�rr�z<Cookie z for �>)r�r�r�r�r�)r"�p�limit�	namevalues    r�__str__zCookie.__str__0sf���9��"�a�a��d�i�-�a���a��$�)�+���:�!�#'�9�9�9�d�j�j�9�I�I��	�I��'0�y�y�%�%�%�8�8rc�p�g}dD]9}t||��}|�|�dt|�������:|�dt|j��z��|�dt|j��z��|jj�dd�|���d�S)N)r�r�r�r�rr�rrr�rr�r�rrrr�zrest=%sz
rfc2109=%s�(r��))�getattrr��reprr!r�	__class__�__name__r�)r"rr�r�s    r�__repr__zCookie.__repr__:s������	6�	6�D��4��&�&�D��K�K�4�4�4��d����4�5�5�5�5����I��T�Z� 0� 0�0�1�1�1����L�4���#5�#5�5�6�6�6��>�2�2�2�D�I�I�d�O�O�O�O�D�Dr)Fr&)r?�
__module__�__qualname__�__doc__r$r(r,r.r2r8r@rHrrrr�s���������6�(%�(%�(%�(%�T"�"�"�-�-�-�-�!�!�!�����9�9�9�E�E�E�E�Errc�*�eZdZdZd�Zd�Zd�Zd�ZdS)ra Defines which cookies get accepted from and returned to server.

    May also modify cookies, though this is probably a bad idea.

    The subclass DefaultCookiePolicy defines the standard rules for Netscape
    and RFC 2965 cookies -- override that if you want a customized policy.

    c��t���)z�Return true if (and only if) cookie should be accepted from server.

        Currently, pre-expired cookies never get this far -- the CookieJar
        class deletes such cookies itself.

        ��NotImplementedError�r"�cookier�s   r�set_okzCookiePolicy.set_okRs��"�#�#�#rc��t���)zAReturn true if (and only if) cookie should be returned to server.rFrHs   r�	return_okzCookiePolicy.return_ok[���!�#�#�#rc��dS)zMReturn false if cookies should not be returned, given cookie domain.
        TrH)r"r�r�s   r�domain_return_okzCookiePolicy.domain_return_ok_�	���trc��dS)zKReturn false if cookies should not be returned, given cookie path.
        TrH)r"r�r�s   r�path_return_okzCookiePolicy.path_return_okdrPrN)r?rArBrCrJrLrOrRrHrrrrIsZ��������$�$�$�$�$�$����
����rrc
���eZdZdZdZdZdZdZeezZdddddddddeddd	f
d
�Z	d�Z
d�Zd
�Zd�Z
d�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd �ZdS)!rzBImplements the standard rules for accepting and returning cookies.r%rr�r
NTF)�https�wssc��||_||_||_||_||_||_|	|_|
|_||_||_	|
|_
|�t|��|_nd|_|�t|��}||_
dS)zAConstructor arguments should be passed as keyword arguments only.NrH)�netscape�rfc2965�rfc2109_as_netscape�hide_cookie2�
strict_domain�strict_rfc2965_unverifiable�strict_ns_unverifiable�strict_ns_domain�strict_ns_set_initial_dollar�strict_ns_set_path�secure_protocols�tuple�_blocked_domains�_allowed_domains)r"�blocked_domains�allowed_domainsrWrXrYrZr[r\r]r^r_r`ras              rr$zDefaultCookiePolicy.__init__ts���!��
����#6�� �(���*���+F��(�&<��#� 0���,H��)�"4��� 0����&�$)�/�$:�$:�D�!�!�$&�D�!��&�#�O�4�4�O� /����rc��|jS)z4Return the sequence of blocked domains (as a tuple).)rc�r"s rrez#DefaultCookiePolicy.blocked_domains�����$�$rc�.�t|��|_dS)z$Set the sequence of blocked domains.N)rbrc)r"res  r�set_blocked_domainsz'DefaultCookiePolicy.set_blocked_domains�s�� %�o� 6� 6����rc�@�|jD]}t||��rdS�dSr0)rcr�)r"r��blocked_domains   r�
is_blockedzDefaultCookiePolicy.is_blocked�s7��"�3�	�	�N� ���8�8�
��t�t�
��urc��|jS)z=Return None, or the sequence of allowed domains (as a tuple).)rdrhs rrfz#DefaultCookiePolicy.allowed_domains�rirc�6�|�t|��}||_dS)z-Set the sequence of allowed domains, or None.N)rbrd)r"rfs  r�set_allowed_domainsz'DefaultCookiePolicy.set_allowed_domains�s#���&�#�O�4�4�O� /����rc�R�|j�dS|jD]}t||��rdS�dS)NFT)rdr�)r"r��allowed_domains   r�is_not_allowedz"DefaultCookiePolicy.is_not_allowed�sE��� �(��5�"�3�	�	�N� ���8�8�
��u�u�
��trc��td|j|j��|j�J�dD]&}d|z}t||��}|||��sdS�'dS)z�
        If you override .set_ok(), be sure to call this method.  If it returns
        false, so should your subclass (assuming your subclass wants to be more
        strict about which cookies to accept).

        � - checking cookie %s=%sN)r��
verifiabilityr�r�r�r��set_ok_FT�rr�r�r<�r"rIr��n�fn_name�fns      rrJzDefaultCookiePolicy.set_ok�sw��	�)�6�;���E�E�E��{�&�&�&�M�	�	�A���k�G���w�'�'�B��2�f�g�&�&�
��u�u�
��trc���|j�td|j|j��dS|jdkr|jstd��dS|jdkr|jstd��dSdS)Nz0   Set-Cookie2 without version attribute (%s=%s)Fr
�$   RFC 2965 cookies are switched off�$   Netscape cookies are switched offT)r�rr�r�rXrWrHs   r�set_ok_versionz"DefaultCookiePolicy.set_ok_version�s����>�!�
�E��;���
.�
.�
.��5��>�A���d�l���9�:�:�:��5�
�^�q�
 �
 ���
 ��9�:�:�:��5��trc��|jrUt|��rF|jdkr|jrt	d��dS|jdkr|jrt	d��dSdS�Nr
z>   third-party RFC 2965 cookie during unverifiable transactionFz>   third-party Netscape cookie during unverifiable transactionT��unverifiablerr�r\rr]rHs   r�set_ok_verifiabilityz(DefaultCookiePolicy.set_ok_verifiability�s�����	�N�7�$;�$;�	��~��!�!�d�&F�!��8�9�9�9��u���1�$�$��)D�$��8�9�9�9��u��trc��|jdkr8|jr1|j�d��rt	d|j��dSdS)Nr
�$z'   illegal name (starts with '$'): '%s'FT)r�r_r�r�rrHs   r�set_ok_namezDefaultCookiePolicy.set_ok_name�sN��
�N�a���D�$E���K�"�"�3�'�'�
 ��<�f�k�J�J�J��5��trc���|jr_t|��}|jdks|jdkr:|jr3|�|j|��st
d|j|��dSdS)Nr
z7   path attribute %s is not a prefix of request path %sFT)rrr�r`rRr�r)r"rIr��req_paths    r�set_ok_pathzDefaultCookiePolicy.set_ok_path�s~��� �	�#�G�,�,�H���!�#�#��.�A�%�%�$�*A�%��'�'���W�=�=�&��!�"(�+�x�9�9�9��u��trc�|�|�|j��rtd|j��dS|�|j��rtd|j��dS|j�rQt|��\}}|j}|jr�|�d��dkr�|�d��}|�dd|��}|dkrU||dzd�}||dz|�}	|	�	��dvr%t|��dkrtd	|��dS|�d��r|dd�}
n|}
|
�d��dk}|s'|�
d
��std|��dS|jdkrm|�
|��sX|�
|
�d
���s@|�d��s+d|z�
|��std||��dS|jdks|j|jzr#t#||��std
||��dS|jdks|j|jzr^|dt|���}|�d��dkr-t&�|��std||��dSdS)N�"   domain %s is in user block-listF�&   domain %s is not in user allow-listr�rr
r%)�co�ac�com�edu�org�net�gov�milrg�aero�biz�cat�coop�info�jobs�mobi�museumr��pro�travel�euz&   country-code second level domain %sr�z/   non-local domain %s contains no embedded dotzO   effective request-host %s (even with added initial dot) does not end with %sz5   effective request-host %s does not domain-match %sz.   host prefix %s for domain %s contains a dotT)rnr�rrtrr�r[�countr�rI�lenr�r�r�r�r^�DomainRFC2965Matchr��DomainStrictNoDotsr�rf)
r"rIr�r�r�r�r��j�tld�sld�undotted_domain�
embedded_dots�host_prefixs
             r�
set_ok_domainz!DefaultCookiePolicy.set_ok_domain�s���?�?�6�=�)�)�	��7���G�G�G��5����v�}�-�-�	��;�V�]�K�K�K��5��"�2	!�-�g�6�6�N�H�d��]�F��!�
%�v�|�|�C�'8�'8�A�'=�'=��L�L��%�%���L�L��a��+�+����6�6� ��1����,�C� ��1��Q��-�C��y�y�{�{�''�'�'�,/�s�8�8�q�=�=��G��P�P�P�$�u�� � ��%�%�
)�"(����*���"(��,�1�1�#�6�6�!�;�M� �
����x�)@�)@�
��H������u��~��"�"����v�.�.�!����/�'A�'A�'A�B�B�!�����-�-�!��d�(�,�,�V�4�4�!��?���)�)�)�!�5����"�"��&��)@�@�#�#�D�&�1�1�!�� �!%�v�/�/�/� �5����"�"��&��)@�@�#�&�}��V����}�5���$�$�S�)�)�Q�.�.����x�0�0�/��K�&��0�0�0� �5��trc�:�|jr�t|��}|�d}nt|��}|j�d��D]=}	t|��n"#t$rtd|��YdSwxYw||krn�>td||j��dSdS)N�80r�z   bad port %s (not numeric)Fz$   request port (%s) not found in %sT)rrr�r�r�rgrsr�r"rIr��req_portr5s     r�set_ok_portzDefaultCookiePolicy.set_ok_port3s���� �	�#�G�,�,�H�������x�=�=���[�&�&�s�+�+�
�
��!���F�F�F�F��!�!�!�!��9�1�=�=�=� �5�5�5�!������=�=��E�!��=����.�.�.��u��ts�A�A7�6A7c��td|j|j��dD]&}d|z}t||��}|||��sdS�'dS)z�
        If you override .return_ok(), be sure to call this method.  If it
        returns false, so should your subclass (assuming your subclass wants to
        be more strict about which cookies to return).

        rv)r�rwr�r�r�r��
return_ok_FTryrzs      rrLzDefaultCookiePolicy.return_okHsg��	�)�6�;���E�E�E�R�	�	�A�"�1�n�G���w�'�'�B��2�f�g�&�&�
��u�u�
��trc��|jdkr|jstd��dS|jdkr|jstd��dSdS)Nr
rFr�T)r�rXrrWrHs   r�return_ok_versionz%DefaultCookiePolicy.return_ok_versionZsW���>�A���d�l���9�:�:�:��5�
�^�q�
 �
 ���
 ��9�:�:�:��5��trc��|jrUt|��rF|jdkr|jrt	d��dS|jdkr|jrt	d��dSdSr�r�rHs   r�return_ok_verifiabilityz+DefaultCookiePolicy.return_ok_verifiabilitycs�����	�N�7�$;�$;�	��~��!�!�d�&F�!��%�&�&�&��u���1�$�$��)D�$��%�&�&�&��u��trc�R�|jr|j|jvrtd��dSdS)Nz(   secure cookie with non-secure requestFT)r��typerarrHs   r�return_ok_securez$DefaultCookiePolicy.return_ok_secureos4���=�	�W�\��1F�F�F��=�>�>�>��5��trc�\�|�|j��rtd��dSdS)Nz   cookie expiredFT)r2�_nowrrHs   r�return_ok_expiresz%DefaultCookiePolicy.return_ok_expiresus3�����T�Y�'�'�	��&�'�'�'��5��trc��|jrPt|��}|�d}|j�d��D]
}||krn�td||j��dSdS)Nr�r�z0   request port %s does not match cookie port %sFT)r�rr�rr�s     r�return_ok_portz"DefaultCookiePolicy.return_ok_port{s~���;�
	�#�G�,�,�H������[�&�&�s�+�+�
�
����=�=��E�!��I����.�.�.��u��trc��t|��\}}|j}|r|�d��sd|z}n|}|jdkr-|j|jzr|js||krtd��dS|jdkr#t||��std||��dS|jdkr+d|z�	|��std||��dSdS)Nr�r
zQ   cookie with unspecified domain does not string-compare equal to request domainFzQ   effective request-host name %s does not domain-match RFC 2965 cookie domain %sz;   request-host %s does not match Netscape cookie domain %sT)
r�r�r�r�r^�DomainStrictNonDomainrrr�r�)r"rIr�r�r�r��	dotdomains       r�return_ok_domainz$DefaultCookiePolicy.return_ok_domain�s ��)�'�2�2���$�����	�&�+�+�C�0�0�	��f��I�I��I�
�N�a���
�
"�T�%?�
?�
 ��'�
 �,2�d�N�N��-�
.�
.�
.��5��>�A���l�4��&@�&@���/�04�f�
>�
>�
>��5��>�Q����D��':�':�9�'E�'E����!�6�
+�
+�
+��5��trc���t|��\}}|�d��sd|z}|�d��sd|z}|r|�d��sd|z}n|}|�|��s|�|��sdS|�|��rt	d|��dS|�|��rt	d|��dSdS)Nr�Fr�r�T)r�r�r�rnrrt)r"r�r�r�r�r�s      rrOz$DefaultCookiePolicy.domain_return_ok�s	��*�'�2�2���$��"�"�3�'�'�	$��8�|�H����s�#�#�	��t�8�D��	�&�+�+�C�0�0�	��f��I�I��I��!�!�)�,�,�	��
�
�i�0H�0H�	��5��?�?�6�"�"�	��7��@�@�@��5����v�&�&�	��;�V�D�D�D��5��trc��td|��t|��}t|��}||krdS|�|��r(|�d��s|||dz�dkrdStd||��dS)Nz- checking cookie path=%sTr�r%z  %s does not path-match %sF)rrr�r�r�)r"r�r�r��pathlens     rrRz"DefaultCookiePolicy.path_return_ok�s����*�D�1�1�1���(�(���d�)�)���t����4��!�!�$�'�'�	��}�}�S�!�!�	�%-�g�g�a�i�.?�%@�C�%G�%G��4��,�h��=�=�=��ur) r?rArBrCr�r�r��
DomainLiberal�DomainStrictr$rerkrnrfrqrtrJr�r�r�r�r�r�rLr�r�r�r�r�r�rOrRrHrrrrjs�������L�L��������M�%�&;�;�L�"&�t���%)�#�$�-1�(-�"/�.3�$)�"2�!0�!0�!0�!0�F%�%�%�7�7�7����%�%�%�0�0�0�������&
�
�
�
�
�
����	�	�	�:�:�:�x���*���$���
�
�
�������������6���4����rrc#��K�t|�����D]:}d}	|jd}t|��Ed{V��n#t$rYnwxYw|s|V��;dS)z)Iterates over nested mapping, depth-firstFTN)�list�values�items�
deepvalues�AttributeError)�mapping�objs  rr�r��s������G�N�N�$�$�%�%�
�
����	'��I�I��G�!�#���&�&�&�&�&�&�&�&��	�	�	�	��D�	����
�	��I�I�I��
�
s�A�
A�Ac��eZdZdS)�AbsentN�r?rArBrHrrr�r����������rr�c�`�eZdZdZejd��Zejd��Zejd��Zejd��Z	ejd��Z
ejdej��Zdd	�Z
d
�Zd�Zd�Zd
�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zdd�Zd�Zd�Zd�Zd�Zd�Z d�Z!dS) rz�Collection of HTTP cookies.

    You may not need to know about this class: try
    urllib.request.build_opener(HTTPCookieProcessor).open(url).
    z\Wr�z\.?[^.]*z[^.]*z^\.+z^\#LWP-Cookies-(\d+\.\d+)Nc�r�|�t��}||_tj��|_i|_dSr&)r�_policy�
_threading�RLock�
_cookies_lock�_cookies�r"�policys  rr$zCookieJar.__init__�s5���>�(�*�*�F����'�-�/�/�����
�
�
rc��||_dSr&)r�r�s  r�
set_policyzCookieJar.set_policy�s
������rc��g}|j�||��sgStd|��|j|}|���D]�}|j�||��s�||}|���D]Q}|j�||��std���-td��|�|���R��|S)Nz!Checking %s for cookies to returnz   not returning cookiez   it's a match)	r�rOrr��keysrRr�rLr�)r"r�r��cookies�cookies_by_pathr��cookies_by_namerIs        r�_cookies_for_domainzCookieJar._cookies_for_domain�s������|�,�,�V�W�=�=�	��I��2�F�;�;�;��-��/��#�(�(�*�*�		'�		'�D��<�.�.�t�W�=�=�
��-�d�3�O�)�0�0�2�2�
'�
'���|�-�-�f�g�>�>���4�5�5�5���(�)�)�)����v�&�&�&�&�
'��rc��g}|j���D]+}|�|�||�����,|S)z2Return a list of cookies to be returned to server.)r�r��extendr�)r"r�r�r�s    r�_cookies_for_requestzCookieJar._cookies_for_request
sP�����m�(�(�*�*�	F�	F�F��N�N�4�3�3�F�G�D�D�E�E�E�E��rc�>�|�d�d���d}g}|D�]|}|j}|s d}|dkr|�d|z��|j�F|j�|j��r'|dkr!|j�d|j��}n|j}|j�|�|j��n|�|j�d	|����|dkr�|j	r|�d
|j
z��|j�d��rE|j}|j
s|�d��r
|dd�}|�d
|z��|j�+d}|jr
|d|jzz}|�|����~|S)z�Return a list of cookie-attributes to be returned to server.

        like ['foo="bar"; $Path="/"', ...]

        The $Version attribute is also added when appropriate (currently only
        once per request).

        c�*�t|j��Sr&)r�r�)�as r�<lambda>z)CookieJar._cookie_attrs.<locals>.<lambda>s��3�q�v�;�;�rT)r��reverseFr
z$Version=%sNr�r�z
$Path="%s"r�r%z$Domain="%s"z$Portz="%s")�sortr�r�r��non_word_rerf�quote_rer�r�rr�r�r�rr�r)	r"r�r��attrsrIr�r�r�r5s	         r�
_cookie_attrszCookieJar._cookie_attrss���	���.�.���=�=�=������(	$�(	$�F��n�G��
:�"���Q�;�;��L�L���!8�9�9�9�
��)�� �'�'���5�5�*�:A�A�+�+��
�)�)�'�6�<�@�@�������|�#����V�[�)�)�)�)��������U�U�;�<�<�<���{�{��(�=��L�L����!;�<�<�<��=�+�+�C�0�0�:�#�]�F�"�5�,��)�)�#�.�.�,�!'�������L�L��&�!8�9�9�9��;�*��A��,�8���6�;�!6�7���L�L��O�O�O���rc���td��|j���	tt	j����x|j_|_|�|��}|�|��}|r>|�	d��s)|�
dd�|����|jjrI|jj
s=|�	d��s(|D]%}|jdkr|�
dd��n�&|j���n#|j���wxYw|���dS)z�Add correct Cookie: header to request (urllib.request.Request object).

        The Cookie2 header is also added unless policy.hide_cookie2 is true.

        �add_cookie_headerrr��Cookie2r%z$Version="1"N)rr��acquirergrtr�r�r�r��
has_header�add_unredirected_headerr�rXrZr��release�clear_expired_cookies)r"r�r�r�rIs     rr�zCookieJar.add_cookie_headerLss��	�"�#�#�#���"�"�$�$�$�	)�,/��	���,<�,<�<�D�L���	��/�/��8�8�G��&�&�w�/�/�E��
4��)�)�(�3�3�4��3�3� �$�)�)�E�"2�"2�4�4�4���$�
�T�\�-F�
��&�&�y�1�1�
�%���F��~��*�*��7�7�	�>�R�R�R���+�

��&�&�(�(�(�(��D��&�&�(�(�(�(�����"�"�$�$�$�$�$s�C0D4�4Ec�v�g}d}d}|D�].}|d\}}d}d}	i}
i}|dd�D]�\}}
|���}||vs||vr|}||vr|
�d}
||
vr�0|dkr)|
�td	��d}	n�|
���}
|d
kr|r�h|
�td���z|dkrAd}	t|
��}
n"#t$rtd
��d}	Yn@wxYwd
}|j|
z}
||vs||vr"|
�|dvrtd|z��d}	n|
|
|<��|
||<��|	r��|�|||
|f����0|S)aReturn list of tuples containing normalised cookie information.

        attrs_set is the list of lists of key,value pairs extracted from
        the Set-Cookie or Set-Cookie2 headers.

        Tuples are name, value, standard, rest, where name and value are the
        cookie name and value, standard is a dictionary containing the standard
        cookie-attributes (discard, secure, version, expires or max-age,
        domain, path and port) and rest is a dictionary containing the rest of
        the cookie-attributes.

        )rr�)r�r�r�r�r�r�r�
commenturlr
Fr%NTr�z%   missing value for domain attributer�zM   missing or invalid value for expires attribute: treating as session cookier�z?   missing or invalid (non-numeric) value for max-age attribute)r�rr�z!   missing value for %s attribute)rIrrgrsr�r�)r"�	attrs_set�
cookie_tuples�
boolean_attrs�value_attrs�cookie_attrsr�r��max_age_set�
bad_cookie�standardr#r�r�r�s               r�_normalized_cookie_tuplesz#CookieJar._normalized_cookie_tuplesms���
�+�
�0��
&�H	@�H	@�L�&�q�/�K�D�%� �K��J��H��D�$�Q�R�R�(�2
 �2
 ���1��W�W�Y�Y����$�$��m�(;�(;��A��
�%�%�!�)��A���=�=����=�=��y��F�G�G�G�%)�
������	�	�A��	�>�>�"�!� ��y�� F�G�G�G� ��	�>�>�"&�K����F�F����%����� 2�3�3�3�%)�
����	����"�A��	�A�
�A���$�$�!�}�*<�*<��	��!B�B�B��B�Q�F�G�G�G�%)�
���"#�H�Q�K�K��D��G�G��
��� � �$��x��!>�?�?�?�?��s�,B<�<C�Cc�2�|\}}}}|�dt��}|�dt��}|�dt��}	|�dt��}
|�dd��}|�"	t|��}n#t$rYdSwxYw|�dd��}|�dd��}
|�d	d��}|�d
d��}|tur|dkrd}t	|��}n_d}t|��}|�d
��}|dkr|dkr|d|�}n
|d|dz�}t|��dkrd
}|tu}d}|r"t|�	d����}|turt|��\}}|}n|�	d��sd|z}d}|	tur+|	�t|��}	nd}tj
dd|	��}	nd}	|
turd}
d}
nH|
|jkr=	|�|||��n#t $rYnwxYwt#d|||��dSt%||||	||||||||
|
|||��S)Nr�r�r�r�r�r�Frrr�r�Tr�r�r
r%r�z\s+z2Expiring cookie, domain='%s', path='%s', name='%s')r*r�rgrsrrr�r��boolr�r�rr�r�r��clear�KeyErrorrr)r"�tupr�r�r�rr#r�r�r�r�r�r�rrrrr�rrr�r�rs                       r�_cookie_from_cookie_tuplez#CookieJar._cookie_from_cookie_tuple�s
��'*�#��e�X�t����h��/�/���|�|�F�F�+�+���|�|�F�F�+�+���,�,�y�&�1�1���,�,�y�$�/�/����
��g�,�,�����
�
�
��t�t�
�������h��.�.���,�,�y�%�0�0���,�,�y�$�/�/���l�l�<��6�6���v���$�"�*�*�!�N��t�$�$�D�D�"�N���(�(�D��
�
�3���A��B�w�w��a�<�<�����8�D�D����1���:�D��4�y�y�A�~�~�c�t�"��/��"���	>�!%�f�&7�&7��&<�&<�!=�!=���V���-�g�6�6�N�H�d��F�F��"�"�3�'�'�	 ���Z�F����v����|�$�G�,�,���!%���v�f�b�$�/�/����D��f����G��G�G�
��	�
!�
!�
��
�
�6�4��.�.�.�.���
�
�
���
�����G��4��
'�
'�
'��4��g��E��N��.�0B��N�����!��
�
�
	s$�
B�
B+�*B+�?I�
I$�#I$c��|�|��}g}|D]/}|�||��}|r|�|���0|Sr&)rrr�)r"r�r�r�r�rrIs       r�_cookies_from_attrs_setz!CookieJar._cookies_from_attrs_set*s[���6�6�y�A�A�
��� �	.�	.�C��3�3�C��A�A�F��-�w�~�~�f�-�-�-���rc��t|jdd��}|�
|jj}|D]}|jdkrd|_|rd|_�dS)NrYr%Tr
)r<r�rXr�r)r"r��
rfc2109_as_nsrIs    r�_process_rfc2109_cookiesz"CookieJar._process_rfc2109_cookies3sh�����.C�T�J�J�
�� � $�� 4�4�M��	'�	'�F��~��"�"�!%��� �'�&'�F�N��
	'�	'rc��|���}|�dg��}|�dg��}ttj����x|j_|_|jj}|jj}|s|r|s|r|s|r|s|sgS	|�t|��|��}n #t$rt��g}YnwxYw|r�|r�	|�t|��|��}	n #t$rt��g}	YnwxYw|�
|	��|r3i}
|D]}d|
|j|j|jf<�|
fd�}t#||	��}	|	r|�|	��|S)zAReturn sequence of Cookie objects extracted from response object.zSet-Cookie2z
Set-CookieNc�2�|j|j|jf}||vSr&)r�r�r�)�	ns_cookie�lookupr�s   r�no_matching_rfc2965z3CookieJar.make_cookies.<locals>.no_matching_rfc2965ls ��#�*�I�N�I�N�J�C��f�,�,r)r��get_allrgrtr�r�rXrWrr��	Exceptionr"r�rr�r�r��filterr�)
r"�responser�r��rfc2965_hdrs�ns_hdrsrXrWr��
ns_cookiesrrIrs
             r�make_cookieszCookieJar.make_cookies?s���-�-�/�/�����}�b�9�9���/�/�,��3�3��(+�D�I�K�K�(8�(8�8����D�I��,�&���<�(���	�g�	��	�!(�	��	�&.�	��	�#*�	��I�	��2�2�"�<�0�0�'�;�;�G�G���	�	�	�%�'�'�'��G�G�G�	�����	+�x�	+�
 �!�9�9�$�W�-�-�w�8�8�
�
���
 �
 �
 �)�+�+�+��
�
�
�
 ����
�)�)�*�5�5�5��
E���%�M�M�F�HL�F�F�M�6�;���D�E�E�:@�-�-�-�-�$�$7��D�D�
��
+����z�*�*�*��s$�#C�C�C�&#D
�
D'�&D'c�j�|j���	ttj����x|j_|_|j�||��r|�|��|j���dS#|j���wxYw)z-Set a cookie if policy says it's OK to do so.N)	r�r�rgrtr�r�rJ�
set_cookier�rHs   r�set_cookie_if_okzCookieJar.set_cookie_if_okvs�����"�"�$�$�$�	)�,/��	���,<�,<�<�D�L���	��|�"�"�6�7�3�3�
(�����'�'�'�
��&�&�(�(�(�(�(��D��&�&�(�(�(�(���s�A!B�B2c�J�|j}|j���	|j|vr
i||j<||j}|j|vr
i||j<||j}|||j<|j���dS#|j���wxYw)z?Set a cookie, without checking whether or not it should be set.N)r�r�r�r�r�r�r�)r"rI�c�c2�c3s     rr zCookieJar.set_cookie�s����M����"�"�$�$�$�	)��}�A�%�%�"�q���'7��6�=�!�B��{�"�$�$��b���o��F�K��B�$�B�v�{�O���&�&�(�(�(�(�(��D��&�&�(�(�(�(���s�A
B�B"c��td|�����|j���	|�||��D]B}|j�||��r%td|��|�|���C	|j���dS#|j���wxYw)zAExtract cookies from response, where allowable given the request.zextract_cookies: %sz setting cookie: %sN)	rr�r�r�rr�rJr r�)r"rr�rIs    r�extract_cookieszCookieJar.extract_cookies�s����$�h�m�m�o�o�6�6�6���"�"�$�$�$�	)��+�+�H�g�>�>�
,�
,���<�&�&�v�w�7�7�,��0�&�9�9�9��O�O�F�+�+�+��
,�

��&�&�(�(�(�(�(��D��&�&�(�(�(�(���s�AB2�2C
c���|�)|�|�td���|j|||=dS|�!|�td���|j||=dS|�
|j|=dSi|_dS)a�Clear some cookies.

        Invoking this method without arguments will clear all cookies.  If
        given a single argument, only cookies belonging to that domain will be
        removed.  If given two arguments, cookies belonging to the specified
        path within that domain are removed.  If given three arguments, then
        the cookie with the specified name, path and domain is removed.

        Raises KeyError if no matching cookie exists.

        Nz8domain and path must be given to remove a cookie by namez.domain must be given to remove cookies by path)rsr�)r"r�r�r�s    rr	zCookieJar.clear�s�������D�L� �N�P�P�P��
�f�%�d�+�D�1�1�1�
�
��~� �D�F�F�F��
�f�%�d�+�+�+�
�
��
�f�%�%�%��D�M�M�Mrc��|j���	|D]/}|jr&|�|j|j|j���0	|j���dS#|j���wxYw)z�Discard all session cookies.

        Note that the .save() method won't save session cookies anyway, unless
        you ask otherwise by passing a true ignore_discard argument.

        N)r�r�rr	r�r�r�r�)r"rIs  r�clear_session_cookieszCookieJar.clear_session_cookies�s���	
��"�"�$�$�$�	)��
H�
H���>�H��J�J�v�}�f�k�6�;�G�G�G��
H�
��&�&�(�(�(�(�(��D��&�&�(�(�(�(���s�2A)�)Bc�P�|j���	tj��}|D]=}|�|��r&|�|j|j|j���>	|j���dS#|j���wxYw)a�Discard all expired cookies.

        You probably don't need to call this method: expired cookies are never
        sent back to the server (provided you're using DefaultCookiePolicy),
        this method is called by CookieJar itself every so often, and the
        .save() method won't save expired cookies anyway (unless you ask
        otherwise by passing a true ignore_expires argument).

        N)	r�r�rtr2r	r�r�r�r�)r"r1rIs   rr�zCookieJar.clear_expired_cookies�s���	
��"�"�$�$�$�	)��)�+�+�C��
H�
H���$�$�S�)�)�H��J�J�v�}�f�k�6�;�G�G�G��
H�
��&�&�(�(�(�(�(��D��&�&�(�(�(�(���s�AB
�
B%c�*�t|j��Sr&)r�r�rhs r�__iter__zCookieJar.__iter__�s���$�-�(�(�(rc��d}|D]}|dz}�|S)z#Return number of contained cookies.r
r%rH)r"r�rIs   r�__len__zCookieJar.__len__�s!��
���%�%�F��A��A�A��rc��g}|D]$}|�t|�����%d|jj�dd�|���d�S�N�<�[r�z]>)r�r=r>r?r��r"�rrIs   rr@zCookieJar.__repr__�sS�����2�2�F�A�H�H�T�&�\�\�2�2�2�2�2�!�^�4�4�4�d�i�i��l�l�l�l�C�Crc��g}|D]$}|�t|�����%d|jj�dd�|���d�Sr1)r�r�r>r?r�r4s   rr8zCookieJar.__str__�sS�����1�1�F�A�H�H�S��[�[�1�1�1�1�1�!�^�4�4�4�d�i�i��l�l�l�l�C�Crr&)NNN)"r?rArBrCr��compiler�r��strict_domain_re�	domain_re�dots_re�ASCII�magic_rer$r�r�r�r�r�rrrrrr!r r'r	r*r�r-r/r@r8rHrrrr�s����������"�*�U�#�#�K��r�z�+�&�&�H�!�r�z�+�.�.����
�8�$�$�I��b�j��!�!�G��r�z�6���A�A�H�����������$���9�9�9�v%�%�%�B_�_�_�BZ�Z�Z�x���
'�
'�
'�5�5�5�n)�)�)�)�)�)�
)�
)�
)�����6
)�
)�
)�)�)�)�&)�)�)����D�D�D�
D�D�D�D�Drrc��eZdZdS)rNr�rHrrrr�r�rrc�6�eZdZdZdd�Zd	d�Zd	d�Z		d	d�ZdS)
rz6CookieJar that can be loaded from and saved to a file.NFc��t�||��|�tj|��}||_t|��|_dS)z}
        Cookies are NOT loaded from the named file until either the .load() or
        .revert() method is called.

        N)rr$�os�fspath�filenamer�	delayload)r"rBrCr�s    rr$zFileCookieJar.__init__�sG��	���4��(�(�(����y��*�*�H� ��
��i������rc��t���)zSave cookies to a file.rF)r"rB�ignore_discard�ignore_expiress    r�savezFileCookieJar.save�rMrc���|�#|j�|j}ntt���t|��5}|�||||��ddd��dS#1swxYwYdS)zLoad cookies from a file.N)rBrs�MISSING_FILENAME_TEXT�open�_really_load�r"rBrErFr s     r�loadzFileCookieJar.loads������}�(�T�]�(�(�"�#8�9�9�9�
�(�^�^�	K�q����a��>�>�J�J�J�	K�	K�	K�	K�	K�	K�	K�	K�	K�	K�	K�	K����	K�	K�	K�	K�	K�	Ks�A�A�"Ac��|�#|j�|j}ntt���|j���	tj|j��}i|_	|�|||��n#t$r	||_�wxYw	|j�
��dS#|j�
��wxYw)z�Clear all cookies and reload cookies from a saved file.

        Raises LoadError (or OSError) if reversion is not successful; the
        object's state will not be altered if this happens.

        N)rBrsrIr�r�r �deepcopyr�rM�OSErrorr�)r"rBrErF�	old_states     r�revertzFileCookieJar.reverts������}�(�T�]�(�(�"�#8�9�9�9���"�"�$�$�$�	)��
�d�m�4�4�I��D�M�
��	�	�(�N�N�C�C�C�C���
�
�
� )��
��
����D�
��&�&�(�(�(�(�(��D��&�&�(�(�(�(���s$� B+�!A9�8B+�9B�B+�+C)NFN�NFF)r?rArBrCr$rGrMrRrHrrrr�sv������@�@�
)�
)�
)�
)�$�$�$�$�K�K�K�K�#�49�)�)�)�)�)�)rrc���|j|jfd|jfd|jfg}|j�|�d|jf��|jr|�d��|jr|�d��|jr|�d��|j	r|�d��|j
r6|�d	tt|j
����f��|j
r|�d
��|jr|�d|jf��|jr|�d|jf��t!|j�����}|D]1}|�|t'|j|��f���2|�d
t'|j��f��t+|g��S)z�Return string representation of Cookie in the LWP cookie file format.

    Actually, the format is extended a bit -- see module docstring.

    r�r�Nr�)�	path_specN)�	port_specN)�
domain_dotN)r�Nr�)rNrr�r�)r�r�r�r�r�r�rrrr�r�rVr�rrr�sortedr!r�r�r�r�)rIrr�r�s    r�lwp_cookie_strrY's����+�v�|�	$�
�&�+�	�
�F�M�	"�	$�A��{�����&�&�+�)>� ?� ?� ?�
��;�a�h�h�':�;�;�;�
��;�a�h�h�':�;�;�;�
� �@�!�(�(�+?�"@�"@�"@�
�}�0�a�h�h�/�0�0�0�
�~�B�q�x�x��(��v�~�)>�)>�?�?�!A�B�B�B�
�~�2�q�x�x� 1�2�2�2�
�~�<�q�x�x��F�N� ;�<�<�<�
��G�1�8�8�\�6�3E�$F�G�G�G��&�,�#�#�%�%�&�&�D�
�,�,��	���!�S���a��)�)�*�+�+�+�+��H�H�i��V�^�,�,�
-�.�.�.��a�S�!�!�!rc�(�eZdZdZdd�Zd	d�Zd�ZdS)
ra[
    The LWPCookieJar saves a sequence of "Set-Cookie3" lines.
    "Set-Cookie3" is the format used by the libwww-perl library, not known
    to be compatible with any browser, but which is easy to read and
    doesn't lose information about RFC 2965 cookies.

    Additional methods

    as_lwp_str(ignore_discard=True, ignore_expired=True)

    Tc��tj��}g}|D]I}|s|jr�|s|�|��r�$|�dt	|��z���Jd�|dgz��S)z�Return cookies as a string of "\n"-separated "Set-Cookie3" headers.

        ignore_discard and ignore_expires: see docstring for FileCookieJar.save

        zSet-Cookie3: %s�
r�)rtrr2r�rYr�)r"rErFr1r5rIs      r�
as_lwp_strzLWPCookieJar.as_lwp_strPs����i�k�k�����	A�	A�F�!�
�f�n�
��!�
�f�&7�&7��&<�&<�
��
�H�H�&���)?�)?�?�@�@�@�@��y�y��B�4�� � � rNFc��|�#|j�|j}ntt���tjtj|tjtjztjzd��d��5}|�	d��|�	|�
||����ddd��dS#1swxYwYdS)N��wz#LWP-Cookies-2.0
)rBrsrIr@�fdopenrJ�O_CREAT�O_WRONLY�O_TRUNC�writer]rLs     rrGzLWPCookieJar.save`s	�����}�(�T�]�(�(�"�#8�9�9�9�
�Y��G�H�b�j�2�;�6���C�U�K�K��
�
�	E��
�G�G�(�)�)�)�
�G�G�D�O�O�N�N�C�C�D�D�D�	E�	E�	E�	E�	E�	E�	E�	E�	E�	E�	E�	E����	E�	E�	E�	E�	E�	Es�3?B?�?C�Cc���|���}|j�|��sd|z}t|���t	j��}d}d}	d}
		|���}|dkrdS|�|��s�3|t
|��d����}t|g��D�]f}|d\}
}i}i}|	D]}d||<�|dd�D]E\}}|�|�	��}nd}||
vs||	vr|}||	vr
|�d	}|||<�6||
vr|||<�@|||<�F|j
}|d
��}|d��}|�t|��}|�d	}|d��}|�d
��}t|d��|
||d��|d��|||d��|d��|d��|d��|||d��|d��|��}|s	|j
r��8|s|�|��r��Q|�|����h���#t $r�t"$r$t%��td|�d|�����wxYw)Nz5%r does not look like a Set-Cookie3 (LWP) format filezSet-Cookie3:)rVrUrWr�r)r�r�r�r�r�rr�r%r�r
FTr�rr�r�r�r�rVrWr�rUr�rr�z invalid Set-Cookie3 format file �: )�readliner<rfrrtr�r�r�r�rIr*r�rrr2r rPrr")r"r rBrErF�magicr!r1�headerrr�line�datar�r�rr#r�r�r�rr�rr�rr#s                          rrKzLWPCookieJar._really_loados%���
�
�����}�#�#�E�*�*�	!��$�%�C��C�.�.� ��i�k�k����.�
�0��
;	.�4
'��z�z�|�|���2�:�:�u�u����v�.�.����C��K�K�L�L�)�/�/�1�1��.��v�6�6�-'�-'�D�"&�q�'�K�D�%�!�H��D�*�,�,��&+����� $�Q�R�R��(�(���1��=�!"�����B�B�!%�B��+�-�-�2��3F�3F� "�A��
�-�-� �y�d�!�*+�H�Q�K�K��+�-�-�*+�H�Q�K�K�&'�D��G�G� ��A��a�	�l�l�G��a�	�l�l�G��*�"*�7�"3�"3����"&���Q�x�[�[�F�'-�'8�'8��'=�'=�$��q�q��|�|�T�5� �q��y�y�!�!�K�.�.�%�'7���<��� �q��y�y�!�!�K�.�.� �q��{�{�&�&� �q��|�|� �q����#�	%�	%�A�*�!�a�i�!� �)�!�a�l�l�3�.?�.?�!� ��O�O�A�&�&�&�&�i4
'��j�	�	�	���	.�	.�	.�%�'�'�'��)�%�X�X�t�t�-�.�.�
.�	.���s�H3�:F9H3�38I+)TTrS)r?rArBrCr]rGrKrHrrrrCs^������
�
�!�!�!�!� 
E�
E�
E�
E�L.�L.�L.�L.�L.rrc� �eZdZdZd�Zdd�ZdS)r	a�

    WARNING: you may want to backup your browser's cookies file if you use
    this class to save cookies.  I *think* it works, but there have been
    bugs in the past!

    This class differs from CookieJar only in the format it uses to save and
    load cookies to and from a file.  This class uses the Mozilla/Netscape
    `cookies.txt' format.  curl and lynx use this file format, too.

    Don't expect cookies saved while the browser is running to be noticed by
    the browser (in fact, Mozilla on unix will overwrite your saved cookies if
    you change them on disk while it's running; on Windows, you probably can't
    save at all while the browser is running).

    Note that the Mozilla/Netscape format will downgrade RFC2965 cookies to
    Netscape cookies on saving.

    In particular, the cookie version and port number information is lost,
    together with information about whether or not Path, Port and Discard were
    specified by the Set-Cookie2 (or Set-Cookie) header, and whether or not the
    domain as set in the HTTP header started with a dot (yes, I'm aware some
    domains in Netscape files start with a dot and some don't -- trust me, you
    really don't want to know any more about this).

    Note that though Mozilla and Netscape use the same format, they use
    slightly different headers.  The class saves cookies using the Netscape
    header by default (Mozilla can cope with that).

    c��tj��}t�|�����st	d|z���		|���}i}|dkrdS|�t��r&d|t<|tt��d�}|�	d��r
|dd�}|�
���d��s|�
��dkr��|�d��\}}	}
}}}
}|dk}|	dk}	|
dkr|}
d}|�d	��}|	|ksJ�d
}|dkrd}d}td|
|dd
||	||
d
|||dd|��}|s	|j
r��C|s|�|��r��\|�|����r#t $r�t"$r$t%��t	d
|�d|�����wxYw)Nz4%r does not look like a Netscape format cookies filer%r�r\r�)�#r��	�TRUEr�FTr
z%invalid Netscape format cookies file rg)rt�NETSCAPE_MAGIC_RGXr�rhrr��HTTPONLY_PREFIX�
HTTPONLY_ATTRr�r�r�r�rrr2r rPrr")r"r rBrErFr1rkr#r�rr�r�r�r�r�r�rr#s                  rrKzMozillaCookieJar._really_load�su���i�k�k��!�'�'��
�
���5�5�	��F�����
�?	.�7
#��z�z�|�|�����2�:�:�u�u�
�?�?�?�3�3�7�*,�D��'���O� 4� 4� 5� 5�6�D��=�=��&�&�8�t�C�R�C�y���J�J�L�L�+�+�J�7�7���J�J�L�L�B�&�&���
�
�4�(�(�M��(�$����u� �F�*��$4��$>� ��2�:�:�!�D� �E�$�/�/��4�4��'�;�6�6�6�6����b�=�=�"�G�"�G��1�d�E���!�#3�[���!�"�"����	!�	!��&��!�)���%��!�,�,�s�*;�*;�������"�"�"�o7
#��r�	�	�	���	.�	.�	.�%�'�'�'��)�%�X�X�t�t�-�.�.�
.�	.���s�G�2EG�8G>NFc
�P�|�#|j�|j}ntt���tjtj|tjtjztjzd��d��5}|�	t��tj��}|D]�}|j}|s|j
r�|s|�|��r�+|jrd}nd}|�d��rd}	nd}	|j�t%|j��}
nd}
|j�
d}|j}n|j}|j}|�t,��r
t.|z}|�	d�||	|j||
||g��dz����	ddd��dS#1swxYwYdS)	Nr_r`rq�FALSEr�r�rpr\)rBrsrIr@rarJrbrcrdre�NETSCAPE_HEADER_TEXTrtr�rr2r�r�r�r�r�r�r(rtrsr�r�)
r"rBrErFr r1rIr�r�r�r�r�r�s
             rrGzMozillaCookieJar.save's�����}�(�T�]�(�(�"�#8�9�9�9�
�Y��G�H�b�j�2�;�6���C�U�K�K��
�
�"	��
�G�G�(�)�)�)��)�+�+�C��
�
�����%��&�.���%��&�*;�*;�C�*@�*@����=�'�6�&�&�&�f��$�$�S�)�)�,��;�;�$+�k��>�-�!�&�.�1�1�G�G� �G��<�'��D�"�K�E�E�!�;�D�"�L�E��.�.�}�=�=�6�,�v�5�F�����I�I�v�{�F�K�%�w��e�=�>�>�������3
�
"	�"	�"	�"	�"	�"	�"	�"	�"	�"	�"	�"	����"	�"	�"	�"	�"	�"	s�3DF�F�"FrS)r?rArBrCrKrGrHrrr	r	�sE��������>G.�G.�G.�R'�'�'�'�'�'rr	r&)XrC�__all__r@r rMr�rt�urllib.parser��urllib.request�	threadingr��http.client�http�calendarrr
rrrtrsr��client�	HTTP_PORTrr7rrrIrwr"r+r3rXrZrqrVr[rdr;rerlr~r��Ir��Xr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrr
r	rrrrrrr�r�rrPrrrYrr	rHrr�<module>r�s�����6M�M�M��
�	�	�	���������	�	�	�	�����#�#�#�#�#�#�#�#���������������
��	
������
����C���-�.�.���R�Z� @�A�A��:����A�A�A��
����9�8�8��
4�
4�
4��2�2�6�2�2�2��B�B�B�B�&0�0�0�0�(��T��=�=�	��b�j�5�r�x�@�@�����6
�6
�6
�p���,�-/�X�7�7���R�Z�2�B�D�2�8�O�E�E�
��R�Z��&
�D�2�8�O�)���*65�65�65�p�b�j�
� �4�"�)��#���$5�5�5�B3�3�3�
$���$6�7�7��#���$M�N�N��#���$9�:�:���2�:�h�'�'��S�S�S�j#��
�;�/�/�����2���A�A�A�H�"�*�Y���
)�
)��
�
�
�%�%�%�N������(�b�j��2�8�,�,����� 	�	�	������� $���"�*�9�:�:��+�+�+����!
�!
�!
�F���"_E�_E�_E�_E�_E�_E�_E�_E�D��������B_�_�_�_�_�,�_�_�_�B���"��������LD�LD�LD�LD�LD�LD�LD�LD�`���������4)�4)�4)�4)�4)�I�4)�4)�4)�n"�"�"�8x.�x.�x.�x.�x.�=�x.�x.�x.�vP�P�P�P�P�}�P�P�P�P�Pr