Your IP : 216.73.216.213


Current Path : /opt/alt/python35/lib/python3.5/site-packages/requests_mock/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib/python3.5/site-packages/requests_mock/__pycache__/response.cpython-35.pyc



b#�]�&�@soddlZddlmZddlmZmZddlmZddlmZm	Z	ddl
Z
ddlmZddl
mZddl
mZed	d
ddd
g�Zeddddg�ZdZe�ZGdd�de�Zdd�ZGdd�de�Zdd�ZGdd�de
j�Zdd�ZGdd �d e�ZGd!d"�d"e�ZdS)#�N)�HTTPAdapter)�MockRequest�MockResponse)�RequestsCookieJar)�
merge_cookies�cookiejar_from_dict)�HTTPResponse)�compat)�
exceptions�raw�body�content�text�json�status_code�reason�headers�cookies��cs"eZdZ�fdd�Z�S)�	CookieJarcstt|�j|||�S)azAdd a cookie to the Jar.

        :param str name: cookie name/key.
        :param str value: cookie value.
        :param int version: Integer or None. Netscape cookies have version 0.
            RFC 2965 and RFC 2109 cookies have a version cookie-attribute of 1.
            However, note that cookielib may 'downgrade' RFC 2109 cookies to
            Netscape cookies, in which case version is 0.
        :param str port: String representing a port or a set of ports
            (eg. '80', or '80,8080'),
        :param str domain: The domain the cookie should apply to.
        :param str path: Cookie path (a string, eg. '/acme/rocket_launchers').
        :param bool secure: True if cookie should only be returned over a
            secure connection.
        :param int expires: Integer expiry date in seconds since epoch or None.
        :param bool discard: True if this is a session cookie.
        :param str comment: String comment from the server explaining the
            function of this cookie.
        :param str comment_url: URL linking to a comment from the server
            explaining the function of this cookie.
        )�superr�set)�self�name�value�kwargs)�	__class__��G/opt/alt/python35/lib/python3.5/site-packages/requests_mock/response.pyr"sz
CookieJar.set)�__name__�
__module__�__qualname__rrr)rrr srcsz�fdd�tD�}t|�dkrDtddj|���dd��D�}|rvtddj|���dS)Ncs.g|]$}�j|d�dk	r|�qS)N)�pop)�.0�x)rrr�
<listcomp>>s	z)_check_body_arguments.<locals>.<listcomp>�z5You may only supply one body element. You supplied %sz, cSs"g|]}|tkr|�qSr)�
_HTTP_ARGS)r#r$rrrr%Ds	z5Too many arguments provided. Unexpected arguments %s.)�
_BODY_ARGS�len�RuntimeError�join�	TypeError)r�provided�extrar)rr�_check_body_arguments<sr/c@s.eZdZdZdd�Zdd�ZdS)�_FakeConnectionzBAn object that can mock the necessary parts of a socket interface.cKsd}tj|��dS)NzwThis response was created without a connection. You are therefore unable to make a request directly on that connection.)r
ZInvalidRequest)r�requestr�msgrrr�sendNsz_FakeConnection.sendcCsdS)Nr)rrrr�closeSsz_FakeConnection.closeN)rr r!�__doc__r3r4rrrrr0Ksr0cCsKtj|j�}|jjt|�t|��|rGt|j|�dS)z�Add cookies to the response.

    Cookies in requests are extracted from the headers in the original_response
    httplib.HTTPMessage which we don't create so we have to do this step
    manually.
    N)r	Z_FakeHTTPMessagerr�extract_cookiesrrr)r1�responserZhttp_messagerrr�_extract_cookiesWs
	
r8c@s"eZdZdZdd�ZdS)�	_IOReaderaA reader that makes a BytesIO look like a HTTPResponse.

    A HTTPResponse will return an empty string when you read from it after
    the socket has been closed. A BytesIO will raise a ValueError. For
    compatibility we want to do the same thing a HTTPResponse does.
    cOs,|jrtjd�Stjj|||�S)N�)�closed�six�b�BytesIO�read)r�argsrrrrr?rs	
z_IOReader.readN)rr r!r5r?rrrrr9jsr9c
Ks�|jdt��}t|�|jdd�}|jdd�}|jdd�}|jdd�}|jdd�}d}|r�t|tj�r�td��|r�t|tj�r�td	��|dk	r�tj	|�}|dk	rd
}|j
|�}|dk	rt|�}|s�td|j
dt�d
|j
d
i�d|j
d�d|ptttjd��dddddtj�}tj||�}	||	_||	_t||	|j
d��|	S)a
    :param int status_code: The status code to return upon a successful
        match. Defaults to 200.
    :param HTTPResponse raw: A HTTPResponse object to return upon a
        successful match.
    :param io.IOBase body: An IO object with a read() method that can
        return a body on successful match.
    :param bytes content: A byte string to return upon a successful match.
    :param unicode text: A text string to return upon a successful match.
    :param object json: A python object to be converted to a JSON string
        and returned upon a successful match.
    :param dict headers: A dictionary object containing headers that are
        returned upon a successful match.
    :param CookieJar cookies: A cookie jar with cookies to set on the
        response.
    �
connectionrNrr
rrzContent should be binary datazText should be string datazutf-8�statusrrrr:Zdecode_contentFZpreload_contentZoriginal_responser)r"r0r/�
isinstancer<�binary_typer,�string_types�	jsonutils�dumps�encoder9r�get�_DEFAULT_STATUSr=r	Z_fake_http_response�
_http_adapterZbuild_responserA�encodingr8)
r1rrArrr
rrrLr7rrr�create_responsezs@
		rMc@s"eZdZdZdd�ZdS)�_Contextz:Stores the data being used to process a current URL match.cCs(||_||_||_||_dS)N)rrrr)rrrrrrrr�__init__�s			z_Context.__init__N)rr r!r5rOrrrrrN�srNc@s(eZdZdd�Zdd�ZdS)�_MatcherResponsecKs�|jdd�|_|jr0|r0td��t|�||_|jjd�}|jjd�}|r�t|�p�t|tj	�r�td��|r�t|�p�t|tj
�r�td��dS)N�excz(Cannot provide other arguments with exc.r
rz+Content should be a callback or binary dataz(Text should be a callback or string data)r"�_excr,r/�_paramsrI�callablerCr<rDrE)rrr
rrrrrO�s
	z_MatcherResponse.__init__csE|jr|j�|jjdt��}t|t�rKt|t��}t|jjdi�j�|jjdt	�|jjd�|����fdd�}t
�d||jjd��d||jjd��d	||jjd	��d
||jjd
��d|jjd�d�jd�jd�j
d�j�	S)Nrrrrcs#t|�r|��||�S|S)N)rT)�fr@r)�contextr1rr�_call�sz,_MatcherResponse.get_response.<locals>._callrrr
rr)rRrSrIrrC�dictrrN�copyrJrMrrrr)rr1rrWr)rVr1r�get_response�s(							z_MatcherResponse.get_responseN)rr r!rOrZrrrrrP�srP)rrFZrequests.adaptersrZrequests.cookiesrrrrrr<Zurllib3.responserZ
requests_mockr	r
�	frozensetr(r'rJrKrr/�objectr0r8r>r9rMrNrPrrrr�<module>
s(	: