# Path: haigha/connections/rabbit_connection.py
# class RabbitConnection(Connection):
# 
#     '''
#     A connection specific to RabbitMQ that supports its extensions.
#     '''
# 
#     def __init__(self, **kwargs):
#         '''
#         Initialize the connection
#         '''
#         class_map = kwargs.get('class_map', {}).copy()
#         class_map.setdefault(40, RabbitExchangeClass)
#         class_map.setdefault(60, RabbitBasicClass)
#         class_map.setdefault(85, RabbitConfirmClass)
#         kwargs['class_map'] = class_map
# 
#         # Set RabbitMQ-specific capabilities to inform broker
# 
#         # Avoid modifying caller's client_properties dict, if passed in
#         if "client_properties" in kwargs:
#             client_properties = copy.deepcopy(kwargs["client_properties"])
#         else:
#             client_properties = dict()
# 
#         # Indicate consumer_cancel_notify capability per
#         # www.rabbitmq.com/consumer-cancel.html
#         client_properties['capabilities'] = dict(consumer_cancel_notify=True)
# 
#         kwargs['client_properties'] = client_properties
# 
# 
#         super(RabbitConnection, self).__init__(**kwargs)
# 
# Path: haigha/message.py
# class Message(object):
# 
#     '''
#     Represents an AMQP message.
#     '''
# 
#     def __init__(self, body='', delivery_info=None, return_info=None,
#                  **properties):
#         '''
#         :param delivery_info: pass only if messages was received via
#           basic.deliver or basic.get_ok; MUST be None otherwise; default: None
#         :param return_info: pass only if message was returned via basic.return;
#           MUST be None otherwise; default: None
#         '''
#         if isinstance(body, unicode):
#             if 'content_encoding' not in properties:
#                 properties['content_encoding'] = 'utf-8'
#             body = body.encode(properties['content_encoding'])
# 
#         if not isinstance(body, (str, unicode, bytearray)):
#             raise TypeError("Invalid message content type %s" % (type(body)))
# 
#         self._body = body
#         self._delivery_info = delivery_info
#         self._return_info = return_info
#         self._properties = properties
# 
#     @property
#     def body(self):
#         return self._body
# 
#     def __len__(self):
#         return len(self._body)
# 
#     def __nonzero__(self):
#         '''Have to define this because length is defined.'''
#         return True
# 
#     def __eq__(self, other):
#         if isinstance(other, Message):
#             return self._properties == other._properties and \
#                 self._body == other._body
#         return False
# 
#     @property
#     def delivery_info(self):
#         '''delivery_info dict if message was received via basic.deliver or
#         basic.get_ok; None otherwise.
#         '''
#         return self._delivery_info
# 
#     @property
#     def return_info(self):
#         '''return_info dict if message was returned via basic.return; None
#         otherwise.
# 
#         properties:
#             'channel': Channel instance
#             'reply_code': reply code (int)
#             'reply_text': reply text
#             'exchange': exchange name
#             'routing_key': routing key
#         '''
#         return self._return_info
# 
#     @property
#     def properties(self):
#         return self._properties
# 
#     def __str__(self):
#         return ("Message[body: %s, delivery_info: %s, return_info: %s, "
#                 "properties: %s]") %\
#             (str(self._body).encode('string_escape'),
#              self._delivery_info, self.return_info, self._properties)


import logging
import socket
import unittest
from haigha.connections.rabbit_connection import RabbitConnection
from haigha.message import Message
        _LOG.info('Enabling publisher confirmations')
        ch.confirm.select()

        _LOG.info('Publishing to exchange "foo" on route "route"')

        with _PubackState(ch) as puback_state:
            mid = ch.basic.publish(Message('hello world'), 'foo', 'route')
            _LOG.info('Published message mid %s', mid)
            while not puback_state.ready:
                connection.read_frames()

            ((how, response_tag),) = puback_state.values
            self.assertEqual(how, puback_state.ACK)
            self.assertEqual(response_tag, mid)

        consumer = _CallbackSink()
        msg = ch.basic.get('bar', consumer=consumer)
        _LOG.info('GET %s', msg)
        # Wait for the rest of the message body to come in, not just the
        # Basic.Get-ok frame
        while not consumer.ready:
            connection.read_frames()
        ((msg,),) = consumer.values
        _LOG.info('GOT %s', msg)
        self.assertEqual(msg.body, 'hello world')


        _LOG.info(
            'Publishing to exchange "foo" on route "nullroute" mandatory=False')
        with _PubackState(ch) as puback_state:

# Path: haigha/connections/rabbit_connection.py
# class RabbitConnection(Connection):
# 
#     '''
#     A connection specific to RabbitMQ that supports its extensions.
#     '''
# 
#     def __init__(self, **kwargs):
#         '''
#         Initialize the connection
#         '''
#         class_map = kwargs.get('class_map', {}).copy()
#         class_map.setdefault(40, RabbitExchangeClass)
#         class_map.setdefault(60, RabbitBasicClass)
#         class_map.setdefault(85, RabbitConfirmClass)
#         kwargs['class_map'] = class_map
# 
#         # Set RabbitMQ-specific capabilities to inform broker
# 
#         # Avoid modifying caller's client_properties dict, if passed in
#         if "client_properties" in kwargs:
#             client_properties = copy.deepcopy(kwargs["client_properties"])
#         else:
#             client_properties = dict()
# 
#         # Indicate consumer_cancel_notify capability per
#         # www.rabbitmq.com/consumer-cancel.html
#         client_properties['capabilities'] = dict(consumer_cancel_notify=True)
# 
#         kwargs['client_properties'] = client_properties
# 
# 
#         super(RabbitConnection, self).__init__(**kwargs)
# 
# Path: haigha/message.py
# class Message(object):
# 
#     '''
#     Represents an AMQP message.
#     '''
# 
#     def __init__(self, body='', delivery_info=None, return_info=None,
#                  **properties):
#         '''
#         :param delivery_info: pass only if messages was received via
#           basic.deliver or basic.get_ok; MUST be None otherwise; default: None
#         :param return_info: pass only if message was returned via basic.return;
#           MUST be None otherwise; default: None
#         '''
#         if isinstance(body, unicode):
#             if 'content_encoding' not in properties:
#                 properties['content_encoding'] = 'utf-8'
#             body = body.encode(properties['content_encoding'])
# 
#         if not isinstance(body, (str, unicode, bytearray)):
#             raise TypeError("Invalid message content type %s" % (type(body)))
# 
#         self._body = body
#         self._delivery_info = delivery_info
#         self._return_info = return_info
#         self._properties = properties
# 
#     @property
#     def body(self):
#         return self._body
# 
#     def __len__(self):
#         return len(self._body)
# 
#     def __nonzero__(self):
#         '''Have to define this because length is defined.'''
#         return True
# 
#     def __eq__(self, other):
#         if isinstance(other, Message):
#             return self._properties == other._properties and \
#                 self._body == other._body
#         return False
# 
#     @property
#     def delivery_info(self):
#         '''delivery_info dict if message was received via basic.deliver or
#         basic.get_ok; None otherwise.
#         '''
#         return self._delivery_info
# 
#     @property
#     def return_info(self):
#         '''return_info dict if message was returned via basic.return; None
#         otherwise.
# 
#         properties:
#             'channel': Channel instance
#             'reply_code': reply code (int)
#             'reply_text': reply text
#             'exchange': exchange name
#             'routing_key': routing key
#         '''
#         return self._return_info
# 
#     @property
#     def properties(self):
#         return self._properties
# 
#     def __str__(self):
#         return ("Message[body: %s, delivery_info: %s, return_info: %s, "
#                 "properties: %s]") %\
#             (str(self._body).encode('string_escape'),
#              self._delivery_info, self.return_info, self._properties)


# Path: tests/integration/rabbit_extensions_test.py
import logging
import socket
import unittest
from haigha.connections.rabbit_connection import RabbitConnection
from haigha.message import Message

        _LOG.info('Enabling publisher confirmations')
        ch.confirm.select()

        _LOG.info('Publishing to exchange "foo" on route "route"')

        with _PubackState(ch) as puback_state:
            mid = ch.basic.publish(Message('hello world'), 'foo', 'route')
            _LOG.info('Published message mid %s', mid)
            while not puback_state.ready:
                connection.read_frames()

            ((how, response_tag),) = puback_state.values
            self.assertEqual(how, puback_state.ACK)
            self.assertEqual(response_tag, mid)

        consumer = _CallbackSink()
        msg = ch.basic.get('bar', consumer=consumer)
        _LOG.info('GET %s', msg)
        # Wait for the rest of the message body to come in, not just the
        # Basic.Get-ok frame
        while not consumer.ready:
            connection.read_frames()
        ((msg,),) = consumer.values
        _LOG.info('GOT %s', msg)
        self.assertEqual(msg.body, 'hello world')


        _LOG.info(
            'Publishing to exchange "foo" on route "nullroute" mandatory=False')
        with _PubackState(ch) as puback_state:

            mid = ch.basic.publish(Message('hello world'), 'foo', 'nullroute')