Make string generator backwards compatible
This commit is contained in:
parent
544638bf42
commit
789eef8f76
1 changed files with 8 additions and 1 deletions
|
|
@ -186,9 +186,16 @@ class RandomStringGenerator:
|
||||||
regex (str): the regular expression.
|
regex (str): the regular expression.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
try:
|
||||||
|
# python 3.11
|
||||||
|
regex_parser = re._parser
|
||||||
|
except AttributeError:
|
||||||
|
# python <3.11
|
||||||
|
regex_parser = re.sre_parse
|
||||||
|
|
||||||
self.total = 1
|
self.total = 1
|
||||||
self.elements = []
|
self.elements = []
|
||||||
tree = re._parser.parse(regex).data # note - sre_parse removed in py3.11
|
tree = regex_parser.parse(regex).data # note - sre_parse removed in py3.11
|
||||||
# `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:
|
||||||
# `element` is also a list, the first element is a string
|
# `element` is also a list, the first element is a string
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue