MCPcopy Create free account
hub / github.com/rthalley/dnspython / expand

Function expand

tests/test_name.py:33–77  ·  view source on GitHub ↗
(text)

Source from the content-addressed store, hash-verified

31
32
33def expand(text):
34 # This is a helper routine to expand name patterns for RFC 4471 tests.
35 #
36 # Basically it turns <character>{<n>} into <n> instances of the character.
37 # For example:
38 #
39 # r"fo{2}.example." => r"foo.example.".
40 #
41 # Two characters get special treatment:
42 # "-" is mapped to r"\000" and "+" is mapped to r"\255". For example
43 #
44 # r"+{3}-.example." -> r"\255\255\255\000.example."
45 #
46 # We do this just to make parsing simpler, so we don't have to process escapes
47 # ourselves.
48 i = 0
49 l = len(text)
50 previous = ""
51 reading_count = False
52 count = 0
53 expanded = []
54 for c in text:
55 if c == "-":
56 c = r"\000"
57 elif c == "+":
58 c = r"\255"
59 if reading_count:
60 assert len(c) == 1
61 if c >= "0" and c <= "9":
62 count *= 10
63 count += ord(c) - ord("0")
64 elif c == "}":
65 expanded.append(previous * count)
66 previous = ""
67 reading_count = False
68 count = 0
69 elif c == "{":
70 reading_count = True
71 else:
72 expanded.append(previous)
73 previous = c
74 # don't forget the last char (if there is one)
75 expanded.append(previous)
76 x = "".join(expanded)
77 return x
78
79
80class NameTestCase(unittest.TestCase):

Callers 2

test_pad_to_max_nameMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…