# Path: greenqueue/models.py
# class TaskResult(models.Model):
#     uuid = models.CharField(max_length=100, unique=True, db_index=True)
#     result = models.TextField(blank=True, null=True, default=None)
# 
# Path: greenqueue/exceptions.py
# class ResultDoesNotExist(Exception):
#     pass
# 
# Path: greenqueue/storage/backends/base.py
# class BaseStorageBackend(object):
#     __metaclass__ = Singleton
#     _sleep = None
# 
#     def get(self, uuid, default=None):
#         raise NotImplementedError
# 
#     def save(self, uuid, result):
#         raise NotImplementedError
# 
#     def wait(self, uuid, timeout=None, interval=0.5):
#         time_elapsed = 0.0
#         result = None
# 
#         while True: 
#             try:
#                 result = self.get(uuid)
#                 break
#             except ResultDoesNotExist:
#                 pass
#             
#             import time
#             time.sleep(interval)
#             time_elapsed += interval
# 
#             if timeout and time_elapsed >= timeout:
#                 raise TimeoutError("The operation timed out.")
# 
#         return result
# 
# Path: greenqueue/settings.py
# GREENQUEUE_BIND_ADDRESS = getattr(settings, 'GREENQUEUE_BIND_ADDRESS', 'ipc:///tmp/greenqueue.sock')
# GREENQUEUE_TASK_MODULES = getattr(settings, 'GREENQUEUE_TASK_MODULES', [])
# GREENQUEUE_BACKEND = getattr(settings, 'GREENQUEUE_BACKEND', 'greenqueue.backends.sync.SyncService')
# GREENQUEUE_WORKER_MANAGER = getattr(settings, 'GREENQUEUE_WORKER_MANAGER', 'greenqueue.worker.sync.SyncManager')
# GREENQUEUE_RESULTS_BACKEND = getattr(settings, "GREENQUEUE_RESULTS_BACKEND", "greenqueue.storage.backends.model.StorageBackend")
# GREENQUEUE_IGNORE_RESULT = getattr(settings, "GREENQUEUE_IGNORE_RESULT", True)
# GREENQUEUE_BACKEND_POOLSIZE = getattr(settings, 'GREENQUEUE_BACKEND_POOLSIZE', 2)
# GREENQUEUE_BACKEND_TASKBUFF = getattr(settings, 'GREENQUEUE_BACKEND_TASKBUFF', 5)
# GREENQUEUE_RABBITMQ_USERNAME = getattr(settings, 'GREENQUEUE_RABBITMQ_USERNAME', None)
# GREENQUEUE_RABBITMQ_PASSWORD = getattr(settings, 'GREENQUEUE_RABBITMQ_PASSWORD', None)
# GREENQUEUE_RABBITMQ_HOSTNAME = getattr(settings, 'GREENQUEUE_RABBITMQ_HOSTNAME', 'localhost')
# GREENQUEUE_RABBITMQ_PORT = getattr(settings, 'GREENQUEUE_RABBITMQ_PORT', 5672)
# GREENQUEUE_RABBITMQ_VHOST = getattr(settings, 'GREENQUEUE_RABBITMQ_VHOST', '/')
# GREENQUEUE_RABBITMQ_QUEUE = getattr(settings, 'GREENQUEUE_RABBITMQ_QUEUE', 'greenqueue')
# GREENQUEUE_RABBITMQ_ROUTING_KEY = getattr(settings, 'GREENQUEUE_RABBITMQ_ROUTING_KEY', GREENQUEUE_RABBITMQ_QUEUE)
# GREENQUEUE_RABBITMQ_EXCHANGE = getattr(settings, 'GREENQUEUE_RABBITMQ_EXCHANGE', '')


from django.db import transaction
from greenqueue.models import TaskResult
from greenqueue.exceptions import ResultDoesNotExist
from .base import BaseStorageBackend
from ... import settings
    import cPickle as pickle
    import pickle
import base64
# -*- coding: utf-8 -*-




try:
except ImportError:


class StorageBackend(BaseStorageBackend):
    def get(self, uuid, default=None):
        try:
            result_obj = TaskResult.objects.get(uuid=uuid)

