Your IP : 3.137.219.221


Current Path : /usr/lib/python3.6/site-packages/requests/__pycache__/
Upload File :
Current File : //usr/lib/python3.6/site-packages/requests/__pycache__/models.cpython-36.opt-1.pyc

3

��[���@s�dZddlZddlZddlZddlmZddlmZddl	m
Z
ddlmZm
Z
mZmZddlmZdd	lmZdd
lmZddlmZddlmZmZmZdd
lmZmZmZm 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.m/Z/m0Z0m1Z1ddl2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z=m>Z>ddl2m?Z@ddlAmBZBeBjCeBjDeBjEeBjFeBjGfZHdZId!ZJdZKGdd�deL�ZMGdd�deL�ZNGdd�deN�ZOGdd�deMeN�ZPGdd �d eL�ZQdS)"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)�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��
iic@s0eZdZedd��Zedd��Zedd��ZdS)�RequestEncodingMixincCsNg}t|j�}|j}|sd}|j|�|j}|rD|jd�|j|�dj|�S)zBuild the path URL to use.�/�?�)r(�url�path�append�query�join)�selfr8�pr9r;�r?�/usr/lib/python3.6/models.py�path_url=s



zRequestEncodingMixin.path_urlcCs�t|ttf�r|St|d�r |St|d�r�g}x|t|�D]p\}}t|t�sVt|d�r\|g}xJ|D]B}|dk	rb|jt|t�r�|jd�n|t|t�r�|jd�n|f�qbWq8Wt|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)Zdoseq)	�
isinstancer*r+�hasattrrr/r:�encoder))�data�result�kZvs�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�rf|g}x\|D]T}|dk	rlt|t�s�t|�}|jt|t�r�|jd�n|t|t�r�|j	d�n|f�qlWqBWx�|D]�\}}d}d}	t|t
tf��r.t|�dk�r|\}
}n&t|�dk�r |\}
}}n|\}
}}}	nt
|��p:|}
|}t|tttf��rX|}n(t|d��rn|j�}n|dk�r|q�n|}t|||
|	d	�}
|
j|d
�|j|
�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)�namerG�filename�headers)�content_type)�
ValueErrorrDr/rrEr+r*r:�decoderF�tuple�list�lenr�	bytearrayrBrZmake_multipartr)�filesrGZ
new_fieldsZfieldsZfield�valrJrIZftZfh�fn�fpZfdataZrf�bodyrQr?r?r@�
_encode_filesmsP




$


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

zRequestHooksMixin.register_hookcCs.y|j|j|�dStk
r(dSXdS)ziDeregister a previously registered hook.
        Returns True if the hook existed, False if not.
        TFN)rg�removerR)r=rirjr?r?r@�deregister_hook�s
z!RequestHooksMixin.deregister_hookN)r^r_r`rkrmr?r?r?r@rc�srcc
@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|	j��D]\}}|j||d�qfW||_||_||_||_||_	|
|_
||_||_||_
dS)N)rirj)rrgrU�itemsrk�methodr8rPrXrGr0�params�auth�cookies)
r=rpr8rPrXrGrqrrrsrgr0rIrJr?r?r@�__init__�s"zRequest.__init__cCs
d|jS)Nz<Request [%s]>)rp)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.)
rpr8rPrXrGr0rqrrrsrg)�PreparedRequest�preparerpr8rPrXrGr0rqrrrsrg)r=r>r?r?r@rw�s
zRequest.prepare)
NNNNNNNNNN)r^r_r`�__doc__rtrurwr?r?r?r@rn�s

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

    Generated from either a :class:`Request <Request>` object or manually.

    Usage::

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

      >>> s = requests.Session()
      >>> s.send(r)
      <Response [200]>
    cCs0d|_d|_d|_d|_d|_t�|_d|_dS)N)rpr8rP�_cookiesr\rrg�_body_position)r=r?r?r@rt"szPreparedRequest.__init__NcCsR|j|�|j||�|j|�|j|�|j|||
�|j||�|j|	�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=rpr8rPrXrGrqrrrsrgr0r?r?r@rw3s


