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

B

�ˀX��@sTddlmZmZddlmZddlmZddlmZddl	m
Z
Gdd�de�ZdS)	�)�matchers�serializers)�BetamaxAdapter)�Cassette)�
Configuration)�Optionsc@sveZdZdZdifdd�Zdd�Zdd�Zed	d
��Ze	dd��Z
ed
d��Zedd��Zdd�Z
dd�Zdd�ZdS)�BetamaxaThis object contains the main API of the request-vcr library.

    This object is entirely a context manager so all you have to do is:

    .. code::

        s = requests.Session()
        with Betamax(s) as vcr:
            vcr.use_cassette('example')
            r = s.get('https://httpbin.org/get')

    Or more concisely, you can do:

    .. code::

        s = requests.Session()
        with Betamax(s).use_cassette('example') as vcr:
            r = s.get('https://httpbin.org/get')

    This object allows for the user to specify the cassette library directory
    and default cassette options.

    .. code::

        s = requests.Session()
        with Betamax(s, cassette_library_dir='tests/cassettes') as vcr:
            vcr.use_cassette('example')
            r = s.get('https://httpbin.org/get')

        with Betamax(s, default_cassette_options={
                're_record_interval': 1000
                }) as vcr:
            vcr.use_cassette('example')
            r = s.get('https://httpbin.org/get')

    NcCsJ||_|j��|_t|jd�|_t�|_|jj�	|p6i�|rF||j_
dS)N)Zold_adapters)�sessionZadapters�copy�
http_adaptersr�betamax_adapterr�config�default_cassette_options�update�cassette_library_dir)�selfr	rr�r�A/opt/alt/python37/lib/python3.7/site-packages/betamax/recorder.py�__init__0s
zBetamax.__init__cCs|��|S)N)�start)rrrr�	__enter__CszBetamax.__enter__cGs|��t|�rdSdS)NF)�stop�any)rZex_argsrrr�__exit__GszBetamax.__exit__cCst�S)aAHelp to configure the library as a whole.

        .. code::

            with Betamax.configure() as config:
                config.cassette_library_dir = 'tests/cassettes/'
                config.default_cassette_options['match_options'] = [
                    'method', 'uri', 'headers'
                    ]
        )rrrrr�	configurePszBetamax.configurecCs|jjS)zwReturn the cassette that is currently in use.

        :returns: :class:`Cassette <betamax.cassette.Cassette>`
        )r�cassette)rrrr�current_cassette^szBetamax.current_cassettecCs|�tj|j<dS)z�Register a new request matcher.

        :param matcher_class: (required), this must sub-class
            :class:`BaseMatcher <betamax.matchers.BaseMatcher>`
        N)rZmatcher_registry�name)Z
matcher_classrrr�register_request_matcherfsz Betamax.register_request_matchercCs|j}|�tj|<dS)z�Register a new serializer.

        :param matcher_class: (required), this must sub-class
            :class:`BaseSerializer <betamax.serializers.BaseSerializer>`
        N)rrZserializer_registry)Zserializer_classrrrr�register_serializeroszBetamax.register_serializercCs$x|jD]}|j�||j�qWdS)z*Start recording or replaying interactions.N)rr	�mountr)r�krrrrzsz
Betamax.startcCs>|j��|j��x$|j��D]\}}|j�||�q WdS)z)Stop recording or replaying interactions.N)rZeject_cassette�closer�itemsr	r )rr!�vrrrr�s

zBetamax.stopcKs^t|�}|dp|d}|jj|d<t�|jj|||d�}|rR|j�|||�ntd��|S)a�Tell Betamax which cassette you wish to use for the context.

        :param str cassette_name: relative name, without the serialization
            format, of the cassette you wish Betamax would use
        :param str serialize_with: the format you want Betamax to serialize
            the cassette with
        :param str serialize: DEPRECATED the format you want Betamax to
            serialize the request and response data to and from
        �	serializeZserialize_withr�recordz4Cassette must have a valid name and may not be None.)rr
rrZ
can_be_loadedrZ
load_cassette�
ValueError)rZ
cassette_name�kwargsr%Zcan_loadrrr�use_cassette�s


zBetamax.use_cassette)�__name__�
__module__�__qualname__�__doc__rrr�staticmethodr�propertyrrrrrr)rrrrr	s%		
rN)
�rrZadapterrrrrr�optionsr�objectrrrrr�<module>s