%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /snap/core/17212/usr/lib/python3/dist-packages/requests/__pycache__/
Upload File :
Create Path :
Current File : //snap/core/17212/usr/lib/python3/dist-packages/requests/__pycache__/models.cpython-35.pyc



~�V]r�@sgdZddlZddlZddlmZmZddlmZddlm	Z	ddl
mZddlm
Z
mZmZdd	lmZdd
lmZddlmZddlmZmZmZmZdd
lmZmZmZmZm Z m!Z!m"Z"ddl#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-ddl.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9ddl.m:Z;ddl<m=Z=e=j>e=j?e=j@e=jAe=jBfZCdZDddZEdZFGdd�deG�ZHGdd�deG�ZIGdd�deI�ZJGdd�deHeI�ZKGdd�deG�ZLdS) z`
requests.models
~~~~~~~~~~~~~~~

This module contains the primary objects that power Requests.
�N)�BytesIO�UnsupportedOperation�)�
default_hooks)�CaseInsensitiveDict)�
HTTPBasicAuth)�cookiejar_from_dict�get_cookie_header�_copy_cookie_jar)�RequestField)�encode_multipart_formdata)�	parse_url)�DecodeError�ReadTimeoutError�
ProtocolError�LocationParseError)�	HTTPError�
MissingSchema�
InvalidURL�ChunkedEncodingError�ContentDecodingError�ConnectionError�StreamConsumedError)
�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�to_native_string)�	cookielib�
urlunparse�urlsplit�	urlencode�str�bytes�StringIO�is_py2�chardet�builtin_str�
basestring)�json)�codes��
iic@sFeZdZedd��Zedd��Zedd��ZdS)�RequestEncodingMixincCsmg}t|j�}|j}|s*d}|j|�|j}|r`|jd�|j|�dj|�S)zBuild the path URL to use.�/�?�)r%�url�path�append�query�join)�selfr6�pr7r9�r=�1/usr/lib/python3/dist-packages/requests/models.py�path_url5s	
	

zRequestEncodingMixin.path_urlcCs
t|ttf�r|St|d�r,|St|d�rg}x�t|�D]�\}}t|t�syt|d�r�|g}xi|D]a}|dk	r�|jt|t�r�|jd�n|t|t�r�|jd�n|f�q�WqNWt|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-8ZdoseqT)	�
isinstancer'r(�hasattrrr-r8�encoder&)�data�result�kZvs�vr=r=r>�_encode_paramsJs 		
!0z#RequestEncodingMixin._encode_paramsc
CsQ|std��nt|t�r0td��g}t|pBi�}t|pTi�}x�|D]�\}}t|t�s�t|d�r�|g}x�|D]|}|dk	r�t|t�s�t|�}|jt|t�r�|jd�n|t|t�r|j	d�n|f�q�WqaWx|D]
\}}d}d}	t|t
tf�r�t|�dkru|\}
}q�t|�dkr�|\}
}}q�|\}
}}}	nt
|�p�|}
|}t|tttf�r�|}n|j�}td|d	|d
|
d|	�}
|
jd|�|j|
�q'Wt|�\}}||fS)
aBuild the body for a multipart/form-data request.

        Will successfully encode files 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.

        zFiles must be provided.zData must not be a string.rANzutf-8���namerE�filename�headers�content_type)�
ValueErrorrBr-rrCr(r'r8�decoderD�tuple�list�lenr�	bytearrayr@rZmake_multipartr)�filesrEZ
new_fieldsZfieldsZfield�valrHrGZftZfh�fn�fpZfdataZrf�bodyrOr=r=r>�
_encode_filesesH		
!0	!z"RequestEncodingMixin._encode_filesN)�__name__�
__module__�__qualname__�propertyr?�staticmethodrIr[r=r=r=r>r24sr2c@s(eZdZdd�Zdd�ZdS)�RequestHooksMixincCs|||jkrtd|��t|tj�rH|j|j|�n0t|d�rx|j|jdd�|D��dS)zProperly register a hook.z1Unsupported event specified, with event name "%s"rAcss'|]}t|tj�r|VqdS)N)rB�collections�Callable)�.0�hr=r=r>�	<genexpr>�sz2RequestHooksMixin.register_hook.<locals>.<genexpr>N)�hooksrPrBrbrcr8rC�extend)r;�event�hookr=r=r>�
register_hook�szRequestHooksMixin.register_hookcCs9y|j|j|�dSWntk
r4dSYnXdS)ziDeregister a previously registered hook.
        Returns True if the hook existed, False if not.
        TFN)rg�removerP)r;rirjr=r=r>�deregister_hook�s

z!RequestHooksMixin.deregister_hookN)r\r]r^rkrmr=r=r=r>ra�srac@sXeZdZdZdddddddddddd�
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 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: dictionary of URL parameters to append to the URL.
    :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', 'http://httpbin.org/get')
      >>> req.prepare()
      <PreparedRequest [GET]>

    Nc
Cs|dkrgn|}|dkr*gn|}|dkrBin|}|dkrZin|}|	dkrrin|	}	t�|_x6t|	j��D]"\}}|jd|d|�q�W||_||_||_||_||_	|
|_
||_||_||_
dS)Nrirj)rrgrS�itemsrk�methodr6rNrVrEr.�params�auth�cookies)
r;rpr6rNrVrErqrrrsrgr.rGrHr=r=r>�__init__�s"								zRequest.__init__cCsd|jS)Nz<Request [%s]>)rp)r;r=r=r>�__repr__�szRequest.__repr__cCsqt�}|jd|jd|jd|jd|jd|jd|jd|jd|j	d	|j
d
|j�
|S)zXConstructs a :class:`PreparedRequest <PreparedRequest>` for transmission and returns it.rpr6rNrVrEr.rqrrrsrg)�PreparedRequest�preparerpr6rNrVrEr.rqrrrsrg)r;r<r=r=r>rw�s											
zRequest.prepare)r\r]r^�__doc__rtrurwr=r=r=r>rn�s
rnc@s�eZdZdZdd�Zdddddddddddd�
Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
ddd�Zdd�Zddd�Z
dd�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', 'http://httpbin.org/get')
      >>> r = req.prepare()
      <PreparedRequest [GET]>

      >>> s = requests.Session()
      >>> s.send(r)
      <Response [200]>

    cCs=d|_d|_d|_d|_d|_t�|_dS)N)rpr6rN�_cookiesrZrrg)r;r=r=r>rts					zPreparedRequest.__init__NcCsk|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;rpr6rNrVrErqrrrsrgr.r=r=r>rw s


zPreparedRequest.preparecCsd|jS)Nz<PreparedRequest [%s]>)rp)r;r=r=r>ru1szPreparedRequest.__repr__cCsvt�}|j|_|j|_|jdk	r?|jj�nd|_t|j�|_|j|_|j|_|S)N)	rvrpr6rN�copyr
ryrZrg)r;r<r=r=r>r�4s	'zPreparedRequest.copycCs4||_|jdk	r0t|jj��|_dS)zPrepares the given HTTP method.N)rpr"�upper)r;rpr=r=r>rz>s	zPreparedRequest.prepare_methodcCs�t|t�r!|jd�}ntr3t|�n	t|�}d|krn|j�jd�rn||_dSy%t	|�\}}}}}}}	Wn4t
k
r�}
zt|
j��WYdd}
~
XnX|s�d}|j
t|d��}t|��|std|��y|jd�jd�}Wntk
rLtd	��YnX|pVd
}|ri|d7}||7}|r�|dt|�7}|s�d}tr5t|t�r�|jd�}t|t�r�|jd�}t|t�r�|jd�}t|t�r|jd�}t|	t�r5|	jd�}	t|ttf�rVt|�}|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 suppliedZidnazutf-8zURL has an invalid label.r5�@r3z%s&%s)rBr(rQr*Zunicoder'�lower�
startswithr6r
rr�args�formatr"rrD�UnicodeErrorrIrr$)r;r6rq�schemerr�hostZportr7r9Zfragment�e�errorZnetlocZ
enc_paramsr=r=r>r{Ds`"	%"