zPreparedRequest.preparecCs
d|jS)Nz<PreparedRequest [%s]>)rp)r=r?r?r@ruEszPreparedRequest.__repr__cCsXt�}|j|_|j|_|jdk	r*|jj�nd|_t|j�|_|j|_|j|_|j	|_	|S)N)
rvrpr8rP�copyrryr\rgrz)r=r>r?r?r@r�HszPreparedRequest.copycCs$||_|jdk	r t|jj��|_dS)zPrepares the given HTTP method.N)rpr�upper)r=rpr?r?r@r{Ss
zPreparedRequest.prepare_methodcCs@ddl}y|j|dd�jd�}Wn|jk
r:t�YnX|S)NrT)Zuts46zutf-8)�idnarFrSZ	IDNAError�UnicodeError)�hostr�r?r?r@�_get_idna_encoded_hostYs
z&PreparedRequest._get_idna_encoded_hostcCs0t|t�r|jd�}ntr"t|�nt|�}|j�}d|krT|j�jd�rT||_	dSyt
|�\}}}}}}}	Wn,tk
r�}
zt|
j
��WYdd}
~
XnX|s�d}|jt|d��}t|��|s�td|��t|��sy|j|�}Wntk
�rtd��YnXn|jd��rtd��|�p"d	}|�r2|d
7}||7}|�rP|dt|�7}|�sZd}t�r�t|t��rv|jd�}t|t��r�|jd�}t|t��r�|jd�}t|t��r�|jd�}t|	t��r�|	jd�}	t|ttf��r�t|�}|j|�}
|
�r|�r
d
||
f}n|
}tt|||d||	g��}||_	dS)zPrepares the given HTTP URL.�utf8�:ZhttpNzDInvalid 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)rDr+rSr,Zunicoder*�lstrip�lower�
startswithr8rrr�args�formatrrrr�r�rFrKrr')r=r8rq�schemerrr�Zportr9r;Zfragment�e�errorZnetlocZ
enc_paramsr?r?r@r|csh








zPreparedRequest.prepare_urlcCs@t�|_|r<x.|j�D]"}t|�|\}}||jt|�<qWdS)z Prepares the given HTTP headers.N)rrPror#r)r=rP�headerrN�valuer?r?r@r}�szPreparedRequest.prepare_headerscCstd}d}|r8|dk	r8d}tj|�}t|t�s8|jd�}tt|d�t|ttt	t
f�g�}yt|�}Wntt
tfk
r�d}YnX|r�|}t|dd�dk	r�y|j�|_Wn ttfk
r�t�|_YnX|r�td��|r�t|�|jd<n
d|jd	<np|�r|j||�\}}n2|�rD|j|�}t|t��s:t|d
��r@d}nd}|j|�|�rjd|jk�rj||jd
<||_dS)z"Prepares the given HTTP body data.Nzapplication/jsonzutf-8rC�tellz1Streamed bodies and files are mutually exclusive.zContent-LengthZchunkedzTransfer-EncodingrBz!application/x-www-form-urlencodedzcontent-typezContent-Type)�complexjson�dumpsrDr+rF�allrEr/rUrTr%r"�	TypeError�AttributeErrorr	�getattrr�rz�IOError�OSError�object�NotImplementedErrorr.rPr]rK�prepare_content_lengthr\)r=rGrXr0r\rQZ	is_stream�lengthr?r?r@r�sJ






