Exemple #1
0
 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)
Exemple #2
0
 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)
Exemple #3
0
 def __doOutput(self, name, args, byref, simple):
     stream = BytesIO()
     writer = HproseWriter(stream, simple)
     stream.write(HproseTags.TagCall)
     writer.writeString(name)
     if (len(args) > 0) or byref:
         writer.reset()
         writer.writeList(args)
         if byref: writer.writeBoolean(True)
     stream.write(HproseTags.TagEnd)
     data = stream.getvalue()
     stream.close()
     for _filter in self.__filters:
         data = _filter.outputFilter(data, self)
     return data
Exemple #4
0
 def __doOutput(self, name, args, byref, simple):
     stream = StringIO()
     writer = HproseWriter(stream, simple)
     stream.write(HproseTags.TagCall)
     writer.writeString(name)
     if (len(args) > 0) or byref:
         writer.reset()
         writer.writeList(args)
         if byref: writer.writeBoolean(True)
     stream.write(HproseTags.TagEnd)
     data = stream.getvalue()
     stream.close()
     for _filter in self.__filters:
         data = _filter.outputFilter(data, self)
     return data