from pyndn import Key, Name, _pyndn, NDN n = Name("/this/is/a/name") ndn_name1 = n.ndn_data name1 = _pyndn.name_comps_from_ndn(ndn_name1) locator1 = _pyndn.KeyLocator_to_ndn(name=ndn_name1) print(locator1) locator1_obj = _pyndn.KeyLocator_obj_from_ndn(locator1) print(locator1_obj) print(locator1_obj.keyName) name2 = _pyndn.name_comps_from_ndn(locator1_obj.keyName.ndn_data) print(name2) for comp1, comp2 in zip(name1, name2): if comp1 != comp2: raise AssertionError("Got a different output: '%s' != '%s'" % (comp1, comp2)) key1 = NDN.getDefaultKey() locator2 = _pyndn.KeyLocator_to_ndn(key=key1.ndn_data_public) print(locator2) locator2_obj = _pyndn.KeyLocator_obj_from_ndn(locator2) key2 = locator2_obj.key print(key2)
from pyndn import Key, Name, _pyndn, NDN n = Name("/this/is/a/name") ndn_name1 = n.ndn_data name1 = _pyndn.name_comps_from_ndn(ndn_name1) locator1 = _pyndn.KeyLocator_to_ndn(name=ndn_name1) print(locator1) locator1_obj = _pyndn.KeyLocator_obj_from_ndn(locator1) print(locator1_obj) print(locator1_obj.keyName) name2 = _pyndn.name_comps_from_ndn(locator1_obj.keyName.ndn_data) print(name2) for comp1, comp2 in zip(name1, name2): if comp1 != comp2: raise AssertionError("Got a different output: '%s' != '%s'" % (comp1, comp2)) key1 = NDN.getDefaultKey() locator2 = _pyndn.KeyLocator_to_ndn(key=key1.ndn_data_public) print(locator2) locator2_obj = _pyndn.KeyLocator_obj_from_ndn(locator2) key2 = locator2_obj.key print(key2) print(key1.ndn_data_public)
from pyndn import _pyndn, NDN, Name import sys comps = ['this', 'is', 'some', 'name'] print(comps) ndn_name = _pyndn.name_comps_to_ndn(comps) comps2 = _pyndn.name_comps_from_ndn(ndn_name) print(comps2) #for comp1, comp2 in zip(map(lambda x: bytearray(x), comps), comps2): for comp1, comp2 in zip([bytearray(x, "ascii") for x in comps], comps2): if comp1 != comp2: raise AssertionError("Got a different output: '%s' != '%s'" % (comp1, comp2)) n = Name(['hello', 'world']) print(str(n)) if str(n) != "/hello/world": raise AssertionError("expected /hello/world") n = Name("ndn:///testing/1/2/3/") print(str(n)) if str(n) != "/testing/1/2/3": raise AssertionError("expected /testing/1/2/3 got: " + str(n)) if len(n) != 4: raise AssertionError("expected 4 components, got: " + len(n)) print(n.components) assert(n.components == [b'testing', b'1', b'2', b'3'])