コード例 #1
0
ファイル: parser.py プロジェクト: morningzhang/dubbo
 def read_object(self, code=None):
     if code is None:
         code = self.read(1)
     if code == b'N':
         return None
     elif code == b'T':
         return True
     elif code == b'F':
         return False
     elif code == b'I':
         return int(unpack('>l', self.read(4))[0])
     elif code == b'L':
         return long(unpack('>q', self.read(8))[0])
     elif code == b'D':
         return float(unpack('>d', self.read(8))[0])
     elif code == b'd':
         return self.read_date()
     elif code == b's' or code == b'x':
         fragment = self.read_string()
         next = self.read(1)
         if next.lower() == code:
             return fragment + self.read_object(next)
         else:
             raise ParseError("Expected terminal string segment, got %r" % (next,))
     elif code == b'S' or code == b'X':
         return self.read_string()
     elif code == b'b':
         fragment = self.read_binary()
         next = self.read(1)
         if next.lower() == code:
             return fragment + self.read_object(next)
         else:
             raise ParseError("Expected terminal binary segment, got %r" % (next,))
     elif code == b'B':
         return self.read_binary()
     elif code == b'r':
         return self.read_remote()
     elif code == b'R':
         return self._refs[unpack(">L", self.read(4))[0]]
     elif code == b'V':
         return self.read_list()
     elif code == b'M':
         return self.read_map()
     else:
         raise ParseError("Unknown type marker %r" % (code,))
コード例 #2
0
ファイル: test_parser.py プロジェクト: rackyun/python-hessian
 def test_parse_long_m0x80000001(self):
     expected = long(-0x80000001)
     reply = self.client.replyLong_m0x80000001()
     self.assertEqual(expected, reply)
コード例 #3
0
ファイル: test_parser.py プロジェクト: rackyun/python-hessian
 def test_parse_long_0x80000000(self):
     expected = long(0x80000000)
     reply = self.client.replyLong_0x80000000()
     self.assertEqual(expected, reply)
コード例 #4
0
def test_parse_long_m9(client):
    expected = long(-9)
    reply = client.replyLong_m9()
    assert reply == expected
コード例 #5
0
def test_parse_long_m0x801(client):
    expected = long(-0x801)
    reply = client.replyLong_m0x801()
    assert reply == expected
コード例 #6
0
def test_parse_long_m0x40000(client):
    expected = long(-0x40000)
    reply = client.replyLong_m0x40000()
    assert reply == expected
