# Path: servicebus/pika/exceptions.py
# class AMQPError(Exception):
# class AMQPConnectionError(AMQPError):
# class IncompatibleProtocolError(AMQPConnectionError):
# class AuthenticationError(AMQPConnectionError):
# class ProbableAuthenticationError(AMQPConnectionError):
# class ProbableAccessDeniedError(AMQPConnectionError):
# class NoFreeChannels(AMQPConnectionError):
# class ConnectionClosed(AMQPConnectionError):
# class AMQPChannelError(AMQPError):
# class ChannelClosed(AMQPChannelError):
# class DuplicateConsumerTag(AMQPChannelError):
# class ConsumerCancelled(AMQPChannelError):
# class UnroutableError(AMQPChannelError):
# class NackError(AMQPChannelError):
# class InvalidChannelNumber(AMQPError):
# class ProtocolSyntaxError(AMQPError):
# class UnexpectedFrameError(ProtocolSyntaxError):
# class ProtocolVersionMismatch(ProtocolSyntaxError):
# class BodyTooLongError(ProtocolSyntaxError):
# class InvalidFrameError(ProtocolSyntaxError):
# class InvalidFieldTypeException(ProtocolSyntaxError):
# class UnsupportedAMQPFieldException(ProtocolSyntaxError):
# class UnspportedAMQPFieldException(UnsupportedAMQPFieldException):
# class MethodNotImplemented(AMQPError):
# class ChannelError(Exception):
# class InvalidMinimumFrameSize(ProtocolSyntaxError):
# class InvalidMaximumFrameSize(ProtocolSyntaxError):
# class RecursionError(Exception):
# class ShortStringTooLong(AMQPError):
#     def __repr__(self):
#     def __repr__(self):
#     def __repr__(self):
#     def __repr__(self):
#     def __repr__(self):
#     def __repr__(self):
#     def __repr__(self):
#     def __repr__(self):
#     def __repr__(self):
#     def __repr__(self):
#     def __repr__(self):
#     def __repr__(self):
#     def __init__(self, messages):
#     def __repr__(self):
#     def __init__(self, messages):
#     def __repr__(self):
#     def __repr__(self):
#     def __repr__(self):
#     def __repr__(self):
#     def __repr__(self):
#     def __repr__(self):
#     def __repr__(self):
#     def __repr__(self):
#     def __repr__(self):
#     def __repr__(self):
#     def __repr__(self):
#     def __repr__(self):
#     def __repr__(self):
# 
# Path: servicebus/pika/adapters/base_connection.py
#     SOL_TCP = socket.SOL_TCP
#     SOL_TCP = 6
#     _SOCKET_ERROR = socket.error
#     _SOCKET_ERROR = OSError
# LOGGER = logging.getLogger(__name__)
#     READ = 0x0001
#     WRITE = 0x0004
#     ERROR = 0x0008
#     ERRORS_TO_ABORT = [errno.EBADF, errno.ECONNABORTED, errno.EPIPE]
#     ERRORS_TO_IGNORE = [errno.EWOULDBLOCK, errno.EAGAIN, errno.EINTR]
#     DO_HANDSHAKE = True
#     WARN_ABOUT_IOLOOP = False
# class BaseConnection(connection.Connection):
#     def __init__(self,
#                  parameters=None,
#                  on_open_callback=None,
#                  on_open_error_callback=None,
#                  on_close_callback=None,
#                  ioloop=None,
#                  stop_ioloop_on_close=True):
#     def add_timeout(self, deadline, callback_method):
#     def close(self, reply_code=200, reply_text='Normal shutdown'):
#     def remove_timeout(self, timeout_id):
#     def _adapter_connect(self):
#     def _adapter_disconnect(self):
#     def _check_state_on_disconnect(self):
#     def _cleanup_socket(self):
#     def _create_and_connect_to_socket(self, sock_addr_tuple):
#     def _do_ssl_handshake(self):
#     def _get_error_code(error_value):
#     def _flush_outbound(self):
#     def _handle_disconnect(self):
#     def _handle_ioloop_stop(self):
#     def _handle_error(self, error_value):
#     def _handle_timeout(self):
#     def _handle_events(self, fd, events, error=None, write_only=False):
#     def _handle_read(self):
#     def _handle_write(self):
#     def _init_connection_state(self):
#     def _manage_event_state(self):
#     def _wrap_socket(self, sock):


import functools
from twisted.internet import defer, error, reactor
from twisted.python import log
from servicebus.pika import exceptions
from servicebus.pika.adapters import base_connection
        Pika Channel class.

        """
        d = defer.Deferred()
        base_connection.BaseConnection.channel(self, d.callback, channel_number)
        return d.addCallback(TwistedChannel)

    # IReadWriteDescriptor methods

    def fileno(self):
        return self.socket.fileno()

    def logPrefix(self):
        return "twisted-pika"

    def connectionLost(self, reason):
        # If the connection was not closed cleanly, log the error
        if not reason.check(error.ConnectionDone):
            log.err(reason)

        self._handle_disconnect()

    def doRead(self):
        self._handle_read()

    def doWrite(self):
        self._handle_write()
        self._manage_event_state()



# Path: servicebus/pika/exceptions.py
# class AMQPError(Exception):
# class AMQPConnectionError(AMQPError):
# class IncompatibleProtocolError(AMQPConnectionError):
# class AuthenticationError(AMQPConnectionError):
# class ProbableAuthenticationError(AMQPConnectionError):
# class ProbableAccessDeniedError(AMQPConnectionError):
# class NoFreeChannels(AMQPConnectionError):
# class ConnectionClosed(AMQPConnectionError):
# class AMQPChannelError(AMQPError):
# class ChannelClosed(AMQPChannelError):
# class DuplicateConsumerTag(AMQPChannelError):
# class ConsumerCancelled(AMQPChannelError):
# class UnroutableError(AMQPChannelError):
# class NackError(AMQPChannelError):
# class InvalidChannelNumber(AMQPError):
# class ProtocolSyntaxError(AMQPError):
# class UnexpectedFrameError(ProtocolSyntaxError):
# class ProtocolVersionMismatch(ProtocolSyntaxError):
# class BodyTooLongError(ProtocolSyntaxError):
# class InvalidFrameError(ProtocolSyntaxError):
# class InvalidFieldTypeException(ProtocolSyntaxError):
# class UnsupportedAMQPFieldException(ProtocolSyntaxError):
# class UnspportedAMQPFieldException(UnsupportedAMQPFieldException):
# class MethodNotImplemented(AMQPError):
# class ChannelError(Exception):
# class InvalidMinimumFrameSize(ProtocolSyntaxError):
# class InvalidMaximumFrameSize(ProtocolSyntaxError):
# class RecursionError(Exception):
# class ShortStringTooLong(AMQPError):
#     def __repr__(self):
#     def __repr__(self):
#     def __repr__(self):
#     def __repr__(self):
#     def __repr__(self):
#     def __repr__(self):
#     def __repr__(self):
#     def __repr__(self):
#     def __repr__(self):
#     def __repr__(self):
#     def __repr__(self):
#     def __repr__(self):
#     def __init__(self, messages):
#     def __repr__(self):
#     def __init__(self, messages):
#     def __repr__(self):
#     def __repr__(self):
#     def __repr__(self):
#     def __repr__(self):
#     def __repr__(self):
#     def __repr__(self):
#     def __repr__(self):
#     def __repr__(self):
#     def __repr__(self):
#     def __repr__(self):
#     def __repr__(self):
#     def __repr__(self):
#     def __repr__(self):
# 
# Path: servicebus/pika/adapters/base_connection.py
#     SOL_TCP = socket.SOL_TCP
#     SOL_TCP = 6
#     _SOCKET_ERROR = socket.error
#     _SOCKET_ERROR = OSError
# LOGGER = logging.getLogger(__name__)
#     READ = 0x0001
#     WRITE = 0x0004
#     ERROR = 0x0008
#     ERRORS_TO_ABORT = [errno.EBADF, errno.ECONNABORTED, errno.EPIPE]
#     ERRORS_TO_IGNORE = [errno.EWOULDBLOCK, errno.EAGAIN, errno.EINTR]
#     DO_HANDSHAKE = True
#     WARN_ABOUT_IOLOOP = False
# class BaseConnection(connection.Connection):
#     def __init__(self,
#                  parameters=None,
#                  on_open_callback=None,
#                  on_open_error_callback=None,
#                  on_close_callback=None,
#                  ioloop=None,
#                  stop_ioloop_on_close=True):
#     def add_timeout(self, deadline, callback_method):
#     def close(self, reply_code=200, reply_text='Normal shutdown'):
#     def remove_timeout(self, timeout_id):
#     def _adapter_connect(self):
#     def _adapter_disconnect(self):
#     def _check_state_on_disconnect(self):
#     def _cleanup_socket(self):
#     def _create_and_connect_to_socket(self, sock_addr_tuple):
#     def _do_ssl_handshake(self):
#     def _get_error_code(error_value):
#     def _flush_outbound(self):
#     def _handle_disconnect(self):
#     def _handle_ioloop_stop(self):
#     def _handle_error(self, error_value):
#     def _handle_timeout(self):
#     def _handle_events(self, fd, events, error=None, write_only=False):
#     def _handle_read(self):
#     def _handle_write(self):
#     def _init_connection_state(self):
#     def _manage_event_state(self):
#     def _wrap_socket(self, sock):


# Path: servicebus/pika/adapters/twisted_connection.py
import functools
from twisted.internet import defer, error, reactor
from twisted.python import log
from servicebus.pika import exceptions
from servicebus.pika.adapters import base_connection

        Pika Channel class.

        """
        d = defer.Deferred()
        base_connection.BaseConnection.channel(self, d.callback, channel_number)
        return d.addCallback(TwistedChannel)

    # IReadWriteDescriptor methods

    def fileno(self):
        return self.socket.fileno()

    def logPrefix(self):
        return "twisted-pika"

    def connectionLost(self, reason):
        # If the connection was not closed cleanly, log the error
        if not reason.check(error.ConnectionDone):
            log.err(reason)

        self._handle_disconnect()

    def doRead(self):
        self._handle_read()

    def doWrite(self):
        self._handle_write()
        self._manage_event_state()



class TwistedProtocolConnection(base_connection.BaseConnection):