# Path: huacaya/storage/base.py
# class BucketBase(object):
#     def drop(self):
#         raise NotImplementedError
# 
#     def put(self, entity):
#         raise NotImplementedError
# 
#     def get(self, stub):
#         raise NotImplementedError
# 
#     def delete(self, stub):
#         raise NotImplementedError
# 
#     def update(self, entity):
#         raise NotImplementedError
# 
#     def __contains__(self, item):
#         raise NotImplementedError
# 
#     def __getitem__(self, item):
#         return self.get(item)
# 
# class StorageBase(object):
#     def create_bucket(self, name, index=()):
#         raise NotImplementedError
# 
#     def get_bucket(self, name):
#         raise NotImplementedError
# 
#     def drop(self, bucket):
#         raise NotImplementedError
# 
#     def __contains__(self, item):
#         raise NotImplementedError
# 
#     def __getitem__(self, item):
#         return self.get_bucket(item)


from .base import BucketBase, StorageBase
from time import mktime
import json
import datetime
import base64
import sqlite3


_singleton_storage = None

class EnhancedJSONEncoder(json.JSONEncoder):
    def default(self, obj):
        if isinstance(obj, datetime.datetime):
            return {'__utctimestamp__': mktime(obj.timetuple())}
        if isinstance(obj, bytes):
            return {'__bytes__': base64.b64encode(obj).decode('ascii')}
        else:
            return super(self.__class__, self).default(obj)

class EnhancedJSONDecoder(json.JSONDecoder):
    def __init__(self, *args, **kwargs):
        json.JSONDecoder.__init__(self, *args, object_hook=self.object_hook, **kwargs)
    def object_hook(self, dct):
        if '__utctimestamp__' in dct:
            return datetime.datetime.fromtimestamp(dct['__utctimestamp__'])
        elif '__bytes__' in dct:
            return base64.b64decode(dct['__bytes__'].encode('ascii'))
        else:
            return dct

def _dumps(dct):
    return json.dumps(dct, cls=EnhancedJSONEncoder)

def _loads(raw):
    return json.loads(raw, cls=EnhancedJSONDecoder)


# Path: huacaya/storage/base.py
# class BucketBase(object):
#     def drop(self):
#         raise NotImplementedError
# 
#     def put(self, entity):
#         raise NotImplementedError
# 
#     def get(self, stub):
#         raise NotImplementedError
# 
#     def delete(self, stub):
#         raise NotImplementedError
# 
#     def update(self, entity):
#         raise NotImplementedError
# 
#     def __contains__(self, item):
#         raise NotImplementedError
# 
#     def __getitem__(self, item):
#         return self.get(item)
# 
# class StorageBase(object):
#     def create_bucket(self, name, index=()):
#         raise NotImplementedError
# 
#     def get_bucket(self, name):
#         raise NotImplementedError
# 
#     def drop(self, bucket):
#         raise NotImplementedError
# 
#     def __contains__(self, item):
#         raise NotImplementedError
# 
#     def __getitem__(self, item):
#         return self.get_bucket(item)


# Path: huacaya/storage/mock.py
from .base import BucketBase, StorageBase
from time import mktime
import json
import datetime
import base64
import sqlite3



_singleton_storage = None

class EnhancedJSONEncoder(json.JSONEncoder):
    def default(self, obj):
        if isinstance(obj, datetime.datetime):
            return {'__utctimestamp__': mktime(obj.timetuple())}
        if isinstance(obj, bytes):
            return {'__bytes__': base64.b64encode(obj).decode('ascii')}
        else:
            return super(self.__class__, self).default(obj)

class EnhancedJSONDecoder(json.JSONDecoder):
    def __init__(self, *args, **kwargs):
        json.JSONDecoder.__init__(self, *args, object_hook=self.object_hook, **kwargs)
    def object_hook(self, dct):
        if '__utctimestamp__' in dct:
            return datetime.datetime.fromtimestamp(dct['__utctimestamp__'])
        elif '__bytes__' in dct:
            return base64.b64decode(dct['__bytes__'].encode('ascii'))
        else:
            return dct

def _dumps(dct):
    return json.dumps(dct, cls=EnhancedJSONEncoder)

def _loads(raw):
    return json.loads(raw, cls=EnhancedJSONDecoder)


class MockBucket(BucketBase):