# Path: greenqueue/models.py
# class TaskResult(models.Model):
#     uuid = models.CharField(max_length=100, unique=True, db_index=True)
#     result = models.TextField(blank=True, null=True, default=None)
# 
# Path: greenqueue/exceptions.py
# class ResultDoesNotExist(Exception):
#     pass
# 
# Path: greenqueue/storage/backends/base.py
# class BaseStorageBackend(object):
#     __metaclass__ = Singleton
#     _sleep = None
# 
#     def get(self, uuid, default=None):
#         raise NotImplementedError
# 
#     def save(self, uuid, result):
#         raise NotImplementedError
# 
#     def wait(self, uuid, timeout=None, interval=0.5):
#         time_elapsed = 0.0
#         result = None
# 
#         while True: 
#             try:
#                 result = self.get(uuid)
#                 break
#             except ResultDoesNotExist:
#                 pass
#             
#             import time
#             time.sleep(interval)
#             time_elapsed += interval
# 
#             if timeout and time_elapsed >= timeout:
#                 raise TimeoutError("The operation timed out.")
# 
#         return result
# 
# Path: greenqueue/settings.py
# GREENQUEUE_BIND_ADDRESS = getattr(settings, 'GREENQUEUE_BIND_ADDRESS', 'ipc:///tmp/greenqueue.sock')
# GREENQUEUE_TASK_MODULES = getattr(settings, 'GREENQUEUE_TASK_MODULES', [])
# GREENQUEUE_BACKEND = getattr(settings, 'GREENQUEUE_BACKEND', 'greenqueue.backends.sync.SyncService')
# GREENQUEUE_WORKER_MANAGER = getattr(settings, 'GREENQUEUE_WORKER_MANAGER', 'greenqueue.worker.sync.SyncManager')
# GREENQUEUE_RESULTS_BACKEND = getattr(settings, "GREENQUEUE_RESULTS_BACKEND", "greenqueue.storage.backends.model.StorageBackend")
# GREENQUEUE_IGNORE_RESULT = getattr(settings, "GREENQUEUE_IGNORE_RESULT", True)
# GREENQUEUE_BACKEND_POOLSIZE = getattr(settings, 'GREENQUEUE_BACKEND_POOLSIZE', 2)
# GREENQUEUE_BACKEND_TASKBUFF = getattr(settings, 'GREENQUEUE_BACKEND_TASKBUFF', 5)
# GREENQUEUE_RABBITMQ_USERNAME = getattr(settings, 'GREENQUEUE_RABBITMQ_USERNAME', None)
# GREENQUEUE_RABBITMQ_PASSWORD = getattr(settings, 'GREENQUEUE_RABBITMQ_PASSWORD', None)
# GREENQUEUE_RABBITMQ_HOSTNAME = getattr(settings, 'GREENQUEUE_RABBITMQ_HOSTNAME', 'localhost')
# GREENQUEUE_RABBITMQ_PORT = getattr(settings, 'GREENQUEUE_RABBITMQ_PORT', 5672)
# GREENQUEUE_RABBITMQ_VHOST = getattr(settings, 'GREENQUEUE_RABBITMQ_VHOST', '/')
# GREENQUEUE_RABBITMQ_QUEUE = getattr(settings, 'GREENQUEUE_RABBITMQ_QUEUE', 'greenqueue')
# GREENQUEUE_RABBITMQ_ROUTING_KEY = getattr(settings, 'GREENQUEUE_RABBITMQ_ROUTING_KEY', GREENQUEUE_RABBITMQ_QUEUE)
# GREENQUEUE_RABBITMQ_EXCHANGE = getattr(settings, 'GREENQUEUE_RABBITMQ_EXCHANGE', '')


# Path: greenqueue/storage/backends/model.py
from django.db import transaction
from greenqueue.models import TaskResult
from greenqueue.exceptions import ResultDoesNotExist
from .base import BaseStorageBackend
from ... import settings
    import cPickle as pickle
    import pickle
import base64

# -*- coding: utf-8 -*-




try:
except ImportError:


class StorageBackend(BaseStorageBackend):
    def get(self, uuid, default=None):
        try:
            result_obj = TaskResult.objects.get(uuid=uuid)

        except TaskResult.DoesNotExist: