AlkantarClanX12

Your IP : 18.117.154.134


Current Path : /opt/alt/python37/lib/python3.7/site-packages/requests/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib/python3.7/site-packages/requests/__pycache__/models.cpython-37.pyc

B

^��`+��@s�dZddlZddlZddlZddlmZddlmZddl	m
Z
ddlmZm
Z
mZmZddlmZdd	lmZdd
lmZddlmZddlmZmZmZdd
lmZmZmZm Z m!Z!m"Z"m#Z#m$Z$ddl%m&Z&m'Z'ddl(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2ddl3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z=m>Z>m?Z?ddl3m@ZAddlBmCZCeCjDeCjEeCjFeCjGeCjHfZIdZJdZKdZLGdd�deM�ZNGdd�deM�ZOGdd�deO�ZPGdd�deNeO�ZQGdd�deM�ZRdS) z`
requests.models
~~~~~~~~~~~~~~~

This module contains the primary objects that power Requests.
�N)�RequestField)�encode_multipart_formdata)�	parse_url)�DecodeError�ReadTimeoutError�
ProtocolError�LocationParseError)�UnsupportedOperation�)�
default_hooks)�CaseInsensitiveDict)�
HTTPBasicAuth)�cookiejar_from_dict�get_cookie_header�_copy_cookie_jar)�	HTTPError�
MissingSchema�
InvalidURL�ChunkedEncodingError�ContentDecodingError�ConnectionError�StreamConsumedError�InvalidJSONError)�to_native_string�unicode_is_ascii)
�guess_filename�get_auth_from_url�requote_uri�stream_decode_response_unicode�to_key_val_list�parse_header_links�iter_slices�guess_json_utf�	super_len�check_header_validity)�Callable�Mapping�	cookielib�
urlunparse�urlsplit�	urlencode�str�bytes�is_py2�chardet�builtin_str�
basestring)�json)�codes�i(ic@s0eZdZedd��Zedd��Zedd��ZdS)�RequestEncodingMixincCsNg}t|j�}|j}|sd}|�|�|j}|rD|�d�|�|�d�|�S)zBuild the path URL to use.�/�?�)r)�url�path�append�query�join)�selfr8�pr9r;�r?�@/opt/alt/python37/lib/python3.7/site-packages/requests/models.py�path_url=s



zRequestEncodingMixin.path_urlcCs�t|ttf�r|St|d�r |St|d�r�g}xzt|�D]n\}}t|t�sTt|d�sZ|g}xJ|D]B}|dk	r`|�t|t�r�|�d�n|t|t�r�|�d�n|f�q`Wq8Wt|dd�S|SdS)z�Encode parameters in a piece of data.

        Will successfully encode parameters when passed as a dict or a list of
        2-tuples. Order is retained if data is a list of 2-tuples but arbitrary
        if parameters are supplied as a dict.
        �read�__iter__Nzutf-8T)�doseq)	�
isinstancer+r,�hasattrrr0r:�encoder*)�data�result�k�vs�vr?r?r@�_encode_paramsRs 	


$z#RequestEncodingMixin._encode_paramscCs�|std��nt|t�r td��g}t|p,i�}t|p8i�}x�|D]�\}}t|t�s^t|d�sd|g}x\|D]T}|dk	rjt|t�s�t|�}|�t|t�r�|�d�n|t|t�r�|�	d�n|f�qjWqBWx�|D]�\}}d}d}	t|t
tf��r,t|�dk�r|\}
}n&t|�dk�r|\}
}}n|\}
}}}	nt
|��p8|}
|}t|tttf��rV|}n(t|d��rl|��}n|dk�rzq�n|}t|||
|	d	�}
|
j|d
�|�|
�q�Wt|�\}}||fS)a�Build the body for a multipart/form-data request.

        Will successfully encode files when passed as a dict or a list of
        tuples. Order is retained if data is a list of tuples but arbitrary
        if parameters are supplied as a dict.
        The tuples may be 2-tuples (filename, fileobj), 3-tuples (filename, fileobj, contentype)
        or 4-tuples (filename, fileobj, contentype, custom_headers).
        zFiles must be provided.zData must not be a string.rCNzutf-8��rB)�namerH�filename�headers)�content_type)�
