Esempio n. 1
0
 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
Esempio n. 2
0
 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