zPreparedRequest.prepare_bodycCsL|dk	r$t|�}|rHt|�|jd<n$|jdkrH|jjd�dkrHd|jd<dS)z>Prepare Content-Length header based on request method and bodyNzContent-Length�GET�HEAD�0)r�r�)r"r.rPrp�get)r=r\r�r?r?r@r�	sz&PreparedRequest.prepare_content_lengthr7cCsj|dkr"t|j�}t|�r|nd}|rft|t�rDt|�dkrDt|�}||�}|jj|j�|j	|j
�dS)z"Prepares the given HTTP auth data.NrL)rr8�anyrDrTrVr
�__dict__�updater�r\)r=rrr8Zurl_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)rDr&Z	CookieJarryrrrP)r=rsZ
cookie_headerr?r?r@r~,s
zPreparedRequest.prepare_cookiescCs*|pg}x|D]}|j|||�qWdS)zPrepares the given hooks.N)rk)r=rgrir?r?r@r�@s
zPreparedRequest.prepare_hooks)
NNNNNNNNNN)N)r7)r^r_r`rxrtrwrur�r{rbr�r|r}rr�r�r~r�r?r?r?r@rvs

V
E
rvc
@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_coderPr8�history�encoding�reasonrs�elapsed�requestcCs^d|_d|_d|_d|_t�|_d|_d|_d|_g|_	d|_
ti�|_t
jd�|_d|_dS)NFr)r��_content_consumed�_nextr�rrP�rawr8r�r�r�rrs�datetimeZ	timedeltar�r�)r=r?r?r@rtTs
zResponse.__init__cCs|S)Nr?)r=r?r?r@�	__enter__�szResponse.__enter__cGs|j�dS)N)�close)r=r�r?r?r@�__exit__�szResponse.__exit__cs �js�j�fdd��jD�S)Ncsi|]}t�|d�|�qS)N)r�)rd�attr)r=r?r@�
<dictcomp>�sz)Response.__getstate__.<locals>.<dictcomp>)r��content�	__attrs__)r=r?)r=r@�__getstate__�szResponse.__getstate__cCs>x |j�D]\}}t|||�q
Wt|dd�t|dd�dS)Nr�Tr�)ro�setattr)r=�staterNr�r?r?r@�__setstate__�szResponse.__setstate__cCs
d|jS)Nz<Response [%s]>)r�)r=r?r?r@ru�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
|jd�S)z,Allows you to use a response as an iterator.�)�iter_content)r=r?r?r@rC�szResponse.__iter__cCs&y|j�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)rPr��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�)rPr�r1Zmoved_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.nextcCstj|j�dS)z7The apparent encoding, provided by the chardet library.r�)r-Zdetectr�)r=r?r?r@�apparent_encoding�szResponse.apparent_encodingr
Fcs~��fdd�}�jr(t�jt�r(t��n$�dk	rLt�t�rLtdt����t�j��}|�}�jrh|n|}|rzt	|��}|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.
        c3s�t�jd�r�y$x�jj�dd�D]
}|Vq WWq�tk
rZ}zt|��WYdd}~Xq�tk
r�}zt|��WYdd}~Xq�tk
r�}zt|��WYdd}~Xq�Xnx�jj	��}|s�P|Vq�Wd�_
dS)N�streamT)Zdecode_content)rEr�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�rDr��boolr�intr��typer r)r=r��decode_unicoder�Z
reused_chunksZ
stream_chunksZchunksr?)r�r=r@r��s
zResponse.iter_contentNccs�d}x�|j||d�D]r}|dk	r(||}|r8|j|�}n|j�}|rn|drn|rn|dd|dkrn|j�}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
���r�r�r�)r��split�
splitlines�pop)r=r�r�Z	delimiter�pendingr��lines�liner?r?r@�
iter_liness$

zResponse.iter_linescCsV|jdkrJ|jrtd��|jdks,|jdkr4d|_ndj|jt��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�/s
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
        ``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@�textCs
z
Response.textcKsj|jrZ|jrZt|j�dkrZt|j�}|dk	rZytj|jj|�f|�Stk
rXYnXtj|jf|�S)z�Returns the json-encoded content of a response, if any.

        :param \*\*kwargs: Optional arguments that ``json.loads`` takes.
        :raises ValueError: If the response body does not contain valid json.
        rMN)	r�r�rVr!r��loadsrS�UnicodeDecodeErrorr�)r=�kwargsr�r?r?r@r0is
z
Response.jsoncCsJ|jjd�}i}|rFt|�}x(|D] }|jd�p8|jd�}|||<q"W|S)z8Returns the parsed header links of the response, if any.�linkZrelr8)rPr�r)r=r��l�linksr��keyr?r?r@r��s
zResponse.linkscCs�d}t|jt�rDy|jjd�}WqJtk
r@|jjd�}YqJXn|j}d|jko^dknrxd|j||jf}n,d|jko�dknr�d|j||jf}|r�t||d	��d
S)z2Raises stored :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)ZresponseN)rDr�r+rSr�r�r8r)r=Zhttp_error_msgr�r?r?r@r��szResponse.raise_for_statuscCs0|js|jj�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)r^r_r`rxr�rtr�r�r�r�rur�r�rCrar�r�r�r�r�r��ITER_CHUNK_SIZEr�r�r�r0r�r�r�r?r?r?r@r�Js2
/


7&r�i()Rrxr��sysZencodings.idnaZ	encodingsZurllib3.fieldsrZurllib3.filepostrZurllib3.utilrZurllib3.exceptionsrrrr�ior	rgrZ
structuresrrrr
rsrrr�
exceptionsrrrrrrrZ_internal_utilsrrZutilsrrrrrrr r!r"r#�compatr$r%r&r'r(r)r*r+r,r-r.r/r0r�Zstatus_codesr1Zmoved�found�otherZtemporary_redirectr�r�ZDEFAULT_REDIRECT_LIMITr�r�r�r4rcrnrvr�r?r?r?r@�<module>sB$08rJ<

?>