$zPreparedRequest.prepare_urlcCs;|r+tdd�|j�D��|_nt�|_dS)z Prepares the given HTTP headers.css'|]\}}t|�|fVqdS)N)r")rdrL�valuer=r=r>rf�sz2PreparedRequest.prepare_headers.<locals>.<genexpr>N)rrorN)r;rNr=r=r>r|�s%zPreparedRequest.prepare_headersc
Cs�d}d}d}|r:|dk	r:d}tj|�}tt|d�t|ttttf�g�}yt	|�}Wn!t
ttfk
r�d}YnX|r�|}|r�t
d��|r�t|�|jd<q{d|jd<n�|r
|j||�\}}nB|rL|j|�}t|t�s=t|d�rFd}nd	}|j|�|r{d
|jkr{||jd<||_dS)z"Prepares the given HTTP body data.Nzapplication/jsonrAz1Streamed bodies and files are mutually exclusive.zContent-LengthZchunkedzTransfer-Encodingr@z!application/x-www-form-urlencodedzcontent-typezContent-Type)�complexjson�dumps�allrCrBr-rSrR�dictr!�	TypeError�AttributeErrorr�NotImplementedErrorr,rNr[rI�prepare_content_lengthrZ)r;rErVr.rZrOZlengthZ	is_streamr=r=r>r~�s>"	

zPreparedRequest.prepare_bodycCs�t|d�rZt|d�rZ|jdd�t|j��|jd<|jdd�nh|dk	r�t|�}|r�t|�|jd<n4|jd	kr�|jjd�dkr�d|jd<dS)
N�seek�tellrrJzContent-Length�GET�HEAD�0)r�r�)rCr�r,r�rNr!rp�get)r;rZ�lr=r=r>r��s'z&PreparedRequest.prepare_content_lengthr5cCs�|dkr3t|j�}t|�r-|nd}|r�t|t�rft|�dkrft|�}||�}|jj|j�|j	|j
�dS)z"Prepares the given HTTP auth data.NrJ)rr6�anyrBrRrTr�__dict__�updater�rZ)r;rrr6Zurl_auth�rr=r=r>r�s!zPreparedRequest.prepare_authcCs\t|tj�r||_nt|�|_t|j|�}|dk	rX||jd<dS)a�Prepares 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)rBr#Z	CookieJarryrr	rN)r;rsZ
cookie_headerr=r=r>r}�szPreparedRequest.prepare_cookiescCs5|p	g}x"|D]}|j|||�qWdS)zPrepares the given hooks.N)rk)r;rgrir=r=r>r�s
zPreparedRequest.prepare_hooks)r\r]r^rxrtrwrur�rzr{r|r~r�rr}r�r=r=r=r>rv�s
M7rvc
s]eZdZdZdddddddd	d
dg
Z�fdd
�Zdd�Zdd�Zdd�Zdd�Z	dd�Z
dd�Zedd��Z
edd��Zedd��Zed d!��Zd"d#d$d%�Zed&d&d'd(�Zed)d*��Zed+d,��Zd-d.�Zed/d0��Zd1d2�Zd3d4�Z�S)5�ResponsezhThe :class:`Response <Response>` object, which contains a
    server's response to an HTTP request.
    �_content�status_coderNr6�history�encoding�reasonrs�elapsed�requestcs�tt|�j�d|_d|_d|_t�|_d|_d|_	d|_
