本文整理匯總了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))