# Path: aredis/utils.py
# def b(x):
#     return x.encode('latin-1') if not isinstance(x, bytes) else x
# 
# Path: aredis/exceptions.py
# class SerializeError(CacheError):
#     pass
# 
# class CompressError(CacheError):
#     pass


import hashlib
import time
import zlib
    import ujson as json
    import json
from aredis.utils import b
from aredis.exceptions import (SerializeError,
                               CompressError)
            raise CompressError('Content can not be decompressed.')


class Serializer:
    """
    Uses json to serialize and deserialize cache to str. You may implement
    your own Serializer implemting `serialize` and `deserialize` methods.
    """

    def __init__(self, encoding='utf-8'):
        self.encoding = encoding

    def _trans_type(self, content):
        if isinstance(content, bytes):
            content = content.decode(self.encoding)
        if not isinstance(content, str):
            raise TypeError('Wrong data type({}) to compress'.format(type(content)))
        return content

    def serialize(self, content):
        try:
            return json.dumps(content)
        except Exception as exc:
            raise SerializeError('Content can not be serialized.')

    def deserialize(self, content):
        content = self._trans_type(content)
        try:
            return json.loads(content)
        except Exception as exc:

# Path: aredis/utils.py
# def b(x):
#     return x.encode('latin-1') if not isinstance(x, bytes) else x
# 
# Path: aredis/exceptions.py
# class SerializeError(CacheError):
#     pass
# 
# class CompressError(CacheError):
#     pass


# Path: aredis/cache.py
import hashlib
import time
import zlib
    import ujson as json
    import json
from aredis.utils import b
from aredis.exceptions import (SerializeError,
                               CompressError)

            raise CompressError('Content can not be decompressed.')


class Serializer:
    """
    Uses json to serialize and deserialize cache to str. You may implement
    your own Serializer implemting `serialize` and `deserialize` methods.
    """

    def __init__(self, encoding='utf-8'):
        self.encoding = encoding

    def _trans_type(self, content):
        if isinstance(content, bytes):
            content = content.decode(self.encoding)
        if not isinstance(content, str):
            raise TypeError('Wrong data type({}) to compress'.format(type(content)))
        return content

    def serialize(self, content):
        try:
            return json.dumps(content)
        except Exception as exc:
            raise SerializeError('Content can not be serialized.')

    def deserialize(self, content):
        content = self._trans_type(content)
        try:
            return json.loads(content)
        except Exception as exc:

            raise SerializeError('Content can not be deserialized.')