コード例 #7
0
ファイル: parser.py プロジェクト: morningzhang/dubbo
    def read_object(self, code=None):
        if code is None:
            code = self.read(1)

        if b'\x00' <= code <= b'\x1F':
            # utf-8 string length 0-32
            return self.read_compact_string(code)
        elif b'\x20' <= code <= b'\x2F':
            # binary data length 0-16
            return self.read_binary(code)
        elif b'\x30' <= code <= b'\x33':
            # utf-8 string length 0-1023
            return self.read_compact_string(code)
        elif b'\x34' <= code <= b'\x37':
            # binary data length 0-1023
            return self.read_binary(code)
        elif b'\x38' <= code <= b'\x3F':
            # three-octet compact long (-x40000 to x3ffff)
            b2 = (ord(code) - 0x3c) << 16
            b1 = ord(self.read(1)) << 8
            b0 = ord(self.read(1))
            return long(b0 + b1 + b2)
        elif code in (b'\x41', b'\x42'):
            # 8-bit binary data non-final chunk ('A')
            # 8-bit binary data final chunk ('B')
            return self.read_binary(code)
        elif code == b'\x43':
            # object type definition ('C')
            self.read_class_def()
            return self.read_object()
        elif code == b'\x48':
            # untyped map ('H')
            return self.read_map()
        elif code == b'\x4A':
            # 64-bit UTC millisecond date ('J')
            return self.read_date()
        elif code == b'\x4B':
            # 32-bit UTC minute date ('K')
            return self.read_compact_date()
        elif code == b'\x4D':
            # map with type ('M')
            return self.read_map(code)
        elif code == b'\x4F':
            # object instance ('O')
            return self.read_class_object(code)
        elif code == b'\x51':
            # reference to map/list/object - integer ('Q')
            return self._refs[self.read_object()]
        elif code in (b'\x52', b'\x53'):
            # utf-8 string non-final chunk ('R')
            # utf-8 string final chunk ('S')
            b1 = ord(self.read(1)) << 8
            b0 = ord(self.read(1))
            return self.read_v2_string(code, b0 + b1)
        elif code == b'\x55':
            # variable-length list/vector ('U')
            return self.read_list(typed=True, fixed_length=False)
        elif code == b'\x56':
            # fixed-length list/vector ('V')
            return self.read_list(typed=True, fixed_length=True)
        elif code == b'\x57':
            # variable-length untyped list/vector ('W')
            return self.read_list(typed=False, fixed_length=False)
        elif code == b'\x58':
            # fixed-length untyped list/vector ('X')
            return self.read_list(typed=False, fixed_length=True)
        elif code == b'\x59':
            # long encoded as 32-bit int ('Y')
            return long(unpack('>l', self.read(4))[0])
        elif code == b'\x5A':
            # list/map terminator ('Z')
            raise ListMapTerminator()
        elif code == b'\x5B':
            # double 0.0
            return 0.0
        elif code == b'\x5C':
            # double 1.0
            return 1.0
        elif code == b'\x5D':
            # double byte
            return float(unpack('>b', self.read(1))[0])
        elif code == b'\x5E':
            # double short
            return float(unpack('>h', self.read(2))[0])
        elif code == b'\x5F':
            # double represented as float
            return float(unpack('>l', self.read(4))[0] / 1000.0)
        elif b'\x60' <= code <= b'\x6F':
            # object with direct type
            return self.read_class_object(code)
        elif b'\x70' <= code <= b'\x77':
            # fixed list with direct length
            list_len = ord(code) - 0x70
            return self.read_list(typed=True, fixed_length=True, length=list_len)
        elif b'\x78' <= code <= b'\x7F':
            # fixed untyped list with direct length
            list_len = ord(code) - 0x78
            return self.read_list(typed=False, fixed_length=True, length=list_len)
        elif b'\x80' <= code <= b'\xBF':
            # one-octet compact int (-x10 to x3f, x90 is 0)
            return ord(code) - 0x90
        elif b'\xC0' <= code <= b'\xCF':
            # two-octet compact int (-x800 to x7ff)
            return 256 * (ord(code) - 0xc8) + int(unpack('>B', self.read(1))[0])
        elif b'\xD0' <= code <= b'\xD7':
            # three-octet compact int (-x40000 to x3ffff)
            b1 = int(unpack('>B', self.read(1))[0])
            b0 = int(unpack('>B', self.read(1))[0])
            return 65536 * (ord(code) - 0xd4) + 256 * b1 + b0
        elif b'\xD8' <= code <= b'\xEF':
            # one-octet compact long (-x8 to xf, xe0 is 0)
            return long(ord(code) - 0xe0)
        elif b'\xF0' <= code <= b'\xFF':
            # two-octet compact long (-x800 to x7ff, xf8 is 0)
            b1 = (ord(code) - 0xF8) << 8
            b0 = ord(self.read(1))
            return long(b0 + b1)
        else:
            return super(ParserV2, self).read_object(code)
コード例 #8
0
ファイル: test_parser.py プロジェクト: tgwang/python-hessian
 def test_parse_long_m0x80000001(self):
     expected = long(-0x80000001)
     reply = self.client.replyLong_m0x80000001()
     self.assertEqual(expected, reply)
コード例 #9
0
def test_parse_long_0x7fffffff(client):
    expected = long(0x7fffffff)
    reply = client.replyLong_0x7fffffff()
    assert reply == expected
コード例 #10
0
ファイル: test_encoding.py プロジェクト: slp520/AutoTest
 def test_encode_long_m9(self):
     response = self.client.argLong_m9(long(-9))
     self.assertEqual(response, True, "Debug response: %s" % response)
コード例 #11
0
def test_encode_long_m9(client):
    response = client.argLong_m9(long(-9))
    assert response is True, "Debug response: %s" % response
コード例 #12
0
def test_encode_long_m0x80000001(client):
    response = client.argLong_m0x80000001(long(-0x80000001))
    assert response is True, "Debug response: %s" % response
コード例 #13
0
def test_encode_long_0x80000000(client):
    response = client.argLong_0x80000000(long(0x80000000))
    assert response is True, "Debug response: %s" % response
コード例 #14
0
ファイル: test_parser.py プロジェクト: rackyun/python-hessian
 def test_parse_long_m9(self):
     expected = long(-9)
     reply = self.client.replyLong_m9()
     self.assertEqual(expected, reply)
コード例 #15
0
def test_parse_long_0x800(client):
    expected = long(0x800)
    reply = client.replyLong_0x800()
    assert reply == expected
コード例 #16
0
ファイル: test_parser.py プロジェクト: tgwang/python-hessian
 def test_parse_long_0x80000000(self):
     expected = long(0x80000000)
     reply = self.client.replyLong_0x80000000()
     self.assertEqual(expected, reply)
コード例 #17
0
def test_parse_long_15(client):
    expected = long(15)
    reply = client.replyLong_15()
    assert reply == expected
コード例 #18
0
ファイル: test_parser.py プロジェクト: tgwang/python-hessian
 def test_parse_long_m9(self):
     expected = long(-9)
     reply = self.client.replyLong_m9()
     self.assertEqual(expected, reply)
コード例 #19
0
 def test_encode_long_m9(self):
     response = self.client.argLong_m9(long(-9))
     self.assertEqual(response, True, "Debug response: %s" % response)