# Path: toto/workerconnection.py
# class WorkerConnection(object):
#   '''Use a ``WorkerConnection`` to make RPCs to the remote worker service(s) or worker/router specified by ``address``.
#      ``address`` may be either an enumerable of address strings or a string of comma separated addresses. RPC retries
#      and timeouts will happen by at most every ``abs(timeout)`` seconds when a periodic callback runs through all active
#      messages and checks for prolonged requests. This is also the default timeout for any new calls. ``timeout`` must not be
#      ``0``.
# 
#      Optionally pass any object or module with ``compress`` and ``decompress`` methods as the ``compression`` parameter to
#      compress messages. The module must implement the same algorithm used on the worker service. By default, messages are not
#      compressed.
# 
#      Optionally pass any object or module with ``dumps`` and ``loads`` methods that convert an ``object`` to and from a
#      ``str`` to replace the default ``cPickle`` serialization with a protocol of your choice.
# 
#      Use ``auto_retry`` to specify whether or not messages should be retried by default. Retrying messages can cause substantial
#      congestion in your worker service. Use with caution.
#   '''
# 
#   def __getattr__(self, path):
#     return WorkerInvocation(path, self)
#   
#   def log_error(self, error):
#     logging.error(repr(error))
# 
#   def enable_traceback_logging(self):
#     from new import instancemethod
#     from traceback import format_exc
#     def log_error(self, e):
#       logging.error(format_exc())
#     self.log_error = instancemethod(log_error, self)
# 
#   @classmethod
#   def instance(cls):
#     '''Returns the default instance of ``WorkerConnection`` as configured by the options prefixed
#       with ``worker_``, instantiating it if necessary. Import the ``workerconnection`` module within
#       your ``TotoService`` and run it with ``--help`` to see all available options.
#     '''
#     if not hasattr(cls, '_instance'):
#       if options.worker_transport == 'http':
#         from toto.httpworkerconnection import HTTPWorkerConnection
#         cls._instance = HTTPWorkerConnection.instance()
#       else:
#         from toto.zmqworkerconnection import ZMQWorkerConnection
#         cls._instance = ZMQWorkerConnection.instance()
#     return cls._instance
# 
# Path: toto/options.py
# def safe_define(*args, **kwargs):
#   try:
#     define(*args, **kwargs)
#   except Exception as e:
#     logging.error(str(e))


import toto
import cPickle as pickle
import zlib
import logging
from toto.exceptions import *
from toto.workerconnection import WorkerConnection
from threading import Thread, Lock
from tornado.options import options
from tornado.gen import coroutine, Return
from tornado.ioloop import IOLoop
from collections import deque
from tornado.httpclient import HTTPRequest, AsyncHTTPClient, HTTPError
from tornado.concurrent import Future
from sys import exc_info
from time import time
from uuid import uuid4
from traceback import format_exc
from toto.options import safe_define
from random import shuffle

class _Request(object):
  def __init__(self, headers, body, timeout, retry_count, future, callback=None):
    self.headers = headers

# Path: toto/workerconnection.py
# class WorkerConnection(object):
#   '''Use a ``WorkerConnection`` to make RPCs to the remote worker service(s) or worker/router specified by ``address``.
#      ``address`` may be either an enumerable of address strings or a string of comma separated addresses. RPC retries
#      and timeouts will happen by at most every ``abs(timeout)`` seconds when a periodic callback runs through all active
#      messages and checks for prolonged requests. This is also the default timeout for any new calls. ``timeout`` must not be
#      ``0``.
# 
#      Optionally pass any object or module with ``compress`` and ``decompress`` methods as the ``compression`` parameter to
#      compress messages. The module must implement the same algorithm used on the worker service. By default, messages are not
#      compressed.
# 
#      Optionally pass any object or module with ``dumps`` and ``loads`` methods that convert an ``object`` to and from a
#      ``str`` to replace the default ``cPickle`` serialization with a protocol of your choice.
# 
#      Use ``auto_retry`` to specify whether or not messages should be retried by default. Retrying messages can cause substantial
#      congestion in your worker service. Use with caution.
#   '''
# 
#   def __getattr__(self, path):
#     return WorkerInvocation(path, self)
#   
#   def log_error(self, error):
#     logging.error(repr(error))
# 
#   def enable_traceback_logging(self):
#     from new import instancemethod
#     from traceback import format_exc
#     def log_error(self, e):
#       logging.error(format_exc())
#     self.log_error = instancemethod(log_error, self)
# 
#   @classmethod
#   def instance(cls):
#     '''Returns the default instance of ``WorkerConnection`` as configured by the options prefixed
#       with ``worker_``, instantiating it if necessary. Import the ``workerconnection`` module within
#       your ``TotoService`` and run it with ``--help`` to see all available options.
#     '''
#     if not hasattr(cls, '_instance'):
#       if options.worker_transport == 'http':
#         from toto.httpworkerconnection import HTTPWorkerConnection
#         cls._instance = HTTPWorkerConnection.instance()
#       else:
#         from toto.zmqworkerconnection import ZMQWorkerConnection
#         cls._instance = ZMQWorkerConnection.instance()
#     return cls._instance
# 
# Path: toto/options.py
# def safe_define(*args, **kwargs):
#   try:
#     define(*args, **kwargs)
#   except Exception as e:
#     logging.error(str(e))


# Path: toto/httpworkerconnection.py
import toto
import cPickle as pickle
import zlib
import logging
from toto.exceptions import *
from toto.workerconnection import WorkerConnection
from threading import Thread, Lock
from tornado.options import options
from tornado.gen import coroutine, Return
from tornado.ioloop import IOLoop
from collections import deque
from tornado.httpclient import HTTPRequest, AsyncHTTPClient, HTTPError
from tornado.concurrent import Future
from sys import exc_info
from time import time
from uuid import uuid4
from traceback import format_exc
from toto.options import safe_define
from random import shuffle


class _Request(object):
  def __init__(self, headers, body, timeout, retry_count, future, callback=None):
    self.headers = headers

    self.body = body