ValueErrorrEr0rrFr,r+r:�decoderG�tuple�list�lenr�	bytearrayrBrZmake_multipartr)�filesrHZ
new_fields�fields�field�valrLrJZftZfh�fn�fpZfdataZrf�bodyrSr?r?r@�
_encode_filesmsP




$


z"RequestEncodingMixin._encode_filesN)�__name__�
__module__�__qualname__�propertyrA�staticmethodrMrar?r?r?r@r4<sr4c@seZdZdd�Zdd�ZdS)�RequestHooksMixincCsZ||jkrtd|��t|t�r2|j|�|�n$t|d�rV|j|�dd�|D��dS)zProperly register a hook.z1Unsupported event specified, with event name "%s"rCcss|]}t|t�r|VqdS)N)rEr%)�.0�hr?r?r@�	<genexpr>�sz2RequestHooksMixin.register_hook.<locals>.<genexpr>N)�hooksrTrEr%r:rF�extend)r=�event�hookr?r?r@�
register_hook�s


zRequestHooksMixin.register_hookcCs.y|j|�|�dStk
r(dSXdS)ziDeregister a previously registered hook.
        Returns True if the hook existed, False if not.
        TFN)rk�removerT)r=rmrnr?r?r@�deregister_hook�s
z!RequestHooksMixin.deregister_hookN)rbrcrdrorqr?r?r?r@rg�srgc
@s*eZdZdZd	dd�Zdd�Zdd�ZdS)
�Requesta{A user-created :class:`Request <Request>` object.

    Used to prepare a :class:`PreparedRequest <PreparedRequest>`, which is sent to the server.

    :param method: HTTP method to use.
    :param url: URL to send.
    :param headers: dictionary of headers to send.
    :param files: dictionary of {filename: fileobject} files to multipart upload.
    :param data: the body to attach to the request. If a dictionary or
        list of tuples ``[(key, value)]`` is provided, form-encoding will
        take place.
    :param json: json for the body to attach to the request (if files or data is not specified).
    :param params: URL parameters to append to the URL. If a dictionary or
        list of tuples ``[(key, value)]`` is provided, form-encoding will
        take place.
    :param auth: Auth handler or (user, pass) tuple.
    :param cookies: dictionary or CookieJar of cookies to attach to this request.
    :param hooks: dictionary of callback hooks, for internal usage.

    Usage::

      >>> import requests
      >>> req = requests.Request('GET', 'https://httpbin.org/get')
      >>> req.prepare()
      <PreparedRequest [GET]>
    Nc
Cs�|dkrgn|}|dkrgn|}|dkr,in|}|dkr<in|}|	dkrLin|	}	t�|_x&t|	���D]\}}|j||d�qfW||_||_||_||_||_	|
|_
||_||_||_
dS)N)rmrn)rrkrW�itemsro�methodr8rRrZrHr1�params�auth�cookies)
r=rtr8rRrZrHrurvrwrkr1rJrLr?r?r@�__init__�s"zRequest.__init__cCs
d|jS)Nz<Request [%s]>)rt)r=r?r?r@�__repr__�szRequest.__repr__cCs<t�}|j|j|j|j|j|j|j|j|j	|j
|jd�
|S)zXConstructs a :class:`PreparedRequest <PreparedRequest>` for transmission and returns it.)
rtr8rRrZrHr1rurvrwrk)�PreparedRequest�preparertr8rRrZrHr1rurvrwrk)r=r>r?r?r@r{�s
zRequest.prepare)
NNNNNNNNNN)rbrcrd�__doc__rxryr{r?r?r?r@rr�s

rrc
@s�eZdZdZdd�Zddd�Zdd�Zd	d
�Zdd�Ze	d
d��Z
dd�Zdd�Zddd�Z
dd�Zd dd�Zdd�Zdd�ZdS)!rza)The fully mutable :class:`PreparedRequest <PreparedRequest>` object,
    containing the exact bytes that will be sent to the server.

    Instances are generated from a :class:`Request <Request>` object, and
    should not be instantiated manually; doing so may produce undesirable
    effects.

    Usage::

      >>> import requests
      >>> req = requests.Request('GET', 'https://httpbin.org/get')
      >>> r = req.prepare()
      >>> r
      <PreparedRequest [GET]>

      >>> s = requests.Session()
      >>> s.send(r)
      <Response [200]>
    cCs0d|_d|_d|_d|_d|_t�|_d|_dS)N)rtr8rR�_cookiesr`rrk�_body_position)r=r?r?r@rx%szPreparedRequest.__init__NcCsR|�|�|�||�|�|�|�|�|�|||
�|�||�|�|	�dS)z6Prepares the entire request with the given parameters.N)�prepare_method�prepare_url�prepare_headers�prepare_cookies�prepare_body�prepare_auth�
prepare_hooks)r=rtr8rRrZrHrurvrwrkr1r?r?r@r{6s


zPreparedRequest.preparecCs
d|jS)Nz<PreparedRequest [%s]>)rt)r=r?r?r@ryHszPreparedRequest.__repr__cCsXt�}|j|_|j|_|jdk	r*|j��nd|_t|j�|_|j|_|j|_|j	|_	|S)N)
rzrtr8rR�copyrr}r`rkr~)r=r>r?r?r@r�KszPreparedRequest.copycCs$||_|jdk	r t|j���|_dS)zPrepares the given HTTP method.N)rtr�upper)r=rtr?r?r@rVs
zPreparedRequest.prepare_methodcCs@ddl}y|j|dd��d�}Wn|jk
r:t�YnX|S)NrT)Zuts46zutf-8)�idnarGrUZ	IDNAError�UnicodeError)�hostr�r?r?r@�_get_idna_encoded_host\s
z&PreparedRequest._get_idna_encoded_hostc
Cs,t|t�r|�d�}ntr"t|�nt|�}|��}d|krR|���d�sR||_	dSyt
|�\}}}}}}}	Wn,tk
r�}
zt|
j
��Wdd}
~
XYnX|s�d}|�t|d��}t|��|s�td|��t|��sy|�|�}Wntk
r�td��YnXn|�d��rtd��|�pd	}|�r.|d
7}||7}|�rL|dt|�7}|�sVd}t�r�t|t��rr|�d�}t|t��r�|�d�}t|t��r�|�d�}t|t��r�|�d�}t|	t��r�|	�d�}	t|ttf��r�t|�}|�|�}
|
�r
|�rd
||
f}n|
}tt|||d||	g��}||_	dS)zPrepares the given HTTP URL.�utf8�:�httpNzDInvalid URL {0!r}: No schema supplied. Perhaps you meant http://{0}?z Invalid URL %r: No host suppliedzURL has an invalid label.�*r7�@r5zutf-8z%s&%s)rEr,rUr-�unicoder+�lstrip�lower�
startswithr8rrr�args�formatrrrr�r�rGrMrr()r=r8ru�schemervr��portr9r;�fragment�e�error�netlocZ
enc_paramsr?r?r@r�fsh








zPreparedRequest.prepare_urlcCs@t�|_|r<x.|��D]"}t|�|\}}||jt|�<qWdS)z Prepares the given HTTP headers.N)rrRrsr$r)r=rR�headerrP�valuer?r?r@r��szPreparedRequest.prepare_headersc	
Cs�d}d}|sn|dk	rnd}ytj|dd�}Wn.tk
rX}zt||d��Wdd}~XYnXt|t�sn|�d�}tt|d�t|t	t
ttf�g�}|�r:yt
|�}Wntttfk
r�d}YnX|}t|dd�dk	�r
y|��|_Wn"ttfk
�rt�|_YnX|�rtd	��|�r.t|�|jd
<n
d|jd<np|�rR|�||�\}}n2|�r�|�|�}t|t	��szt|d
��r�d}nd}|�|�|�r�d|jk�r�||jd<||_dS)z"Prepares the given HTTP body data.Nzapplication/jsonF)�	allow_nan)�requestzutf-8rC�tellz1Streamed bodies and files are mutually exclusive.zContent-Length�chunkedzTransfer-EncodingrBz!application/x-www-form-urlencodedzcontent-typezContent-Type)�complexjson�dumpsrTrrEr,rG�allrFr0rWrVr&r#�	TypeError�AttributeErrorr	�getattrr�r~�IOError�OSError�object�NotImplementedErrorr/rRrarM�prepare_content_lengthr`)	r=rHrZr1r`rS�veZ	is_stream�lengthr?r?r@r��sP





zPreparedRequest.prepare_bodycCsL|dk	r$t|�}|rHt|�|jd<n$|jdkrH|j�d�dkrHd|jd<dS)z>Prepare Content-Length header based on request method and bodyNzContent-Length)ZGETZHEAD�0)r#r/rRrt�get)r=r`r�r?r?r@r�sz&PreparedRequest.prepare_content_lengthr7cCsj|dkr"t|j�}t|�r|nd}|rft|t�rDt|�dkrDt|�}||�}|j�|j�|�	|j
�dS)z"Prepares the given HTTP auth data.NrN)rr8�anyrErVrXr
�__dict__�updater�r`)r=rvr8Zurl_auth�rr?r?r@r�s
zPreparedRequest.prepare_authcCs@t|tj�r||_n
t|�|_t|j|�}|dk	r<||jd<dS)aPrepares the given HTTP cookie data.

        This function eventually generates a ``Cookie`` header from the
        given cookies using cookielib. Due to cookielib's design, the header
        will not be regenerated if it already exists, meaning this function
        can only be called once for the life of the
        :class:`PreparedRequest <PreparedRequest>` object. Any subsequent calls
        to ``prepare_cookies`` will have no actual effect, unless the "Cookie"
        header is removed beforehand.
        NZCookie)rEr'Z	CookieJarr}rrrR)r=rwZ
cookie_headerr?r?r@r�4s
zPreparedRequest.prepare_cookiescCs*|pg}x|D]}|�|||�qWdS)zPrepares the given hooks.N)ro)r=rkrmr?r?r@r�Hs
zPreparedRequest.prepare_hooks)
NNNNNNNNNN)N)r7)rbrcrdr|rxr{ryr�rrfr�r�r�r�r�r�r�r�r?r?r?r@rzs

V
J
rzc
@seZdZdZdddddddd	d
dg
Zdd
�Zdd�Zdd�Zdd�Zdd�Z	dd�Z
dd�Zdd�Zdd�Z
edd��Zed d!��Zed"d#��Zed$d%��Zed&d'��Zd;d*d+�Zed)d,fd-d.�Zed/d0��Zed1d2��Zd3d4�Zed5d6��Zd7d8�Zd9d:�Zd,S)<�ResponsezhThe :class:`Response <Response>` object, which contains a
    server's response to an HTTP request.
    �_content�status_coderRr8�history�encoding�reasonrw�elapsedr�cCs^d|_d|_d|_d|_t�|_d|_d|_d|_g|_	d|_
ti�|_t
�d�|_d|_dS)NFr)r��_content_consumed�_nextr�rrR�rawr8r�r�r�rrw�datetime�	timedeltar�r�)r=r?r?r@rx\s
zResponse.__init__cCs|S)Nr?)r=r?r?r@�	__enter__�szResponse.__enter__cGs|��dS)N)�close)r=r�r?r?r@�__exit__�szResponse.__exit__cs �js�j�fdd��jD�S)Ncsi|]}t�|d�|�qS)N)r�)rh�attr)r=r?r@�
<dictcomp>�sz)Response.__getstate__.<locals>.<dictcomp>)r��content�	__attrs__)r=r?)r=r@�__getstate__�szResponse.__getstate__cCs>x |��D]\}}t|||�q
Wt|dd�t|dd�dS)Nr�Tr�)rs�setattr)r=�staterPr�r?r?r@�__setstate__�szResponse.__setstate__cCs
d|jS)Nz<Response [%s]>)r�)r=r?r?r@ry�szResponse.__repr__cCs|jS)akReturns True if :attr:`status_code` is less than 400.

        This attribute checks if the status code of the response is between
        400 and 600 to see if there was a client error or a server error. If
        the status code, is between 200 and 400, this will return True. This
        is **not** a check to see if the response code is ``200 OK``.
        )�ok)r=r?r?r@�__bool__�szResponse.__bool__cCs|jS)akReturns True if :attr:`status_code` is less than 400.

        This attribute checks if the status code of the response is between
        400 and 600 to see if there was a client error or a server error. If
        the status code, is between 200 and 400, this will return True. This
        is **not** a check to see if the response code is ``200 OK``.
        )r�)r=r?r?r@�__nonzero__�szResponse.__nonzero__cCs
|�d�S)z,Allows you to use a response as an iterator.�)�iter_content)r=r?r?r@rC�szResponse.__iter__cCs&y|��Wntk
r dSXdS)axReturns True if :attr:`status_code` is less than 400, False if not.

        This attribute checks if the status code of the response is between
        400 and 600 to see if there was a client error or a server error. If
        the status code is between 200 and 400, this will return True. This
        is **not** a check to see if the response code is ``200 OK``.
        FT)�raise_for_statusr)r=r?r?r@r��s
	zResponse.okcCsd|jko|jtkS)z�True if this Response is a well-formed HTTP redirect that could have
        been processed automatically (by :meth:`Session.resolve_redirects`).
        �location)rRr��REDIRECT_STATI)r=r?r?r@�is_redirect�szResponse.is_redirectcCsd|jko|jtjtjfkS)z@True if this Response one of the permanent versions of redirect.r�)rRr�r2Zmoved_permanently�permanent_redirect)r=r?r?r@�is_permanent_redirect�szResponse.is_permanent_redirectcCs|jS)zTReturns a PreparedRequest for the next request in a redirect chain, if there is one.)r�)r=r?r?r@�next�sz
Response.nextcCst�|j�dS)zOThe apparent encoding, provided by the charset_normalizer or chardet libraries.r�)r.�detectr�)r=r?r?r@�apparent_encoding�szResponse.apparent_encodingr
Fcs|��fdd�}�jr(t�jt�r(t��n"�dk	rJt�t�sJtdt����t�j��}|�}�jrf|n|}|rxt	|��}|S)a�Iterates over the response data.  When stream=True is set on the
        request, this avoids reading the content at once into memory for
        large responses.  The chunk size is the number of bytes it should
        read into memory.  This is not necessarily the length of each item
        returned as decoding can take place.

        chunk_size must be of type int or None. A value of None will
        function differently depending on the value of `stream`.
        stream=True will read data as it arrives in whatever size the
        chunks are received. If stream=False, data is returned as
        a single chunk.

        If decode_unicode is True, content will be decoded using the best
        available encoding based on the response.
        c
3s�t�jd�r�y$x�jj�dd�D]
}|Vq WWq�tk
rZ}zt|��Wdd}~XYq�tk
r�}zt|��Wdd}~XYq�tk
r�}zt|��Wdd}~XYq�Xnx�j�	��}|s�P|Vq�Wd�_
dS)N�streamT)Zdecode_content)rFr�r�rrrrrrrBr�)�chunkr�)�
chunk_sizer=r?r@�generate�s 
z'Response.iter_content.<locals>.generateNz.chunk_size must be an int, it is instead a %s.)
r�rEr��boolr�intr��typer!r)r=r��decode_unicoder�Z
reused_chunksZ
stream_chunks�chunksr?)r�r=r@r��s
zResponse.iter_contentNccs�d}x�|j||d�D]r}|dk	r(||}|r8|�|�}n|��}|rn|drn|rn|dd|dkrn|��}nd}x|D]
}|VqxWqW|dk	r�|VdS)z�Iterates over the response data, one line at a time.  When
        stream=True is set on the request, this avoids reading the
        content at once into memory for large responses.

        .. note:: This method is not reentrant safe.
        N)r�r����)r��split�
splitlines�pop)r=r�r��	delimiter�pendingr��lines�liner?r?r@�
iter_liness$

zResponse.iter_linescCsV|jdkrJ|jrtd��|jdks,|jdkr4d|_nd�|�t��pFd|_d|_|jS)z"Content of the response, in bytes.Fz2The content for this response was already consumedrN�T)r�r��RuntimeErrorr�r�r<r��CONTENT_CHUNK_SIZE)r=r?r?r@r�7s
zResponse.contentc	Cshd}|j}|jstd�S|jdkr(|j}yt|j|dd�}Wn&ttfk
rbt|jdd�}YnX|S)a�Content of the response, in unicode.

        If Response.encoding is None, encoding will be guessed using
        ``charset_normalizer`` or ``chardet``.

        The encoding of the response content is determined based solely on HTTP
        headers, following RFC 2616 to the letter. If you can take advantage of
        non-HTTP knowledge to make a better guess at the encoding, you should
        set ``r.encoding`` appropriately before accessing this property.
        Nr7�replace)�errors)r�r�r+r��LookupErrorr�)r=r�r�r?r?r@�textKs
z
Response.textcKsh|jsX|jrXt|j�dkrXt|j�}|dk	rXytj|j�|�f|�Stk
rVYnXtj|jf|�S)a.Returns the json-encoded content of a response, if any.

        :param \*\*kwargs: Optional arguments that ``json.loads`` takes.
        :raises simplejson.JSONDecodeError: If the response body does not
            contain valid json and simplejson is installed.
        :raises json.JSONDecodeError: If the response body does not contain
            valid json and simplejson is not installed on Python 3.
        :raises ValueError: If the response body does not contain valid
            json and simplejson is not installed on Python 2.        
        rON)	r�r�rXr"r��loadsrU�UnicodeDecodeErrorr�)r=�kwargsr�r?r?r@r1qs
z
Response.jsoncCsJ|j�d�}i}|rFt|�}x(|D] }|�d�p8|�d�}|||<q"W|S)z8Returns the parsed header links of the response, if any.�link�relr8)rRr�r )r=r��l�linksr��keyr?r?r@r��s
zResponse.linkscCs�d}t|jt�rDy|j�d�}WqJtk
r@|j�d�}YqJXn|j}d|jkr`dkrxnnd|j||jf}n,d|jkr�dkr�nnd|j||jf}|r�t||d	��d
S)z+Raises :class:`HTTPError`, if one occurred.r7zutf-8z
iso-8859-1i�i�z%s Client Error: %s for url: %siXz%s Server Error: %s for url: %s)�responseN)rEr�r,rUr�r�r8r)r=Zhttp_error_msgr�r?r?r@r��szResponse.raise_for_statuscCs0|js|j��t|jdd�}|dk	r,|�dS)z�Releases the connection back to the pool. Once this method has been
        called the underlying ``raw`` object must not be accessed again.

        *Note: Should not normally need to be called explicitly.*
        �release_connN)r�r�r�r�)r=r�r?r?r@r��s

zResponse.close)r
F)rbrcrdr|r�rxr�r�r�r�ryr�r�rCrer�r�r�r�r�r��ITER_CHUNK_SIZEr�r�r�r1r�r�r�r?r?r?r@r�Rs2
/


7&r�)Sr|r��sysZencodings.idna�	encodingsZurllib3.fieldsrZurllib3.filepostrZurllib3.utilrZurllib3.exceptionsrrrr�ior	rkrZ
structuresrrvr
rwrrr�
exceptionsrrrrrrrrZ_internal_utilsrr�utilsrrrrrr r!r"r#r$�compatr%r&r'r(r)r*r+r,r-r.r/r0r1r�Zstatus_codesr2Zmoved�found�otherZtemporary_redirectr�r�ZDEFAULT_REDIRECT_LIMITr�r�r�r4rgrrrzr�r?r?r?r@�<module>sB(08rJD