forked from named-data/PyCCN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
names.py
43 lines (31 loc) · 1.03 KB
/
names.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from pyccn import _pyccn, CCN, Name
import sys
comps = ['this', 'is', 'some', 'name']
print(comps)
ccn_name = _pyccn.name_comps_to_ccn(comps)
comps2 = _pyccn.name_comps_from_ccn(ccn_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("ccnx:https:///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'])
n = Name([1, '2', bytearray(b'3'), bytes(b'4')])
print(str(n))
assert(str(n) == "/1/2/3/4")
n = Name()
print(str(n))
n = n.appendSegment(5)
print(str(n))
assert(str(n) == "/%00%05")