本文整理汇总了Python中ydk.services.CodecService.decode方法的典型用法代码示例。如果您正苦于以下问题:Python CodecService.decode方法的具体用法?Python CodecService.decode怎么用?Python CodecService.decode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ydk.services.CodecService
的用法示例。
在下文中一共展示了CodecService.decode方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_oc_nis_decode
# 需要导入模块: from ydk.services import CodecService [as 别名]
# 或者: from ydk.services.CodecService import decode [as 别名]
def test_oc_nis_decode(self):
codec_provider = CodecServiceProvider(type='xml')
codec = CodecService()
nis_top = oc_nis.NetworkInstances()
entity = codec.decode(codec_provider, nis_xml, nis_top);
self.assertIsNotNone(entity)
示例2: _get_decoded_entity
# 需要导入模块: from ydk.services import CodecService [as 别名]
# 或者: from ydk.services.CodecService import decode [as 别名]
def _get_decoded_entity():
from ydk.providers import CodecServiceProvider
from ydk.services import CodecService
payload = '''
<system xmlns="urn:ietf:params:xml:ns:yang:ietf-system">
<contact>[email protected]</contact>
<hostname>1.2.3.4</hostname>
<clock>
<timezone-name>Argentina</timezone-name>
</clock>
<ntp>
<server>
<name>xyz</name>
<udp>
<address>1.2.3.4</address>
<port>22</port>
</udp>
<association-type>peer</association-type>
</server>
</ntp>
<dns-resolver>
<search>abc.com</search>
<search>fff.com</search>
<server>
<name>abc</name>
<udp-and-tcp>
<address>1.2.3.4</address>
<port>830</port>
</udp-and-tcp>
</server>
</dns-resolver>
<authentication>
<user>
<name>guest</name>
<password>guest</password>
</user>
<user>
<name>admin</name>
<password>admin</password>
</user>
</authentication>
</system>
'''
codec = CodecService()
provider = CodecServiceProvider(type='xml')
return codec.decode(provider, payload)
示例3: SanityYang
# 需要导入模块: from ydk.services import CodecService [as 别名]
# 或者: from ydk.services.CodecService import decode [as 别名]
#.........这里部分代码省略.........
def test_encode_1(self):
r_1 = self._get_runner_entity()
payload = self.codec.encode(self.provider, r_1)
self.assertEqual(self._runner_payload, payload)
def test_encode_2(self):
from ydk.models.ydktest_sanity import YdkEnumTestEnum
r_1 = ysanity.Runner.Ytypes.BuiltInT()
r_1.enum_value = YdkEnumTestEnum.LOCAL
payload = self.codec.encode(self.provider, r_1)
self.assertEqual(self._enum_payload_1, payload)
def test_encode_invalid_1(self):
try:
self.codec.encode(self.provider, None)
except YPYServiceError as err:
self.assertEqual(
err.message, "'encoder' and 'entity' cannot be None")
else:
raise Exception('YPYServiceError not raised')
def test_encode_invalid_2(self):
try:
self.codec.encode(None, self._get_runner_entity())
except YPYServiceError as e:
err = e
self.assertEqual(
err.message, "'encoder' and 'entity' cannot be None")
else:
raise Exception('YPYServiceError not raised')
def test_encode_invalid_3(self):
try:
self.codec.encode(None, None)
except YPYServiceError as e:
err = e
self.assertEqual(
err.message, "'encoder' and 'entity' cannot be None")
else:
raise Exception('YPYServiceError not raised')
def test_decode_1(self):
entity = self.codec.decode(self.provider, self._enum_payload_2)
self.assertEqual(
self._enum_payload_2, self.codec.encode(self.provider, entity))
def test_decode_invalid_1(self):
try:
self.codec.decode(None, self._enum_payload_2)
except YPYServiceError as e:
err = e
self.assertEqual(
err.message, "'decoder' and 'payload' cannot be None")
else:
raise Exception('YPYServiceError not raised')
def test_decode_invalid_2(self):
try:
self.codec.decode(self.provider, None)
except YPYServiceError as e:
err = e
self.assertEqual(
err.message, "'decoder' and 'payload' cannot be None")
else:
raise Exception('YPYServiceError not raised')
def test_decode_invalid_3(self):
try:
self.codec.decode(None, None)
except YPYServiceError as e:
err = e
self.assertEqual(
err.message, "'decoder' and 'payload' cannot be None")
else:
raise Exception('YPYServiceError not raised')
def test_encode_decode(self):
r_1 = self._get_runner_entity()
payload = self.codec.encode(self.provider, r_1)
entity = self.codec.decode(self.provider, payload)
self.assertEqual(is_equal(r_1, entity), True)
self.assertEqual(payload, self.codec.encode(self.provider, entity))
def test_encode_decode_dict(self):
r_1 = self._get_runner_entity()
r_entity = {'ydktest-sanity':r_1}
payload = self.codec.encode(self.provider, r_entity)
entity = self.codec.decode(self.provider, payload)
for module in entity:
self.assertEqual(is_equal(r_entity[module], entity[module]), True)
self.assertEqual(payload, self.codec.encode(self.provider, entity))
def test_decode_oc_pattern(self):
obj_A = oc_pattern.OcA()
obj_A.a = 'Hello'
entity = self.codec.decode(self.provider, self._oc_pattern_payload)
self.assertEqual(is_equal(obj_A, entity), True)
示例4: SanityYang
# 需要导入模块: from ydk.services import CodecService [as 别名]
# 或者: from ydk.services.CodecService import decode [as 别名]
class SanityYang(unittest.TestCase):
@classmethod
def setUpClass(self):
self.codec = CodecService()
self.provider = CodecServiceProvider(type='xml')
self._enum_payload_1 = \
'<built-in-t xmlns="http://cisco.com/ns/yang/ydktest-sanity">\n <enum-value>local</enum-value>\n</built-in-t>\n'
self._enum_payload_2 = \
'<runner xmlns="http://cisco.com/ns/yang/ydktest-sanity">\n <ytypes>\n <built-in-t>\n <enum-value>local</enum-value>\n </built-in-t>\n </ytypes>\n</runner>\n'
self._runner_payload = \
'<runner xmlns="http://cisco.com/ns/yang/ydktest-sanity">\n\
<two-list>\n\
<ldata>\n\
<number>21</number>\n\
<name>runner:twolist:ldata[21]:name</name>\n\
<subl1>\n\
<number>211</number>\n\
<name>runner:twolist:ldata[21]:subl1[211]:name</name>\n\
</subl1>\n\
<subl1>\n\
<number>212</number>\n\
<name>runner:twolist:ldata[21]:subl1[212]:name</name>\n\
</subl1>\n\
</ldata>\n\
<ldata>\n\
<number>22</number>\n\
<name>runner:twolist:ldata[22]:name</name>\n\
<subl1>\n\
<number>221</number>\n\
<name>runner:twolist:ldata[22]:subl1[221]:name</name>\n\
</subl1>\n\
<subl1>\n\
<number>222</number>\n\
<name>runner:twolist:ldata[22]:subl1[222]:name</name>\n\
</subl1>\n\
</ldata>\n\
</two-list>\n\
</runner>\n'
@classmethod
def tearDownClass(self):
pass
def setUp(self):
print '\nIn method', self._testMethodName + ':'
def tearDown(self):
pass
def _get_runner_entity(self):
r_1 = ysanity.Runner()
e_1, e_2 = ysanity.Runner.TwoList.Ldata(), ysanity.Runner.TwoList.Ldata()
e_11, e_12 = ysanity.Runner.TwoList.Ldata.Subl1(), ysanity.Runner.TwoList.Ldata.Subl1()
e_1.number = 21
e_1.name = 'runner:twolist:ldata[' + str(e_1.number) + ']:name'
e_11.number = 211
e_11.name = 'runner:twolist:ldata[' + str(e_1.number) + ']:subl1[' + str(e_11.number) + ']:name'
e_12.number = 212
e_12.name = 'runner:twolist:ldata[' + str(e_1.number) + ']:subl1[' + str(e_12.number) + ']:name'
e_1.subl1.extend([e_11, e_12])
e_21, e_22 = ysanity.Runner.TwoList.Ldata.Subl1(), ysanity.Runner.TwoList.Ldata.Subl1()
e_2.number = 22
e_2.name = 'runner:twolist:ldata[' + str(e_2.number) + ']:name'
e_21.number = 221
e_21.name = 'runner:twolist:ldata[' + str(e_2.number) + ']:subl1[' + str(e_21.number) + ']:name'
e_22.number = 222
e_22.name = 'runner:twolist:ldata[' + str(e_2.number) + ']:subl1[' + str(e_22.number) + ']:name'
e_2.subl1.extend([e_21, e_22])
r_1.two_list.ldata.extend([e_1, e_2])
return r_1
def test_encode_1(self):
r_1 = self._get_runner_entity()
payload = self.codec.encode(self.provider, r_1)
self.assertEqual(self._runner_payload, payload)
def test_encode_2(self):
from ydk.models.ydktest.ydktest_sanity import YdkEnumTestEnum
r_1 = ysanity.Runner.Ytypes.BuiltInT()
r_1.enum_value = YdkEnumTestEnum.LOCAL
payload = self.codec.encode(self.provider, r_1)
self.assertEqual(self._enum_payload_1, payload)
def test_decode_1(self):
entity = self.codec.decode(self.provider, self._enum_payload_2)
self.assertEqual(self._enum_payload_2, self.codec.encode(self.provider, entity))
def test_encode_decode(self):
r_1 = self._get_runner_entity()
payload = self.codec.encode(self.provider, r_1)
entity = self.codec.decode(self.provider, payload)
self.assertEqual(is_equal(r_1, entity), True)
self.assertEqual(payload, self.codec.encode(self.provider, entity))
示例5: SanityYang
# 需要导入模块: from ydk.services import CodecService [as 别名]
# 或者: from ydk.services.CodecService import decode [as 别名]
#.........这里部分代码省略.........
ldata = ldata_list[lkey]
self.assertNotEqual(ldata, None)
ldata_21 = ldata_list['21']
self.assertEqual(ldata_21.number, 21)
self.assertEqual(ldata_21.name, 'runner:twolist:ldata[21]:name')
subl_21 = ldata_21.subl1
subl_21_keys = subl_21.keys()
self.assertEqual(subl_21_keys, ['211', '212'])
subl_21_212 = subl_21['212']
self.assertEqual(subl_21_212.name, 'runner:twolist:ldata[21]:subl1[212]:name')
def test_xml_encode_2(self):
self.provider.encoding = EncodingFormat.XML
r_1 = Runner.Ytypes.BuiltInT()
r_1.enum_value = YdkEnumTest.local
payload = self.codec.encode(self.provider, r_1)
self.assertEqual(self._xml_enum_payload_1, payload)
@assert_with_error("'provider' and 'entity_holder' cannot be None", YServiceError)
def test_encode_invalid_1(self):
self.codec.encode(self.provider, None)
@assert_with_error("'provider' and 'entity_holder' cannot be None", YServiceError)
def test_encode_invalid_2(self):
self.codec.encode(None, self._get_runner_entity())
@assert_with_error("'provider' and 'entity_holder' cannot be None", YServiceError)
def test_encode_invalid_3(self):
self.codec.encode(None, None)
def test_xml_decode_1(self):
self.provider.encoding = EncodingFormat.XML
entity = self.codec.decode(self.provider, self._xml_enum_payload_2)
self.assertEqual(
self._xml_enum_payload_2, self.codec.encode(self.provider, entity))
@assert_with_error("'provider' and 'payload_holder' cannot be None", YServiceError)
def test_decode_invalid_1(self):
self.codec.decode(None, self._xml_enum_payload_2)
@assert_with_error("'provider' and 'payload_holder' cannot be None", YServiceError)
def test_decode_invalid_2(self):
self.codec.decode(self.provider, None)
@assert_with_error("'provider' and 'payload_holder' cannot be None", YServiceError)
def test_decode_invalid_3(self):
self.codec.decode(None, None)
def test_xml_encode_decode(self):
self.provider.encoding = EncodingFormat.XML
r_1 = self._get_runner_entity()
payload = self.codec.encode(self.provider, r_1)
entity = self.codec.decode(self.provider, payload)
self.assertEqual(r_1, entity)
self.assertEqual(payload, self.codec.encode(self.provider, entity))
def test_xml_encode_decode_dict(self):
self.provider.encoding = EncodingFormat.XML
r_1 = self._get_runner_entity()
r_entity = {'ydktest-sanity':r_1}
payload = self.codec.encode(self.provider, r_entity)
entity = self.codec.decode(self.provider, payload)
示例6: SanityCodec
# 需要导入模块: from ydk.services import CodecService [as 别名]
# 或者: from ydk.services.CodecService import decode [as 别名]
class SanityCodec(unittest.TestCase):
@classmethod
def setUpClass(self):
self.codec = CodecService()
self.provider = CodecServiceProvider(type=EncodingFormat.XML)
self._enum_payload_1 = """<built-in-t xmlns="http://cisco.com/ns/yang/ydktest-sanity">
<enum-value>local</enum-value>
</built-in-t>
"""
self._enum_payload_2 = """<runner xmlns="http://cisco.com/ns/yang/ydktest-sanity">
<ytypes>
<built-in-t>
<enum-value>local</enum-value>
</built-in-t>
</ytypes>
</runner>"""
self._runner_payload = """<runner xmlns="http://cisco.com/ns/yang/ydktest-sanity">
<two-list>
<ldata>
<number>21</number>
<name>runner:twolist:ldata[21]:name</name>
<subl1>
<number>211</number>
<name>runner:twolist:ldata[21]:subl1[211]:name</name>
</subl1>
<subl1>
<number>212</number>
<name>runner:twolist:ldata[21]:subl1[212]:name</name>
</subl1>
</ldata>
<ldata>
<number>22</number>
<name>runner:twolist:ldata[22]:name</name>
<subl1>
<number>221</number>
<name>runner:twolist:ldata[22]:subl1[221]:name</name>
</subl1>
<subl1>
<number>222</number>
<name>runner:twolist:ldata[22]:subl1[222]:name</name>
</subl1>
</ldata>
</two-list>
</runner>
"""
@assert_with_error(_entity_pattern, YServiceError)
def test_encode_invalid_1(self):
self.codec.encode(self.provider, None)
@assert_with_error(_entity_pattern, YServiceError)
def test_encode_invalid_2(self):
self.codec.encode(None, _get_runner_entity())
@assert_with_error(_entity_pattern, YServiceError)
def test_encode_invalid_3(self):
self.codec.encode(None, None)
@assert_with_error(_payload_pattern, YServiceError)
def test_decode_invalid_1(self):
self.codec.decode(None, self._enum_payload_2)
@assert_with_error(_payload_pattern, YServiceError)
def test_decode_invalid_2(self):
self.codec.decode(self.provider, None)
@assert_with_error(_payload_pattern, YServiceError)
def test_decode_invalid_3(self):
self.codec.decode(None, None)