g|_d|_t
i�|_tjd�|_d|_dS)NFr)�superr�rtr��_content_consumedr�rrN�rawr6r�r�r�rrs�datetimeZ	timedeltar�r�)r;)�	__class__r=r>rts								zResponse.__init__cs0�js�jt�fdd��jD��S)Nc3s'|]}|t�|d�fVqdS)N)�getattr)rd�attr)r;r=r>rfQsz(Response.__getstate__.<locals>.<genexpr>)r��contentr��	__attrs__)r;r=)r;r>�__getstate__Js
	zResponse.__getstate__cCsQx*|j�D]\}}t|||�q
Wt|dd�t|dd�dS)Nr�Tr�)ro�setattr)r;�staterLr�r=r=r>�__setstate__UszResponse.__setstate__cCsd|jS)Nz<Response [%s]>)r�)r;r=r=r>ru]szResponse.__repr__cCs|jS)z,Returns true if :attr:`status_code` is 'OK'.)�ok)r;r=r=r>�__bool__`szResponse.__bool__cCs|jS)z,Returns true if :attr:`status_code` is 'OK'.)r�)r;r=r=r>�__nonzero__dszResponse.__nonzero__cCs
|jd�S)z,Allows you to use a response as an iterator.�)�iter_content)r;r=r=r>rAhszResponse.__iter__cCs+y|j�Wntk
r&dSYnXdS)NFT)�raise_for_statusr)r;r=r=r>r�ls

	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)rNr��REDIRECT_STATI)r;r=r=r>�is_redirecttszResponse.is_redirectcCs(d|jko'|jtjtjfkS)z?True if this Response one of the permanent versions of redirectr�)rNr�r/Zmoved_permanently�permanent_redirect)r;r=r=r>�is_permanent_redirect{szResponse.is_permanent_redirectcCstj|j�dS)z6The apparent encoding, provided by the chardet libraryr�)r+Zdetectr�)r;r=r=r>�apparent_encoding�szResponse.apparent_encodingrFcs���fdd�}�jr9t�jt�r9t��t�j��}|�}�jrc|n|}|r~t|��}|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.

        If decode_unicode is True, content will be decoded using the best
        available encoding based on the response.
        c3st�jd�r�y,x%�jj�dd�D]}|Vq.WWq�tk
rq}zt|��WYdd}~Xq�tk
r�}zt|��WYdd}~Xq�tk
r�}zt|��WYdd}~Xq�Xn%x"�jj	��}|s�P|Vq�Wd�_
dS)N�streamZdecode_contentT)rCr�r�rrrrrrr@r�)�chunkr�)�
chunk_sizer;r=r>�generate�s 
"	z'Response.iter_content.<locals>.generate)r�rBr��boolrrr)r;r��decode_unicoder�Z
reused_chunksZ
stream_chunksZchunksr=)r�r;r>r��s		zResponse.iter_contentNccs�d}x�|jd|d|�D]�}|dk	r;||}|rS|j|�}n|j�}|r�|dr�|r�|dd|dkr�|j�}nd}x|D]}|Vq�WqW|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.
        Nr�r�r���r�r�r�)r��split�
splitlines�pop)r;r�r�Z	delimiter�pendingr��lines�liner=r=r>�
iter_lines�s
.

zResponse.iter_linescCs�|jdkr�y[|jr'td��|jdkrBd|_n't�j|jt��pct�|_Wntk
r�d|_YnXd|_|jS)z"Content of the response, in bytes.Fz2The content for this response was already consumedrNT)	r�r��RuntimeErrorr�r(r:r��CONTENT_CHUNK_SIZEr�)r;r=r=r>r��s		+
	zResponse.contentcCs�d}|j}|js"td�S|jdkr:|j}yt|j|dd�}Wn-ttfk
r�t|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.
        Nr5�errors�replace)r�r�r'r��LookupErrorr�)r;r�r�r=r=r>�text�s		
	z
Response.textcKs�|jrot|j�dkrot|j�}|dk	roy tj|jj|�|�SWntk
rnYnXtj|j|�S)z�Returns the json-encoded content of a response, if any.

        :param \*\*kwargs: Optional arguments that ``json.loads`` takes.
        rKN)	r�rTr�r r��loadsrQ�UnicodeDecodeErrorr�)r;�kwargsr�r=r=r>r.s
z
Response.jsoncCsg|jjd�}i}|rct|�}x6|D].}|jd�pR|jd�}|||<q1W|S)z8Returns the parsed header links of the response, if any.�linkZrelr6)rNr�r)r;�headerr��linksr��keyr=r=r>r�*s
zResponse.linkscCs�d}d|jko dknrDd|j|j|jf}n;d|jko^dknrd|j|j|jf}|r�t|d|��dS)	z2Raises stored :class:`HTTPError`, if one occurred.r5i�i�z%s Client Error: %s for url: %siXz%s Server Error: %s for url: %sZresponseN)r�r�r6r)r;Zhttp_error_msgr=r=r>r�<szResponse.raise_for_statuscCs#|js|jj�S|jj�S)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.*
        )r�r��closeZrelease_conn)r;r=r=r>r�Js	
zResponse.close)r\r]r^rxr�rtr�r�rur�r�rAr_r�r�r�r�r��ITER_CHUNK_SIZEr�r�r�r.r�r�r�r=r=)r�r>r�s,0/&r�)Mrxrbr��iorrrgrZ
structuresrrrrrsrr	r
Zpackages.urllib3.fieldsrZpackages.urllib3.filepostrZpackages.urllib3.utilr
Zpackages.urllib3.exceptionsrrrr�
exceptionsrrrrrrrZutilsrrrrrrrr r!r"�compatr#r$r%r&r'r(r)r*r+r,r-r.r�Zstatus_codesr/Zmoved�found�otherZtemporary_redirectr�r�ZDEFAULT_REDIRECT_LIMITr�r��objectr2rarnrvr�r=r=r=r>�<module>s<"4FL
mE�

Zerion Mini Shell 1.0