def dispatch(self, channel, message): method = message.method try: handler = self.handlers[method] except KeyError: name = "%s_%s" % (pythonize(method.klass.name), pythonize(method.name)) handler = getattr(self, name) self.handlers[method] = handler return handler(channel, message)
def _unpackFrame(self, data): s = StringIO(data) c = Codec(s) frameType = spec.pythonize(self.spec.constants.byid[c.decode_octet()].name) channel = c.decode_short() payload = Frame.DECODERS[frameType].decode(self.spec, c) end = c.decode_octet() if end != self.FRAME_END: raise GarbageException('frame error: expected %r, got %r' % (self.FRAME_END, end)) frame = Frame(channel, payload) return frame