/usr/lib/python2.7/dist-packages/betamax/serializers/base.py is in python-betamax 0.5.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | # -*- coding: utf-8 -*-
NOT_IMPLEMENTED_ERROR_MSG = ('This method must be implemented by classes'
' inheriting from BaseSerializer.')
class BaseSerializer(object):
"""
Base Serializer class that provides an interface for other serializers.
Usage:
.. code-block:: python
from betamax import Betamax, BaseSerializer
class MySerializer(BaseSerializer):
name = 'my'
@staticmethod
def generate_cassette_name(cassette_library_dir, cassette_name):
# Generate a string that will give the relative path of a
# cassette
def serialize(self, cassette_data):
# Take a dictionary and convert it to whatever
def deserialize(self):
# Uses a cassette file to return a dictionary with the
# cassette information
Betamax.register_serializer(MySerializer)
The last line is absolutely necessary.
"""
name = None
@staticmethod
def generate_cassette_name(cassette_library_dir, cassette_name):
raise NotImplementedError(NOT_IMPLEMENTED_ERROR_MSG)
def __init__(self):
if not self.name:
raise ValueError("Serializer's name attribute must be a string"
" value, not None.")
self.on_init()
def on_init(self):
"""Method to implement if you wish something to happen in ``__init__``.
The return value is not checked and this is called at the end of
``__init__``. It is meant to provide the matcher author a way to
perform things during initialization of the instance that would
otherwise require them to override ``BaseSerializer.__init__``.
"""
return None
def serialize(self, cassette_data):
"""A method that must be implemented by the Serializer author.
:param dict cassette_data: A dictionary with two keys:
``http_interactions``, ``recorded_with``.
:returns: Serialized data as a string.
"""
raise NotImplementedError(NOT_IMPLEMENTED_ERROR_MSG)
def deserialize(self, cassette_data):
"""A method that must be implemented by the Serializer author.
The return value is extremely important. If it is not empty, the
dictionary returned must have the following structure::
{
'http_interactions': [{
# Interaction
},
{
# Interaction
}],
'recorded_with': 'name of recorder'
}
:params str cassette_data: The data serialized as a string which needs
to be deserialized.
:returns: dictionary
"""
raise NotImplementedError(NOT_IMPLEMENTED_ERROR_MSG)
|