# Path: haigha/frames/method_frame.py
# class MethodFrame(Frame):
# 
#     '''
#     Frame which carries identifier for methods.
#     '''
# 
#     @classmethod
#     def type(cls):
#         return 1
# 
#     @property
#     def class_id(self):
#         return self._class_id
# 
#     @property
#     def method_id(self):
#         return self._method_id
# 
#     @property
#     def args(self):
#         return self._args
# 
#     @classmethod
#     def parse(self, channel_id, payload):
#         class_id = payload.read_short()
#         method_id = payload.read_short()
#         return MethodFrame(channel_id, class_id, method_id, payload)
# 
#     def __init__(self, channel_id, class_id, method_id, args=None):
#         Frame.__init__(self, channel_id)
#         self._class_id = class_id
#         self._method_id = method_id
#         self._args = args
# 
#     def __str__(self):
#         if isinstance(self.args, (Reader, Writer)):
#             return "%s[channel: %d, class_id: %d, method_id: %d, args: %s]" %\
#                 (self.__class__.__name__, self.channel_id,
#                  self.class_id, self.method_id, str(self.args))
#         else:
#             return "%s[channel: %d, class_id: %d, method_id: %d, args: None]" %\
#                 (self.__class__.__name__, self.channel_id,
#                  self.class_id, self.method_id)
# 
#     def write_frame(self, buf):
#         writer = Writer(buf)
#         writer.write_octet(self.type())
#         writer.write_short(self.channel_id)
# 
#         # Write a temporary value for the total length of the frame
#         stream_args_len_pos = len(buf)
#         writer.write_long(0)
# 
#         # Mark the point in the stream where we start writing arguments,
#         # *including* the class and method ids.
#         stream_method_pos = len(buf)
# 
#         writer.write_short(self.class_id)
#         writer.write_short(self.method_id)
# 
#         # This is assuming that args is a Writer
#         if self._args is not None:
#             writer.write(self._args.buffer())
# 
#         # Write the total length back at the position we allocated
#         stream_len = len(buf) - stream_method_pos
#         writer.write_long_at(stream_len, stream_args_len_pos)
# 
#         # Write the footer
#         writer.write_octet(0xce)
# 
# Path: haigha/classes/protocol_class.py
# class ProtocolClass(object):
# 
#     '''
#     The base class of all protocol classes.
#     '''
# 
#     class ProtocolError(Exception):
#         pass
# 
#     class InvalidMethod(ProtocolError):
#         pass
# 
#     class FrameUnderflow(ProtocolError):
#         pass
# 
#     dispatch_map = {}
# 
#     def __init__(self, channel):
#         '''
#         Construct this protocol class on a channel.
#         '''
#         # Cache the channel id so that cleanup can remove the circular channel
#         # reference but id is still accessible (it's useful!)
#         self._channel = channel
#         self._channel_id = channel.channel_id
# 
#     @property
#     def channel(self):
#         return self._channel
# 
#     @property
#     def channel_id(self):
#         return self._channel_id
# 
#     @property
#     def logger(self):
#         return self._channel.logger
# 
#     @property
#     def default_ticket(self):
#         return 0
# 
#     @property
#     def name(self):
#         '''The name given this in the protocol, i.e. 'basic', 'tx', etc'''
#         raise NotImplementedError('must provide a name for %s' % (self))
# 
#     def allow_nowait(self):
#         '''
#         Return True if the transport or  channel allows nowait,
#         False otherwise.
#         '''
#         return not self._channel.synchronous
# 
#     def _cleanup(self):
#         '''
#         "Private" call from Channel when it's shutting down so that local
#         data can be cleaned up and references closed out. It's strongly
#         recommended that subclasses call this /after/ doing their own cleanup .
#         Note that this removes reference to both the channel and the dispatch
#         map.
#         '''
#         self._channel = None
#         self.dispatch_map = None
# 
#     def dispatch(self, method_frame):
#         '''
#         Dispatch a method for this protocol.
#         '''
#         method = self.dispatch_map.get(method_frame.method_id)
#         if method:
#             callback = self.channel.clear_synchronous_cb(method)
#             callback(method_frame)
#         else:
#             raise self.InvalidMethod(
#                 "no method is registered with id: %d" % method_frame.method_id)
# 
#     def send_frame(self, frame):
#         '''
#         Send a frame
#         '''
#         self.channel.send_frame(frame)


from haigha.frames.method_frame import MethodFrame
from haigha.classes.protocol_class import ProtocolClass
from collections import deque
'''
Copyright (c) 2011-2017, Agora Games, LLC All rights reserved.

https://github.com/agoragames/haigha/blob/master/LICENSE.txt
'''




class TransactionClass(ProtocolClass):

    '''
    Implements the AMQP Transaction class
    '''


# Path: haigha/frames/method_frame.py
# class MethodFrame(Frame):
# 
#     '''
#     Frame which carries identifier for methods.
#     '''
# 
#     @classmethod
#     def type(cls):
#         return 1
# 
#     @property
#     def class_id(self):
#         return self._class_id
# 
#     @property
#     def method_id(self):
#         return self._method_id
# 
#     @property
#     def args(self):
#         return self._args
# 
#     @classmethod
#     def parse(self, channel_id, payload):
#         class_id = payload.read_short()
#         method_id = payload.read_short()
#         return MethodFrame(channel_id, class_id, method_id, payload)
# 
#     def __init__(self, channel_id, class_id, method_id, args=None):
#         Frame.__init__(self, channel_id)
#         self._class_id = class_id
#         self._method_id = method_id
#         self._args = args
# 
#     def __str__(self):
#         if isinstance(self.args, (Reader, Writer)):
#             return "%s[channel: %d, class_id: %d, method_id: %d, args: %s]" %\
#                 (self.__class__.__name__, self.channel_id,
#                  self.class_id, self.method_id, str(self.args))
#         else:
#             return "%s[channel: %d, class_id: %d, method_id: %d, args: None]" %\
#                 (self.__class__.__name__, self.channel_id,
#                  self.class_id, self.method_id)
# 
#     def write_frame(self, buf):
#         writer = Writer(buf)
#         writer.write_octet(self.type())
#         writer.write_short(self.channel_id)
# 
#         # Write a temporary value for the total length of the frame
#         stream_args_len_pos = len(buf)
#         writer.write_long(0)
# 
#         # Mark the point in the stream where we start writing arguments,
#         # *including* the class and method ids.
#         stream_method_pos = len(buf)
# 
#         writer.write_short(self.class_id)
#         writer.write_short(self.method_id)
# 
#         # This is assuming that args is a Writer
#         if self._args is not None:
#             writer.write(self._args.buffer())
# 
#         # Write the total length back at the position we allocated
#         stream_len = len(buf) - stream_method_pos
#         writer.write_long_at(stream_len, stream_args_len_pos)
# 
#         # Write the footer
#         writer.write_octet(0xce)
# 
# Path: haigha/classes/protocol_class.py
# class ProtocolClass(object):
# 
#     '''
#     The base class of all protocol classes.
#     '''
# 
#     class ProtocolError(Exception):
#         pass
# 
#     class InvalidMethod(ProtocolError):
#         pass
# 
#     class FrameUnderflow(ProtocolError):
#         pass
# 
#     dispatch_map = {}
# 
#     def __init__(self, channel):
#         '''
#         Construct this protocol class on a channel.
#         '''
#         # Cache the channel id so that cleanup can remove the circular channel
#         # reference but id is still accessible (it's useful!)
#         self._channel = channel
#         self._channel_id = channel.channel_id
# 
#     @property
#     def channel(self):
#         return self._channel
# 
#     @property
#     def channel_id(self):
#         return self._channel_id
# 
#     @property
#     def logger(self):
#         return self._channel.logger
# 
#     @property
#     def default_ticket(self):
#         return 0
# 
#     @property
#     def name(self):
#         '''The name given this in the protocol, i.e. 'basic', 'tx', etc'''
#         raise NotImplementedError('must provide a name for %s' % (self))
# 
#     def allow_nowait(self):
#         '''
#         Return True if the transport or  channel allows nowait,
#         False otherwise.
#         '''
#         return not self._channel.synchronous
# 
#     def _cleanup(self):
#         '''
#         "Private" call from Channel when it's shutting down so that local
#         data can be cleaned up and references closed out. It's strongly
#         recommended that subclasses call this /after/ doing their own cleanup .
#         Note that this removes reference to both the channel and the dispatch
#         map.
#         '''
#         self._channel = None
#         self.dispatch_map = None
# 
#     def dispatch(self, method_frame):
#         '''
#         Dispatch a method for this protocol.
#         '''
#         method = self.dispatch_map.get(method_frame.method_id)
#         if method:
#             callback = self.channel.clear_synchronous_cb(method)
#             callback(method_frame)
#         else:
#             raise self.InvalidMethod(
#                 "no method is registered with id: %d" % method_frame.method_id)
# 
#     def send_frame(self, frame):
#         '''
#         Send a frame
#         '''
#         self.channel.send_frame(frame)


# Path: haigha/classes/transaction_class.py
from haigha.frames.method_frame import MethodFrame
from haigha.classes.protocol_class import ProtocolClass
from collections import deque

'''
Copyright (c) 2011-2017, Agora Games, LLC All rights reserved.

https://github.com/agoragames/haigha/blob/master/LICENSE.txt
'''




class TransactionClass(ProtocolClass):

    '''
    Implements the AMQP Transaction class
    '''


    class TransactionsNotEnabled(ProtocolClass.ProtocolError):