本文整理汇总了Python中krpc.encoder.Encoder.encode方法的典型用法代码示例。如果您正苦于以下问题:Python Encoder.encode方法的具体用法?Python Encoder.encode怎么用?Python Encoder.encode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类krpc.encoder.Encoder
的用法示例。
在下文中一共展示了Encoder.encode方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_encode_message
# 需要导入模块: from krpc.encoder import Encoder [as 别名]
# 或者: from krpc.encoder.Encoder import encode [as 别名]
def test_encode_message(self):
request = krpc.schema.KRPC.Request()
request.service = 'ServiceName'
request.procedure = 'ProcedureName'
data = Encoder.encode(request, self.types.as_type('KRPC.Request'))
expected = '0a0b536572766963654e616d65120d50726f6365647572654e616d65'
self.assertEqual(expected, hexlify(data))
示例2: test_encode_message
# 需要导入模块: from krpc.encoder import Encoder [as 别名]
# 或者: from krpc.encoder.Encoder import encode [as 别名]
def test_encode_message(self):
call = self.types.procedure_call_type.python_type()
call.service = 'ServiceName'
call.procedure = 'ProcedureName'
data = Encoder.encode(call, self.types.procedure_call_type)
expected = '0a0b536572766963654e616d65120d50726f6365647572654e616d65'
self.assertEqual(expected, hexlify(data))
示例3: test_encode_class
# 需要导入模块: from krpc.encoder import Encoder [as 别名]
# 或者: from krpc.encoder.Encoder import encode [as 别名]
def test_encode_class(self):
typ = self.types.as_type('Class(ServiceName.ClassName)')
class_type = typ.python_type
self.assertTrue(issubclass(class_type, ClassBase))
value = class_type(300)
self.assertEqual(300, value._object_id)
data = Encoder.encode(value, typ)
self.assertEqual('ac02', hexlify(data))
示例4: encode_argument
# 需要导入模块: from krpc.encoder import Encoder [as 别名]
# 或者: from krpc.encoder.Encoder import encode [as 别名]
def encode_argument(i, value):
typ = param_types[i]
if type(value) != typ.python_type:
# Try coercing to the correct type
try:
value = self._types.coerce_to(value, typ)
except ValueError:
raise TypeError('%s.%s() argument %d must be a %s, got a %s' % \
(service, procedure, i, typ.python_type, type(value)))
return Encoder.encode(value, typ)
示例5: _build_request
# 需要导入模块: from krpc.encoder import Encoder [as 别名]
# 或者: from krpc.encoder.Encoder import encode [as 别名]
def _build_request(self, service, procedure, args,
param_names, param_types, return_type): #pylint: disable=unused-argument
""" Build a KRPC.Request object """
request = krpc.schema.KRPC.Request(service=service, procedure=procedure)
for i, (value, typ) in enumerate(itertools.izip(args, param_types)):
if isinstance(value, DefaultArgument):
continue
if not isinstance(value, typ.python_type):
try:
value = self._types.coerce_to(value, typ)
except ValueError:
raise TypeError('%s.%s() argument %d must be a %s, got a %s' % \
(service, procedure, i, typ.python_type, type(value)))
request.arguments.add(position=i, value=Encoder.encode(value, typ))
return request
示例6: _run_test_encode_value
# 需要导入模块: from krpc.encoder import Encoder [as 别名]
# 或者: from krpc.encoder.Encoder import encode [as 别名]
def _run_test_encode_value(self, typ, cases):
for decoded, encoded in cases:
data = Encoder.encode(decoded, self.types.as_type(typ))
self.assertEqual(encoded, hexlify(data))
示例7: test_encode_class_none
# 需要导入模块: from krpc.encoder import Encoder [as 别名]
# 或者: from krpc.encoder.Encoder import encode [as 别名]
def test_encode_class_none(self):
typ = self.types.as_type('Class(ServiceName.ClassName)')
value = None
data = Encoder.encode(value, typ)
self.assertEqual('00', hexlify(data))
示例8: test_encode_unicode_string
# 需要导入模块: from krpc.encoder import Encoder [as 别名]
# 或者: from krpc.encoder.Encoder import encode [as 别名]
def test_encode_unicode_string(self):
data = Encoder.encode(b'\xe2\x84\xa2'.decode('utf-8'), self.types.as_type('string'))
self.assertEqual('03e284a2', hexlify(data))
示例9: test_encode_value
# 需要导入模块: from krpc.encoder import Encoder [as 别名]
# 或者: from krpc.encoder.Encoder import encode [as 别名]
def test_encode_value(self):
data = Encoder.encode(300, self.types.as_type('int32'))
self.assertEqual('ac02', hexlify(data))