Your IP : 216.73.216.213


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__/adapter.cpython-37.pyc

B

�ˀX>�@sjdZddlZddlmZddlmZddlmZmZddlm	Z	m
Z
e�ZGdd	�d	e	�Z
d
Zdd�ZdS)
z7
betamax.adapter.

==============

adapter for betamax
�N�)�cassette)�BetamaxError)�datetime�	timedelta)�BaseAdapter�HTTPAdaptercs\eZdZdZ�fdd�Zdd�Zdd�Zdd	�Zd
d�Zddd�Z	ddd�Z
dd�Z�ZS)�BetamaxAdapterz�This object is an implementation detail of the library.

    It is not meant to be a public API and is not exported as such.

    csDtt|���d|_d|_|�di�|_tf|�|_d|_	i|_
dS)N�old_adapters)�superr	�__init__r�
cassette_name�popr
r�http_adapter�	serialize�options)�self�kwargs)�	__class__��@/opt/alt/python37/lib/python3.7/site-packages/betamax/adapter.pyrszBetamaxAdapter.__init__cCs|jrtj�|j�rdSdS)zlCheck if cassette exists on file system.

        :returns: bool -- True if exists, False otherwise
        TF)r
�os�path�exists)rrrr�cassette_exists"szBetamaxAdapter.cassette_existscCs|j��dS)z&Propagate close to underlying adapter.N)r�close)rrrrr+szBetamaxAdapter.closecCs|jr|j��d|_dS)z Eject currently loaded cassette.N)rZeject)rrrr�eject_cassette/s
zBetamaxAdapter.eject_cassettecCs8||_||_|j�|���|j�di�}i}tjj}|j�d|d�}|j�d�|d<|j�d�|d<|j�d�|d<x*t	|���D]\}}	|	dkr�|�
|�q�Wtj||f||j�d�d	�|��|_d|jkr�|jd|j_|jj�|�t
j}
|j�d
��rt
|jd
�}
t��}|
||jjk�r4|j��dS)a%Load cassette.

        Loads a previously serialized http response as a cassette

        :param str cassette_name: (required), name of cassette
        :param str serialize: (required), type of serialization i.e 'json'
        :options dict options: (required), options for cassette
        �placeholders�match_requests_onZpreserve_exact_body_bytesZallow_playback_repeats�record�record_modeN�cassette_library_dir)rr!�re_record_interval)r
rr�update�items�getrZCassetteZdefault_cassette_options�listrr �
match_optionsr�maxr�utcnowZearliest_recorded_date�clear)rr
rrrZcassette_optionsZdefault_optionsr�option�valuer"�nowrrr�
load_cassette5s:	



zBetamaxAdapter.load_cassetteFNTc
Csjd}|j}|std��|jr&|�|�}|sF|��rF|�||||||�}|sXtt||���|��}	||	_|	S)zcSend request.

        :param request request: request
        :returns: A Response object
        Nz#No cassette was specified or found.)	rrZinteractionsZ
find_matchZis_recording�send_and_record�unhandled_request_messageZas_responseZ
connection)
r�request�stream�timeout�verify�cert�proxiesZinteractionZcurrent_cassetteZresprrr�sendms
zBetamaxAdapter.sendc	Cs0|�|j�}|j|d||||d�}|j�||�S)ajSend request and record response.

        The response will be serialized and saved to a
        cassette which can be replayed in the future.

        :param request request: request
        :param bool stream: (optional) defer download until content is accessed
        :param float timeout: (optional) time to wait for a response
        :param bool verify: (optional) verify SSL certificate
        :param str cert: (optional) path to SSL client
        :param proxies dict: (optional) mapping protocol to URL of the proxy
        :return: Interaction
        :rtype: class:`betamax.cassette.Interaction`
        T)r2r3r4r5r6)�find_adapter�urlr7rZsave_interaction)	rr1r2r3r4r5r6�adapter�responserrrr/�s

zBetamaxAdapter.send_and_recordcCs.x(|j��D]\}}|���|�r|SqWdS)z�Find adapter.

        Searches for an existing adapter where the url and prefix match.

        :param url str: (required) url of the adapter
        :returns: betamax adapter
        N)r
r$�lower�
startswith)rr9�prefixr:rrrr8�szBetamaxAdapter.find_adapter)FNTNN)FNTNN)
�__name__�
__module__�__qualname__�__doc__rrrrr.r7r/r8�
__classcell__rr)rrr	s		8

r	z�A request was made that could not be handled.

A request was made to {url} that could not be found in {cassette_file_path}.

The settings on the cassette are:

    - record_mode: {cassette_record_mode}
    - match_options {cassette_match_options}.
cCstj|j|j|j|jd�S)z*Generate exception for unhandled requests.)r9Zcassette_file_pathZcassette_record_modeZcassette_match_options)�UNHANDLED_REQUEST_EXCEPTION�formatr9r
r r')r1rrrrr0�sr0)rBr�r�
exceptionsrrrZrequests.adaptersrr�objectZ	_SENTINELr	rDr0rrrr�<module>s(