# Path: golem/core/entity_value.py
# class EntityValue:
#     """
#     This class holds the value of a single entity in context.
#     """
# 
#     def __init__(self, context, name, value=None, raw=None):
#         self.name = name
#         self.raw = raw or dict()  # type: dict
#         self.value = value or self.raw.get("value")
#         self.timestamp = time.time()
#         self.counter = context.counter
#         self.state_set = context.get_state_name() or ""
# 
#     # Methods to access the raw data returned by parsers
# 
#     def get(self, key, default=None):
#         return self.raw.get(key, default)
# 
#     def __contains__(self, item):
#         return self.raw.__contains__(item)
# 
#     def __getitem__(self, item):
#         return self.raw.__getitem__(item)
# 
#     # Common methods to access values
# 
#     def __str__(self):
#         return self.value
# 
#     def __repr__(self):
#         return "EntityValue:" + str(self.value)


from base64 import b64encode, b64decode
from golem.core.entity_value import EntityValue
    from golem.core.entities import Entity
    from datetime import datetime
import dateutil.parser
import pickle




# FIXME just pickle the whole thing instead of serializing

def json_deserialize(obj):
    #print('Deserializing:', obj)
    if obj.get('__type__') == 'datetime':
        return dateutil.parser.parse(obj.get('value'))
    elif obj.get('__type__') == 'entity':
        bytearr = str.encode(obj.get("__data__"))
        return pickle.loads(b64decode(bytearr))
    return obj


def json_serialize(obj):
    # from golem.core.entities import Entity
    if isinstance(obj, datetime):
        return {'__type__':'datetime', 'value': obj.isoformat()}

# Path: golem/core/entity_value.py
# class EntityValue:
#     """
#     This class holds the value of a single entity in context.
#     """
# 
#     def __init__(self, context, name, value=None, raw=None):
#         self.name = name
#         self.raw = raw or dict()  # type: dict
#         self.value = value or self.raw.get("value")
#         self.timestamp = time.time()
#         self.counter = context.counter
#         self.state_set = context.get_state_name() or ""
# 
#     # Methods to access the raw data returned by parsers
# 
#     def get(self, key, default=None):
#         return self.raw.get(key, default)
# 
#     def __contains__(self, item):
#         return self.raw.__contains__(item)
# 
#     def __getitem__(self, item):
#         return self.raw.__getitem__(item)
# 
#     # Common methods to access values
# 
#     def __str__(self):
#         return self.value
# 
#     def __repr__(self):
#         return "EntityValue:" + str(self.value)


# Path: golem/core/serialize.py
from base64 import b64encode, b64decode
from golem.core.entity_value import EntityValue
    from golem.core.entities import Entity
    from datetime import datetime
import dateutil.parser
import pickle





# FIXME just pickle the whole thing instead of serializing

def json_deserialize(obj):
    #print('Deserializing:', obj)
    if obj.get('__type__') == 'datetime':
        return dateutil.parser.parse(obj.get('value'))
    elif obj.get('__type__') == 'entity':
        bytearr = str.encode(obj.get("__data__"))
        return pickle.loads(b64decode(bytearr))
    return obj


def json_serialize(obj):
    # from golem.core.entities import Entity
    if isinstance(obj, datetime):
        return {'__type__':'datetime', 'value': obj.isoformat()}

    elif isinstance(obj, EntityValue):