Пример #1
0
 def _run_test_decode_value(self, typ, cases):
     for decoded, encoded in cases:
         value = Decoder.decode(unhexlify(encoded), self.types.as_type(typ))
         if typ in ('float', 'double'):
             self.assertEqual(str(decoded)[0:8], str(value)[0:8])
         else:
             self.assertEqual(decoded, value)
Пример #2
0
 def _run_test_decode_value(self, typ, cases):
     for decoded, encoded in cases:
         value = Decoder.decode(unhexlify(encoded), typ)
         if typ.python_type == float:
             self.assertEqual(str(decoded)[0:8], str(value)[0:8])
         else:
             self.assertEqual(decoded, value)
Пример #3
0
 def _run_test_decode_value(self, typ, cases):
     for decoded, encoded in cases:
         value = Decoder.decode(unhexlify(encoded), self.types.as_type(typ))
         if typ in ('float','double'):
             self.assertEqual(str(decoded)[0:8], str(value)[0:8])
         else:
             self.assertEqual(decoded, value)
Пример #4
0
 def test_decode_message_delimited(self):
     typ = krpc.schema.KRPC.Request
     message = '1c' + '0a0b536572766963654e616d65120d50726f6365647572654e616d65'
     request = Decoder.decode_delimited(unhexlify(message),
                                        self.types.as_type('KRPC.Request'))
     self.assertEqual('ServiceName', request.service)
     self.assertEqual('ProcedureName', request.procedure)
Пример #5
0
 def test_decode_value(self):
     value = Decoder.decode(unhexlify('ac02'), self.types.uint32_type)
     self.assertEqual(int(300), value)
Пример #6
0
 def test_guid(self):
     self.assertEqual('6f271b39-00dd-4de4-9732-f0d3a68838df', Decoder.guid(unhexlify('391b276fdd00e44d9732f0d3a68838df')))
Пример #7
0
 def test_decode_message(self):
     message = '0a0b536572766963654e616d65120d50726f6365647572654e616d65'
     call = Decoder.decode(
         unhexlify(message), self.types.procedure_call_type)
     self.assertEqual('ServiceName', call.service)
     self.assertEqual('ProcedureName', call.procedure)
Пример #8
0
 def test_unhexlify(self):
     self.assertEqual(unhexlify(''), b'')
     self.assertEqual(unhexlify('000102'), b'\x00\x01\x02')
     self.assertEqual(unhexlify('ff'), b'\xFF')
Пример #9
0
 def test_decode_class_none(self):
     typ = self.types.class_type('ServiceName', 'ClassName')
     value = Decoder.decode(unhexlify('00'), typ)
     self.assertIsNone(value)
Пример #10
0
 def test_decode_message(self):
     message = '0a0b536572766963654e616d65120d50726f6365647572654e616d65'
     call = Decoder.decode(unhexlify(message),
                           self.types.procedure_call_type)
     self.assertEqual('ServiceName', call.service)
     self.assertEqual('ProcedureName', call.procedure)
Пример #11
0
 def test_decode_unicode_string(self):
     value = Decoder.decode(unhexlify('03e284a2'), self.types.as_type('string'))
     self.assertEqual(b'\xe2\x84\xa2'.decode('utf-8'), value)
Пример #12
0
 def test_decode_value(self):
     value = Decoder.decode(unhexlify('ac02'), self.types.as_type('int32'))
     self.assertEqual(int(300), value)
Пример #13
0
 def test_decode_message(self):
     message = '0a0b536572766963654e616d65120d50726f6365647572654e616d65'
     request = Decoder.decode(unhexlify(message), self.types.as_type('KRPC.Request'))
     self.assertEqual('ServiceName', request.service)
     self.assertEqual('ProcedureName', request.procedure)
Пример #14
0
 def test_decode_value_delimited(self):
     value = Decoder.decode_delimited(unhexlify('02' + 'ac02'),
                                      self.types.as_type('int32'))
     self.assertEqual(300, value)
Пример #15
0
 def test_decode_size_and_position(self):
     message = '1c'
     size, position = Decoder.decode_size_and_position(unhexlify(message))
     self.assertEqual(28, size)
     self.assertEqual(1, position)
Пример #16
0
 def test_decode_unicode_string(self):
     value = Decoder.decode(unhexlify('03e284a2'), self.types.string_type)
     self.assertEqual(b'\xe2\x84\xa2'.decode('utf-8'), value)
Пример #17
0
 def test_decode_size_and_position(self):
     message = '1c'
     size,position = Decoder.decode_size_and_position(unhexlify(message))
     self.assertEqual(28, size)
     self.assertEqual(1, position)
Пример #18
0
 def test_message_size(self):
     message = '1c'
     size = Decoder.decode_message_size(unhexlify(message))
     self.assertEqual(28, size)
Пример #19
0
 def test_decode_message_delimited(self):
     typ = krpc.schema.KRPC.Request
     message = '1c'+'0a0b536572766963654e616d65120d50726f6365647572654e616d65'
     request = Decoder.decode_delimited(unhexlify(message), self.types.as_type('KRPC.Request'))
     self.assertEqual('ServiceName', request.service)
     self.assertEqual('ProcedureName', request.procedure)
Пример #20
0
 def test_decode_class(self):
     typ = self.types.class_type('ServiceName', 'ClassName')
     value = Decoder.decode(unhexlify('ac02'), typ)
     self.assertTrue(isinstance(value, typ.python_type))
     self.assertEqual(300, value._object_id)
Пример #21
0
 def test_decode_value_delimited(self):
     value = Decoder.decode_delimited(unhexlify('02'+'ac02'), self.types.as_type('int32'))
     self.assertEqual(300, value)
Пример #22
0
 def test_guid(self):
     self.assertEqual(
         '6f271b39-00dd-4de4-9732-f0d3a68838df',
         Decoder.guid(unhexlify('391b276fdd00e44d9732f0d3a68838df')))
Пример #23
0
 def test_decode_message(self):
     message = '0a0b536572766963654e616d65120d50726f6365647572654e616d65'
     request = Decoder.decode(unhexlify(message),
                              self.types.as_type('KRPC.Request'))
     self.assertEqual('ServiceName', request.service)
     self.assertEqual('ProcedureName', request.procedure)
Пример #24
0
 def test_unhexlify(self):
     self.assertEqual(unhexlify(''), b'')
     self.assertEqual(unhexlify('000102'), b'\x00\x01\x02')
     self.assertEqual(unhexlify('ff'), b'\xFF')
Пример #25
0
 def test_decode_class_none(self):
     typ = self.types.as_type('Class(ServiceName.ClassName)')
     value = Decoder.decode(unhexlify('00'), typ)
     self.assertIsNone(value)
Пример #26
0
 def test_decode_class(self):
     typ = self.types.as_type('Class(ServiceName.ClassName)')
     value = Decoder.decode(unhexlify('ac02'), typ)
     self.assertTrue(isinstance(value, typ.python_type))
     self.assertEqual(300, value._object_id)
Пример #27
0
 def test_message_size(self):
     message = '1c'
     size = Decoder.decode_message_size(unhexlify(message))
     self.assertEqual(28, size)