Your IP : 216.73.216.213
B
�ˀX�
� @ s4 d dl mZ ddlmZ ddlZG dd� de�ZdS )� )�BaseSerializer� )�MissingDirectoryErrorNc @ sJ e Zd ZdZddd�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.
Fc C s || _ || _|| _d S )N)�proxied_serializer�allow_serialization�
cassette_path)�self�
serializerr r � r �J/opt/alt/python37/lib/python3.7/site-packages/betamax/serializers/proxy.py�__init__ s zSerializerProxy.__init__c C sV t j�| j�\}}|dks4t j�|�s4td�|���t j�| j�sRt| jd�� � d S )N� zDConfigured cassette directory '{0}' does not exist - try creating itzw+)
�os�path�splitr �isdirr �format�exists�open�close)r � directory�_r r r �_ensure_path_exists s z#SerializerProxy._ensure_path_existsc C sD ddl m} |�|�}|d kr,td�|���| �|||�}| ||�S )Nr )�serializer_registryz No serializer registered for {0})r r �get�
ValueErrorr �generate_cassette_name)�clsZserialize_with�cassette_library_dir�
cassette_namer r
r r r r �find( s
zSerializerProxy.findc C s | � ||�S )N)r )r
r r r r r r 6 s z&SerializerProxy.generate_cassette_namec C s@ | j s
d S | �� t| jd��}|�| j�|�� W d Q R X d S )N�w)r r r r �writer � serialize)r Z
cassette_data�fdr r r r$ = s
zSerializerProxy.serializec C s6 | � � i }t| j��}| j�|�� �}W d Q R X |S )N)r r r r �deserialize�read)r �datar% r r r r&