Your IP : 216.73.216.213


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

B

�ˀX�
�@s4ddlmZddlmZddlZGdd�de�ZdS)�)�BaseSerializer�)�MissingDirectoryErrorNc@sJeZdZdZddd�Zdd�Zedd��Zed	d
��Z	dd�Z
d
d�ZdS)�SerializerProxyag
    This is an internal implementation detail of the betamax library.

    No users implementing a serializer should be using this. Developers
    working on betamax need only understand that this handles the logic
    surrounding whether a cassette should be updated, overwritten, or created.

    It provides one consistent way for betamax to be confident in how it
    serializes the data it receives. It allows authors of Serializer classes
    to not have to duplicate how files are handled. It delegates the
    responsibility of actually serializing the data to those classes and
    handles the rest.

    FcCs||_||_||_dS)N)�proxied_serializer�allow_serialization�
cassette_path)�self�
serializerrr�r�J/opt/alt/python37/lib/python3.7/site-packages/betamax/serializers/proxy.py�__init__szSerializerProxy.__init__cCsVtj�|j�\}}|dks4tj�|�s4td�|���tj�|j�sRt|jd��	�dS)N�zDConfigured cassette directory '{0}' does not exist - try creating itzw+)
�os�path�splitr�isdirr�format�exists�open�close)r	�	directory�_rrr�_ensure_path_existssz#SerializerProxy._ensure_path_existscCsDddlm}|�|�}|dkr,td�|���|�|||�}|||�S)Nr)�serializer_registryz No serializer registered for {0})rr�get�
ValueErrorr�generate_cassette_name)�clsZserialize_with�cassette_library_dir�
cassette_namerr
rrrr�find(s

zSerializerProxy.findcCs|�||�S)N)r)r
rr rrrr6sz&SerializerProxy.generate_cassette_namec	Cs@|js
dS|��t|jd��}|�|j�|��WdQRXdS)N�w)rrrr�writer�	serialize)r	Z
cassette_data�fdrrrr$=s
zSerializerProxy.serializec	Cs6|��i}t|j��}|j�|���}WdQRX|S)N)rrrr�deserialize�read)r	�datar%rrrr&Fs
zSerializerProxy.deserializeN)F)�__name__�
__module__�__qualname__�__doc__r
r�classmethodr!�staticmethodrr$r&rrrrrs

	r)�baserZbetamax.exceptionsrrrrrrr�<module>s