Update random_string_generator's use of sre_parse.parse().data for Py3.
This commit is contained in:
parent
bb15fed784
commit
8c15dff56d
1 changed files with 8 additions and 7 deletions
|
|
@ -185,8 +185,8 @@ class RandomStringGenerator(object):
|
||||||
tree = re.sre_parse.parse(regex).data
|
tree = re.sre_parse.parse(regex).data
|
||||||
# `tree` contains a list of elements in the regular expression
|
# `tree` contains a list of elements in the regular expression
|
||||||
for element in tree:
|
for element in tree:
|
||||||
# `eleemnt` is also a list, the first element is a string
|
# `element` is also a list, the first element is a string
|
||||||
name = element[0]
|
name = str(element[0]).lower()
|
||||||
desc = {"min": 1, "max": 1}
|
desc = {"min": 1, "max": 1}
|
||||||
|
|
||||||
# If `.`, break here
|
# If `.`, break here
|
||||||
|
|
@ -213,10 +213,11 @@ class RandomStringGenerator(object):
|
||||||
|
|
||||||
def _find_literal(self, element):
|
def _find_literal(self, element):
|
||||||
"""Find the literal corresponding to a piece of regular expression."""
|
"""Find the literal corresponding to a piece of regular expression."""
|
||||||
|
name = str(element[0]).lower()
|
||||||
chars = []
|
chars = []
|
||||||
if element[0] == "literal":
|
if name == "literal":
|
||||||
chars.append(chr(element[1]))
|
chars.append(chr(element[1]))
|
||||||
elif element[0] == "in":
|
elif name == "in":
|
||||||
negate = False
|
negate = False
|
||||||
if element[1][0][0] == "negate":
|
if element[1][0][0] == "negate":
|
||||||
negate = True
|
negate = True
|
||||||
|
|
@ -233,10 +234,10 @@ class RandomStringGenerator(object):
|
||||||
chars.remove(char)
|
chars.remove(char)
|
||||||
else:
|
else:
|
||||||
chars.append(char)
|
chars.append(char)
|
||||||
elif element[0] == "range":
|
elif name == "range":
|
||||||
chars = [chr(i) for i in range(element[1][0], element[1][1] + 1)]
|
chars = [chr(i) for i in range(element[1][0], element[1][1] + 1)]
|
||||||
elif element[0] == "category":
|
elif name == "category":
|
||||||
category = element[1]
|
category = str(element[1]).lower()
|
||||||
if category == "category_digit":
|
if category == "category_digit":
|
||||||
chars = list(string.digits)
|
chars = list(string.digits)
|
||||||
elif category == "category_word":
|
elif category == "category_word":
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue