# Path: haigha/classes/protocol_class.py
# class ProtocolClass(object):
#     class ProtocolError(Exception):
#     class InvalidMethod(ProtocolError):
#     class FrameUnderflow(ProtocolError):
#     def __init__(self, channel):
#     def channel(self):
#     def channel_id(self):
#     def logger(self):
#     def default_ticket(self):
#     def name(self):
#     def allow_nowait(self):
#     def _cleanup(self):
#     def dispatch(self, method_frame):
#     def send_frame(self, frame):
# 
# 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 chai import Chai
from haigha.classes import protocol_class
from haigha.classes.protocol_class import ProtocolClass
'''
Copyright (c) 2011-2017, Agora Games, LLC All rights reserved.

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




class ProtocolClassTest(Chai):

    def test_dispatch_when_in_dispatch_map(self):
        ch = mock()
        frame = mock()
        frame.method_id = 42


# Path: haigha/classes/protocol_class.py
# class ProtocolClass(object):
#     class ProtocolError(Exception):
#     class InvalidMethod(ProtocolError):
#     class FrameUnderflow(ProtocolError):
#     def __init__(self, channel):
#     def channel(self):
#     def channel_id(self):
#     def logger(self):
#     def default_ticket(self):
#     def name(self):
#     def allow_nowait(self):
#     def _cleanup(self):
#     def dispatch(self, method_frame):
#     def send_frame(self, frame):
# 
# 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: tests/unit/classes/protocol_class_test.py
from chai import Chai
from haigha.classes import protocol_class
from haigha.classes.protocol_class import ProtocolClass

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

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




class ProtocolClassTest(Chai):

    def test_dispatch_when_in_dispatch_map(self):
        ch = mock()
        frame = mock()
        frame.method_id = 42


        klass = ProtocolClass(ch)