def _doInvoke(self, istream, context): simpleReader = HproseReader(istream, True) tag = HproseTags.TagCall while tag == HproseTags.TagCall: name = simpleReader.readString() aliasname = name.lower() if isinstance(aliasname, str): aliasname = unicode(aliasname, 'utf-8') args = [] byref = False tag = simpleReader.checkTags( (HproseTags.TagList, HproseTags.TagEnd, HproseTags.TagCall)) if tag == HproseTags.TagList: reader = HproseReader(istream) args = reader.readListWithoutTag() tag = reader.checkTags((HproseTags.TagTrue, HproseTags.TagEnd, HproseTags.TagCall)) if (tag == HproseTags.TagTrue): byref = True tag = reader.checkTags( (HproseTags.TagEnd, HproseTags.TagCall)) self._fireBeforeInvokeEvent(name, args, byref, context) if aliasname in self.__functions: function = self.__functions[aliasname] resultMode = self.__resultMode[aliasname] simple = self.__simpleMode[aliasname] result = function(*self._fixArgs(args, function, context)) elif u'*' in self.__functions: function = self.__functions[u'*'] resultMode = self.__resultMode[u'*'] simple = self.__simpleMode[u'*'] result = function(name, args) else: raise HproseException, "Can't find this function %s()." % name self._fireAfterInvokeEvent(name, args, byref, result, context) ostream = StringIO() if resultMode == HproseResultMode.RawWithEndTag: return self.__outputFilter(result, context) if resultMode == HproseResultMode.Raw: ostream.write(result) else: ostream.write(HproseTags.TagResult) if resultMode == HproseResultMode.Serialized: ostream.write(result) else: if simple == None: simple = self.simple writer = HproseWriter(ostream, simple) writer.serialize(result) if byref: ostream.write(HproseTags.TagArgument) writer.reset() writer.writeList(args) ostream.write(HproseTags.TagEnd) return self._responseEnd(ostream, context)
def _doInvoke(self, istream, context): simpleReader = HproseReader(istream, True) tag = HproseTags.TagCall while tag == HproseTags.TagCall: name = simpleReader.readString() aliasname = name.lower() if isinstance(aliasname, str): aliasname = unicode(aliasname, 'utf-8') args = [] byref = False tag = simpleReader.checkTags((HproseTags.TagList, HproseTags.TagEnd, HproseTags.TagCall)) if tag == HproseTags.TagList: reader = HproseReader(istream) args = reader.readListWithoutTag() tag = reader.checkTags((HproseTags.TagTrue, HproseTags.TagEnd, HproseTags.TagCall)) if (tag == HproseTags.TagTrue): byref = True tag = reader.checkTags((HproseTags.TagEnd, HproseTags.TagCall)) self._fireBeforeInvokeEvent(name, args, byref, context) if aliasname in self.__functions: function = self.__functions[aliasname] resultMode = self.__resultMode[aliasname] simple = self.__simpleMode[aliasname] result = function(*self._fixArgs(args, function, context)) elif u'*' in self.__functions: function = self.__functions[u'*'] resultMode = self.__resultMode[u'*'] simple = self.__simpleMode[u'*'] result = function(name, args) else: raise HproseException, "Can't find this function %s()." % name self._fireAfterInvokeEvent(name, args, byref, result, context) ostream = StringIO() if resultMode == HproseResultMode.RawWithEndTag: return self.__outputFilter(result, context) if resultMode == HproseResultMode.Raw: ostream.write(result) else: ostream.write(HproseTags.TagResult) if resultMode == HproseResultMode.Serialized: ostream.write(result) else: if simple == None: simple = self.simple writer = HproseWriter(ostream, simple) writer.serialize(result) if byref: ostream.write(HproseTags.TagArgument) writer.reset() writer.writeList(args) ostream.write(HproseTags.TagEnd) return self._responseEnd(ostream, context)
def __doInput(self, data, args, resultMode): for _filter in reversed(self.__filters): data = _filter.inputFilter(data, self) if data == None or len(data) == 0 or data[len(data) - 1:] != HproseTags.TagEnd: raise HproseException("Wrong Response: \r\n%s" % str(data, 'utf-8')) if resultMode == HproseResultMode.RawWithEndTag: return data if resultMode == HproseResultMode.Raw: return data[:-1] stream = BytesIO(data) reader = HproseReader(stream) result = None try: error = None while True: tag = stream.read(1) if tag == HproseTags.TagEnd: break elif tag == HproseTags.TagResult: if resultMode == HproseResultMode.Normal: reader.reset() result = reader.unserialize() else: s = reader.readRaw() result = s.getvalue() s.close() elif tag == HproseTags.TagArgument: reader.reset() a = reader.readList() if isinstance(args, list): for i in range(len(args)): args[i] = a[i] elif tag == HproseTags.TagError: reader.reset() error = reader.readString() else: raise HproseException("Wrong Response: \r\n%s" % str(data, 'utf-8')) if error != None: raise HproseException(error) finally: stream.close() return result
def __doInput(self, data, args, resultMode): for _filter in reversed(self.__filters): data = _filter.inputFilter(data, self) if data == None or len(data) == 0 or data[len(data) - 1] != HproseTags.TagEnd: raise HproseException, "Wrong Response: \r\n%s" % data if resultMode == HproseResultMode.RawWithEndTag: return data if resultMode == HproseResultMode.Raw: return data[:-1] stream = StringIO(data) reader = HproseReader(stream) result = None try: error = None while True: tag = stream.read(1) if tag == HproseTags.TagEnd: break elif tag == HproseTags.TagResult: if resultMode == HproseResultMode.Normal: reader.reset() result = reader.unserialize() else: s = reader.readRaw() result = s.getvalue() s.close() elif tag == HproseTags.TagArgument: reader.reset() a = reader.readList() if isinstance(args, list): for i in xrange(len(args)): args[i] = a[i] elif tag == HproseTags.TagError: reader.reset() error = reader.readString() else: raise HproseException, "Wrong Response: \r\n%s" % data if error != None: raise HproseException, error finally: stream.close() return result