Your IP : 216.73.216.196


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

B

�ˀX%�@sddlmZddlmZddlmZmZddlmZddlm	Z	ddl
mZddlm
Z
ydd	lmZWn ek
r�dd	lmZYnXdd
lZdd
lZdd
lZd!dd�Zd"d
d�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Ze�Z dd �Z!d
S)#�)�MockHTTPResponse�)�datetime)�PreparedRequest�Response)�HTTPResponse)�CaseInsensitiveDict)�_codes)�RequestsCookieJar)�HTTPHeaderDictNcCst|d�r|�|pdd�}|S)N�decodezutf-8�replace)�hasattrr)�content�encoding�r�=/opt/alt/python37/lib/python3.7/site-packages/betamax/util.py�coerce_contents
rcCs"t|d�r|�|pd�}t�|�S)N�encodezutf-8)rr�io�BytesIO)�stringrrrr�body_ios
rcCst|t�r|dS|S)Nr)�
isinstance�list)�valuerrr�	from_lists
rcCs�t|dt|dd��}t|d�r&|��}|s.d}|sDd|j�dd�kr~tjdkrjt|d	�rj|�|d
pfd�}t�	|��
�|d<nt||d
�|d
<dS)a:Simple function which takes a response or request and coerces the body.

    This function adds either ``'string'`` or ``'base64_string'`` to
    ``body_dict``. If ``preserve_exact_body_bytes`` is ``True`` then it
    encodes the body as a base64 string and saves it like that. Otherwise,
    it saves the plain string.

    :param r: This is either a PreparedRequest instance or a Response
        instance.
    :param preserve_exact_body_bytes bool: Either True or False.
    :param body_dict dict: A dictionary already containing the encoding to be
        used.
    �raw�bodyN�read��gzipzContent-Encoding)�rrrzutf-8�
base64_stringr)�getattrrr�headers�get�sys�version_infor�base64�	b64encoderr)�r�preserve_exact_body_bytesZ	body_dictrrrr�add_body%s
r-cCs>|j}ddi}t|||�|tdd�|��D��|j|jd�S)Nrzutf-8css"|]\}}t|d�|gfVqdS)zutf-8N)r)�.0�k�vrrr�	<genexpr>Ksz-serialize_prepared_request.<locals>.<genexpr>)rr%�method�uri)r%r-�dict�itemsr2�url)�requestr,r%rrrr�serialize_prepared_requestDsr8cCs�t�}t�|_|d}t|t�rH|�d�}|pBt�|�dd����|_	n||_	dd�|d�
�D�}t|�|_|d|_
|d	|_|S)
Nrrr#r cSsg|]\}}|t|�f�qSr)r)r.r/r0rrr�
<listcomp>\sz0deserialize_prepared_request.<locals>.<listcomp>r%r2r3)rr
Z_cookiesrr4r&r)�	b64decoderrr5rr%r2r6)�
serialized�prZ
original_body�hrrr�deserialize_prepared_requestRs




r>cCs`d|ji}t|||�t|jj�}i}x|��D]}|�|�||<q0W|||j|jd�|j	d�S)Nr)�code�message)rr%�statusr6)
rr-rrr%�keysZgetlist�status_code�reasonr6)�responser,rZ
header_mapr%�header_namerrr�serialize_responsecs
rGcCs�t�}|dd|_t�}xJ|d��D]:\}}t|t�rVx&|D]}|�||�q@Wq(|�||�q(Wt|�|_|�	dd�|_
d|kr�|dd|_|dd|_n|d	|_t
|jd
��|_t|||�|S)Nrrr%r6r rAr?r@rCr)rrrr5rr�addrr%r&r6rCrDr	�upper�add_urllib3_response)r;r+Zheader_dictrFZheader_listZheader_valuerrr�deserialize_responsess"



rKcCsdd|dkr*t�t�|dd����}ntf|d�}t||j|j|dt	|�d�}d|_
||_dS)Nr#rF)rArDr%Zpreload_contentZoriginal_response)rrr)r:rrrrCrDrZchunkedr)r;rEr%rr=rrrrJ�srJcCs@t����}y|�d�}Wntk
r.|SX|d|�SdS)N�.)r�utcnow�	isoformat�rindex�
ValueError)Zstamp�irrr�	timestamp�srRcCs"|�|t�}|tkr|�|�}|S)N)r&�	_SENTINEL)�option�kwargs�defaultsrrrr�_option_from�s
rW)N)N)"Z
mock_responserrZrequests.modelsrrZrequests.packages.urllib3rZrequests.structuresrZrequests.status_codesr	Zrequests.cookiesr
Z&requests.packages.urllib3._collectionsr�ImportErrorr%r)rr'rrrr-r8r>rGrKrJrR�objectrSrWrrrr�<module>s2