-
-
Save 0xACE/437c55eaae70385ece7a1d7304ff94dc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
======================================================= test session starts ======================================================== | |
platform linux -- Python 3.8.1, pytest-5.3.2, py-1.8.1, pluggy-0.13.1 | |
rootdir: /build/python-rebulk/src/rebulk-2.0.0, inifile: pytest.ini | |
collected 165 items | |
README.rst F [ 0%] | |
rebulk/rebulk.py . [ 1%] | |
rebulk/utils.py . [ 1%] | |
rebulk/test/test_chain.py ..FFFFFFFFFFFFF [ 10%] | |
rebulk/test/test_debug.py ..... [ 13%] | |
rebulk/test/test_introspector.py ..F. [ 16%] | |
rebulk/test/test_loose.py ...... [ 20%] | |
rebulk/test/test_match.py .................FF..FF... [ 35%] | |
rebulk/test/test_pattern.py ...............F.........F........FF.FF...FFFF. [ 64%] | |
rebulk/test/test_processors.py .....F........ [ 72%] | |
rebulk/test/test_rebulk.py .......F.FFFFFFFF.... [ 85%] | |
rebulk/test/test_rules.py ........... [ 92%] | |
rebulk/test/test_toposort.py ......... [ 97%] | |
rebulk/test/test_validators.py .... [100%] | |
============================================================= FAILURES ============================================================= | |
_______________________________________________________ [doctest] README.rst _______________________________________________________ | |
130 ... .matches("01-02-03-04") | |
131 >>> matches[0].children | |
132 [<01:(0, 2)+initiator=01-02-03-04>, <04:(9, 11)+initiator=01-02-03-04>] | |
133 | |
134 - ``abbreviations`` | |
135 | |
136 Defined as a list of 2-tuple, each tuple is an abbreviation. It simply replace ``tuple[0]`` with ``tuple[1]`` in the | |
137 expression. | |
138 | |
139 >>> Rebulk().regex(r'Custom-separators', abbreviations=[("-", r"[\W_]+")])\ | |
UNEXPECTED EXCEPTION: ValueError("unused keyword argument 'abbreviations'") | |
Traceback (most recent call last): | |
File "/usr/lib/python3.8/doctest.py", line 1329, in __run | |
exec(compile(example.source, filename, "single", | |
File "<doctest README.rst[19]>", line 1, in <module> | |
File "/build/python-rebulk/src/rebulk-2.0.0/rebulk/builder.py", line 179, in regex | |
return self.pattern(self.build_re(*pattern, **kwargs)) | |
File "/build/python-rebulk/src/rebulk-2.0.0/rebulk/builder.py", line 107, in build_re | |
return RePattern(*pattern, **kwargs) | |
File "/build/python-rebulk/src/rebulk-2.0.0/rebulk/pattern.py", line 441, in __init__ | |
pattern = call(re.compile, pattern, **self._kwargs) | |
File "/build/python-rebulk/src/rebulk-2.0.0/rebulk/loose.py", line 60, in call | |
return function(*call_args, **call_kwargs) | |
File "/usr/lib/python3.8/site-packages/regex/regex.py", line 348, in compile | |
return _compile(pattern, flags, ignore_unused, kwargs) | |
File "/usr/lib/python3.8/site-packages/regex/regex.py", line 585, in _compile | |
raise ValueError('unused keyword argument {!a}'.format(any_one)) | |
ValueError: unused keyword argument 'abbreviations' | |
/build/python-rebulk/src/rebulk-2.0.0/README.rst:139: UnexpectedException | |
_______________________________________________________ test_chain_defaults ________________________________________________________ | |
def test_chain_defaults(): | |
rebulk = Rebulk() | |
rebulk.defaults(validator=lambda x: x.value.startswith('t'), ignore_names=['testIgnore'], children=True) | |
> rebulk.chain() \ | |
.regex("(?P<test>test)") \ | |
.regex(" ").repeater("*") \ | |
.regex("(?P<best>best)") \ | |
.regex(" ").repeater("*") \ | |
.regex("(?P<testIgnore>testIgnore)") | |
rebulk/test/test_chain.py:68: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
rebulk/builder.py:179: in regex | |
return self.pattern(self.build_re(*pattern, **kwargs)) | |
rebulk/builder.py:107: in build_re | |
return RePattern(*pattern, **kwargs) | |
rebulk/pattern.py:441: in __init__ | |
pattern = call(re.compile, pattern, **self._kwargs) | |
rebulk/loose.py:60: in call | |
return function(*call_args, **call_kwargs) | |
/usr/lib/python3.8/site-packages/regex/regex.py:348: in compile | |
return _compile(pattern, flags, ignore_unused, kwargs) | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
pattern = '(?P<test>test)', flags = 0, ignore_unused = False | |
kwargs = {'children': True, 'ignore_names': ['testIgnore'], 'validator': <function test_chain_defaults.<locals>.<lambda> at 0x7ff81b029940>} | |
def _compile(pattern, flags, ignore_unused, kwargs): | |
"Compiles a regular expression to a PatternObject." | |
global DEFAULT_VERSION | |
try: | |
from regex import DEFAULT_VERSION | |
except ImportError: | |
pass | |
# We won't bother to cache the pattern if we're debugging. | |
debugging = (flags & DEBUG) != 0 | |
# What locale is this pattern using? | |
locale_key = (type(pattern), pattern) | |
if _locale_sensitive.get(locale_key, True) or (flags & LOCALE) != 0: | |
# This pattern is, or might be, locale-sensitive. | |
pattern_locale = _getpreferredencoding() | |
else: | |
# This pattern is definitely not locale-sensitive. | |
pattern_locale = None | |
if not debugging: | |
try: | |
# Do we know what keyword arguments are needed? | |
args_key = pattern, type(pattern), flags | |
args_needed = _named_args[args_key] | |
# Are we being provided with its required keyword arguments? | |
args_supplied = set() | |
if args_needed: | |
for k, v in args_needed: | |
try: | |
args_supplied.add((k, frozenset(kwargs[k]))) | |
except KeyError: | |
raise error("missing named list: {!r}".format(k)) | |
args_supplied = frozenset(args_supplied) | |
# Have we already seen this regular expression and named list? | |
pattern_key = (pattern, type(pattern), flags, args_supplied, | |
DEFAULT_VERSION, pattern_locale) | |
return _cache[pattern_key] | |
except KeyError: | |
# It's a new pattern, or new named list for a known pattern. | |
pass | |
# Guess the encoding from the class of the pattern string. | |
if isinstance(pattern, str): | |
guess_encoding = UNICODE | |
elif isinstance(pattern, bytes): | |
guess_encoding = ASCII | |
elif isinstance(pattern, Pattern): | |
if flags: | |
raise ValueError("cannot process flags argument with a compiled pattern") | |
return pattern | |
else: | |
raise TypeError("first argument must be a string or compiled pattern") | |
# Set the default version in the core code in case it has been changed. | |
_regex_core.DEFAULT_VERSION = DEFAULT_VERSION | |
global_flags = flags | |
while True: | |
caught_exception = None | |
try: | |
source = _Source(pattern) | |
info = _Info(global_flags, source.char_type, kwargs) | |
info.guess_encoding = guess_encoding | |
source.ignore_space = bool(info.flags & VERBOSE) | |
parsed = _parse_pattern(source, info) | |
break | |
except _UnscopedFlagSet: | |
# Remember the global flags for the next attempt. | |
global_flags = info.global_flags | |
except error as e: | |
caught_exception = e | |
if caught_exception: | |
raise error(caught_exception.msg, caught_exception.pattern, | |
caught_exception.pos) | |
if not source.at_end(): | |
raise error("unbalanced parenthesis", pattern, source.pos) | |
# Check the global flags for conflicts. | |
version = (info.flags & _ALL_VERSIONS) or DEFAULT_VERSION | |
if version not in (0, VERSION0, VERSION1): | |
raise ValueError("VERSION0 and VERSION1 flags are mutually incompatible") | |
if (info.flags & _ALL_ENCODINGS) not in (0, ASCII, LOCALE, UNICODE): | |
raise ValueError("ASCII, LOCALE and UNICODE flags are mutually incompatible") | |
if isinstance(pattern, bytes) and (info.flags & UNICODE): | |
raise ValueError("cannot use UNICODE flag with a bytes pattern") | |
if not (info.flags & _ALL_ENCODINGS): | |
if isinstance(pattern, str): | |
info.flags |= UNICODE | |
else: | |
info.flags |= ASCII | |
reverse = bool(info.flags & REVERSE) | |
fuzzy = isinstance(parsed, _Fuzzy) | |
# Remember whether this pattern as an inline locale flag. | |
_locale_sensitive[locale_key] = info.inline_locale | |
# Fix the group references. | |
caught_exception = None | |
try: | |
parsed.fix_groups(pattern, reverse, False) | |
except error as e: | |
caught_exception = e | |
if caught_exception: | |
raise error(caught_exception.msg, caught_exception.pattern, | |
caught_exception.pos) | |
# Should we print the parsed pattern? | |
if flags & DEBUG: | |
parsed.dump(indent=0, reverse=reverse) | |
# Optimise the parsed pattern. | |
parsed = parsed.optimise(info, reverse) | |
parsed = parsed.pack_characters(info) | |
# Get the required string. | |
req_offset, req_chars, req_flags = _get_required_string(parsed, info.flags) | |
# Build the named lists. | |
named_lists = {} | |
named_list_indexes = [None] * len(info.named_lists_used) | |
args_needed = set() | |
for key, index in info.named_lists_used.items(): | |
name, case_flags = key | |
values = frozenset(kwargs[name]) | |
if case_flags: | |
items = frozenset(_fold_case(info, v) for v in values) | |
else: | |
items = values | |
named_lists[name] = values | |
named_list_indexes[index] = items | |
args_needed.add((name, values)) | |
# Any unused keyword arguments, possibly resulting from a typo? | |
unused_kwargs = set(kwargs) - set(named_lists) | |
if unused_kwargs and not ignore_unused: | |
any_one = next(iter(unused_kwargs)) | |
> raise ValueError('unused keyword argument {!a}'.format(any_one)) | |
E ValueError: unused keyword argument 'ignore_names' | |
/usr/lib/python3.8/site-packages/regex/regex.py:585: ValueError | |
____________________________________________________ test_chain_with_validators ____________________________________________________ | |
def test_chain_with_validators(): | |
def chain_validator(match): | |
return match.value.startswith('t') and match.value.endswith('t') | |
def default_validator(match): | |
return match.value.startswith('t') and match.value.endswith('g') | |
def custom_validator(match): | |
return match.value.startswith('b') and match.value.endswith('t') | |
rebulk = Rebulk() | |
rebulk.defaults(children=True, validator=default_validator) | |
> rebulk.chain(validate_all=True, validator={'__parent__': chain_validator}) \ | |
.regex("(?P<test>testing)", validator=default_validator).repeater("+") \ | |
.regex(" ").repeater("+") \ | |
.regex("(?P<best>best)", validator=custom_validator).repeater("+") | |
rebulk/test/test_chain.py:93: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
rebulk/builder.py:179: in regex | |
return self.pattern(self.build_re(*pattern, **kwargs)) | |
rebulk/builder.py:107: in build_re | |
return RePattern(*pattern, **kwargs) | |
rebulk/pattern.py:441: in __init__ | |
pattern = call(re.compile, pattern, **self._kwargs) | |
rebulk/loose.py:60: in call | |
return function(*call_args, **call_kwargs) | |
/usr/lib/python3.8/site-packages/regex/regex.py:348: in compile | |
return _compile(pattern, flags, ignore_unused, kwargs) | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
pattern = '(?P<test>testing)', flags = 0, ignore_unused = False | |
kwargs = {'children': True, 'validator': <function test_chain_with_validators.<locals>.default_validator at 0x7ff81ae8a700>} | |
def _compile(pattern, flags, ignore_unused, kwargs): | |
"Compiles a regular expression to a PatternObject." | |
global DEFAULT_VERSION | |
try: | |
from regex import DEFAULT_VERSION | |
except ImportError: | |
pass | |
# We won't bother to cache the pattern if we're debugging. | |
debugging = (flags & DEBUG) != 0 | |
# What locale is this pattern using? | |
locale_key = (type(pattern), pattern) | |
if _locale_sensitive.get(locale_key, True) or (flags & LOCALE) != 0: | |
# This pattern is, or might be, locale-sensitive. | |
pattern_locale = _getpreferredencoding() | |
else: | |
# This pattern is definitely not locale-sensitive. | |
pattern_locale = None | |
if not debugging: | |
try: | |
# Do we know what keyword arguments are needed? | |
args_key = pattern, type(pattern), flags | |
args_needed = _named_args[args_key] | |
# Are we being provided with its required keyword arguments? | |
args_supplied = set() | |
if args_needed: | |
for k, v in args_needed: | |
try: | |
args_supplied.add((k, frozenset(kwargs[k]))) | |
except KeyError: | |
raise error("missing named list: {!r}".format(k)) | |
args_supplied = frozenset(args_supplied) | |
# Have we already seen this regular expression and named list? | |
pattern_key = (pattern, type(pattern), flags, args_supplied, | |
DEFAULT_VERSION, pattern_locale) | |
return _cache[pattern_key] | |
except KeyError: | |
# It's a new pattern, or new named list for a known pattern. | |
pass | |
# Guess the encoding from the class of the pattern string. | |
if isinstance(pattern, str): | |
guess_encoding = UNICODE | |
elif isinstance(pattern, bytes): | |
guess_encoding = ASCII | |
elif isinstance(pattern, Pattern): | |
if flags: | |
raise ValueError("cannot process flags argument with a compiled pattern") | |
return pattern | |
else: | |
raise TypeError("first argument must be a string or compiled pattern") | |
# Set the default version in the core code in case it has been changed. | |
_regex_core.DEFAULT_VERSION = DEFAULT_VERSION | |
global_flags = flags | |
while True: | |
caught_exception = None | |
try: | |
source = _Source(pattern) | |
info = _Info(global_flags, source.char_type, kwargs) | |
info.guess_encoding = guess_encoding | |
source.ignore_space = bool(info.flags & VERBOSE) | |
parsed = _parse_pattern(source, info) | |
break | |
except _UnscopedFlagSet: | |
# Remember the global flags for the next attempt. | |
global_flags = info.global_flags | |
except error as e: | |
caught_exception = e | |
if caught_exception: | |
raise error(caught_exception.msg, caught_exception.pattern, | |
caught_exception.pos) | |
if not source.at_end(): | |
raise error("unbalanced parenthesis", pattern, source.pos) | |
# Check the global flags for conflicts. | |
version = (info.flags & _ALL_VERSIONS) or DEFAULT_VERSION | |
if version not in (0, VERSION0, VERSION1): | |
raise ValueError("VERSION0 and VERSION1 flags are mutually incompatible") | |
if (info.flags & _ALL_ENCODINGS) not in (0, ASCII, LOCALE, UNICODE): | |
raise ValueError("ASCII, LOCALE and UNICODE flags are mutually incompatible") | |
if isinstance(pattern, bytes) and (info.flags & UNICODE): | |
raise ValueError("cannot use UNICODE flag with a bytes pattern") | |
if not (info.flags & _ALL_ENCODINGS): | |
if isinstance(pattern, str): | |
info.flags |= UNICODE | |
else: | |
info.flags |= ASCII | |
reverse = bool(info.flags & REVERSE) | |
fuzzy = isinstance(parsed, _Fuzzy) | |
# Remember whether this pattern as an inline locale flag. | |
_locale_sensitive[locale_key] = info.inline_locale | |
# Fix the group references. | |
caught_exception = None | |
try: | |
parsed.fix_groups(pattern, reverse, False) | |
except error as e: | |
caught_exception = e | |
if caught_exception: | |
raise error(caught_exception.msg, caught_exception.pattern, | |
caught_exception.pos) | |
# Should we print the parsed pattern? | |
if flags & DEBUG: | |
parsed.dump(indent=0, reverse=reverse) | |
# Optimise the parsed pattern. | |
parsed = parsed.optimise(info, reverse) | |
parsed = parsed.pack_characters(info) | |
# Get the required string. | |
req_offset, req_chars, req_flags = _get_required_string(parsed, info.flags) | |
# Build the named lists. | |
named_lists = {} | |
named_list_indexes = [None] * len(info.named_lists_used) | |
args_needed = set() | |
for key, index in info.named_lists_used.items(): | |
name, case_flags = key | |
values = frozenset(kwargs[name]) | |
if case_flags: | |
items = frozenset(_fold_case(info, v) for v in values) | |
else: | |
items = values | |
named_lists[name] = values | |
named_list_indexes[index] = items | |
args_needed.add((name, values)) | |
# Any unused keyword arguments, possibly resulting from a typo? | |
unused_kwargs = set(kwargs) - set(named_lists) | |
if unused_kwargs and not ignore_unused: | |
any_one = next(iter(unused_kwargs)) | |
> raise ValueError('unused keyword argument {!a}'.format(any_one)) | |
E ValueError: unused keyword argument 'children' | |
/usr/lib/python3.8/site-packages/regex/regex.py:585: ValueError | |
________________________________________________________ test_matches_docs _________________________________________________________ | |
def test_matches_docs(): | |
> rebulk = Rebulk().regex_defaults(flags=re.IGNORECASE) \ | |
.defaults(children=True, formatter={'episode': int, 'version': int}) \ | |
.chain() \ | |
.regex(r'e(?P<episode>\d{1,4})').repeater(1) \ | |
.regex(r'v(?P<version>\d+)').repeater('?') \ | |
.regex(r'[ex-](?P<episode>\d{1,4})').repeater('*') \ | |
.close() # .repeater(1) could be omitted as it's the default behavior | |
rebulk/test/test_chain.py:105: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
rebulk/builder.py:179: in regex | |
return self.pattern(self.build_re(*pattern, **kwargs)) | |
rebulk/builder.py:107: in build_re | |
return RePattern(*pattern, **kwargs) | |
rebulk/pattern.py:441: in __init__ | |
pattern = call(re.compile, pattern, **self._kwargs) | |
rebulk/loose.py:60: in call | |
return function(*call_args, **call_kwargs) | |
/usr/lib/python3.8/site-packages/regex/regex.py:348: in compile | |
return _compile(pattern, flags, ignore_unused, kwargs) | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
pattern = 'e(?P<episode>\\d{1,4})', flags = re.IGNORECASE, ignore_unused = False | |
kwargs = {'children': True, 'formatter': {'episode': <class 'int'>, 'version': <class 'int'>}} | |
def _compile(pattern, flags, ignore_unused, kwargs): | |
"Compiles a regular expression to a PatternObject." | |
global DEFAULT_VERSION | |
try: | |
from regex import DEFAULT_VERSION | |
except ImportError: | |
pass | |
# We won't bother to cache the pattern if we're debugging. | |
debugging = (flags & DEBUG) != 0 | |
# What locale is this pattern using? | |
locale_key = (type(pattern), pattern) | |
if _locale_sensitive.get(locale_key, True) or (flags & LOCALE) != 0: | |
# This pattern is, or might be, locale-sensitive. | |
pattern_locale = _getpreferredencoding() | |
else: | |
# This pattern is definitely not locale-sensitive. | |
pattern_locale = None | |
if not debugging: | |
try: | |
# Do we know what keyword arguments are needed? | |
args_key = pattern, type(pattern), flags | |
args_needed = _named_args[args_key] | |
# Are we being provided with its required keyword arguments? | |
args_supplied = set() | |
if args_needed: | |
for k, v in args_needed: | |
try: | |
args_supplied.add((k, frozenset(kwargs[k]))) | |
except KeyError: | |
raise error("missing named list: {!r}".format(k)) | |
args_supplied = frozenset(args_supplied) | |
# Have we already seen this regular expression and named list? | |
pattern_key = (pattern, type(pattern), flags, args_supplied, | |
DEFAULT_VERSION, pattern_locale) | |
return _cache[pattern_key] | |
except KeyError: | |
# It's a new pattern, or new named list for a known pattern. | |
pass | |
# Guess the encoding from the class of the pattern string. | |
if isinstance(pattern, str): | |
guess_encoding = UNICODE | |
elif isinstance(pattern, bytes): | |
guess_encoding = ASCII | |
elif isinstance(pattern, Pattern): | |
if flags: | |
raise ValueError("cannot process flags argument with a compiled pattern") | |
return pattern | |
else: | |
raise TypeError("first argument must be a string or compiled pattern") | |
# Set the default version in the core code in case it has been changed. | |
_regex_core.DEFAULT_VERSION = DEFAULT_VERSION | |
global_flags = flags | |
while True: | |
caught_exception = None | |
try: | |
source = _Source(pattern) | |
info = _Info(global_flags, source.char_type, kwargs) | |
info.guess_encoding = guess_encoding | |
source.ignore_space = bool(info.flags & VERBOSE) | |
parsed = _parse_pattern(source, info) | |
break | |
except _UnscopedFlagSet: | |
# Remember the global flags for the next attempt. | |
global_flags = info.global_flags | |
except error as e: | |
caught_exception = e | |
if caught_exception: | |
raise error(caught_exception.msg, caught_exception.pattern, | |
caught_exception.pos) | |
if not source.at_end(): | |
raise error("unbalanced parenthesis", pattern, source.pos) | |
# Check the global flags for conflicts. | |
version = (info.flags & _ALL_VERSIONS) or DEFAULT_VERSION | |
if version not in (0, VERSION0, VERSION1): | |
raise ValueError("VERSION0 and VERSION1 flags are mutually incompatible") | |
if (info.flags & _ALL_ENCODINGS) not in (0, ASCII, LOCALE, UNICODE): | |
raise ValueError("ASCII, LOCALE and UNICODE flags are mutually incompatible") | |
if isinstance(pattern, bytes) and (info.flags & UNICODE): | |
raise ValueError("cannot use UNICODE flag with a bytes pattern") | |
if not (info.flags & _ALL_ENCODINGS): | |
if isinstance(pattern, str): | |
info.flags |= UNICODE | |
else: | |
info.flags |= ASCII | |
reverse = bool(info.flags & REVERSE) | |
fuzzy = isinstance(parsed, _Fuzzy) | |
# Remember whether this pattern as an inline locale flag. | |
_locale_sensitive[locale_key] = info.inline_locale | |
# Fix the group references. | |
caught_exception = None | |
try: | |
parsed.fix_groups(pattern, reverse, False) | |
except error as e: | |
caught_exception = e | |
if caught_exception: | |
raise error(caught_exception.msg, caught_exception.pattern, | |
caught_exception.pos) | |
# Should we print the parsed pattern? | |
if flags & DEBUG: | |
parsed.dump(indent=0, reverse=reverse) | |
# Optimise the parsed pattern. | |
parsed = parsed.optimise(info, reverse) | |
parsed = parsed.pack_characters(info) | |
# Get the required string. | |
req_offset, req_chars, req_flags = _get_required_string(parsed, info.flags) | |
# Build the named lists. | |
named_lists = {} | |
named_list_indexes = [None] * len(info.named_lists_used) | |
args_needed = set() | |
for key, index in info.named_lists_used.items(): | |
name, case_flags = key | |
values = frozenset(kwargs[name]) | |
if case_flags: | |
items = frozenset(_fold_case(info, v) for v in values) | |
else: | |
items = values | |
named_lists[name] = values | |
named_list_indexes[index] = items | |
args_needed.add((name, values)) | |
# Any unused keyword arguments, possibly resulting from a typo? | |
unused_kwargs = set(kwargs) - set(named_lists) | |
if unused_kwargs and not ignore_unused: | |
any_one = next(iter(unused_kwargs)) | |
> raise ValueError('unused keyword argument {!a}'.format(any_one)) | |
E ValueError: unused keyword argument 'formatter' | |
/usr/lib/python3.8/site-packages/regex/regex.py:585: ValueError | |
___________________________________________________________ test_matches ___________________________________________________________ | |
def test_matches(): | |
rebulk = Rebulk() | |
def digit(input_string): | |
i = input_string.find("1849") | |
if i > -1: | |
return i, i + len("1849") | |
input_string = "1849testtestxxfixfux_foxabc1849testtestxoptionalfoxabc" | |
> chain = rebulk.chain() \ | |
.functional(digit) \ | |
.string("test").hidden().repeater(2) \ | |
.string("x").hidden().repeater('{1,3}') \ | |
.string("optional").hidden().repeater('?') \ | |
.regex("f.?x", name='result').repeater('+') \ | |
.close() | |
rebulk/test/test_chain.py:131: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
rebulk/chain.py:302: in regex | |
return self._chain.regex(*pattern, **kwargs) | |
rebulk/builder.py:179: in regex | |
return self.pattern(self.build_re(*pattern, **kwargs)) | |
rebulk/builder.py:107: in build_re | |
return RePattern(*pattern, **kwargs) | |
rebulk/pattern.py:441: in __init__ | |
pattern = call(re.compile, pattern, **self._kwargs) | |
rebulk/loose.py:60: in call | |
return function(*call_args, **call_kwargs) | |
/usr/lib/python3.8/site-packages/regex/regex.py:348: in compile | |
return _compile(pattern, flags, ignore_unused, kwargs) | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
pattern = 'f.?x', flags = 0, ignore_unused = False, kwargs = {'name': 'result'} | |
def _compile(pattern, flags, ignore_unused, kwargs): | |
"Compiles a regular expression to a PatternObject." | |
global DEFAULT_VERSION | |
try: | |
from regex import DEFAULT_VERSION | |
except ImportError: | |
pass | |
# We won't bother to cache the pattern if we're debugging. | |
debugging = (flags & DEBUG) != 0 | |
# What locale is this pattern using? | |
locale_key = (type(pattern), pattern) | |
if _locale_sensitive.get(locale_key, True) or (flags & LOCALE) != 0: | |
# This pattern is, or might be, locale-sensitive. | |
pattern_locale = _getpreferredencoding() | |
else: | |
# This pattern is definitely not locale-sensitive. | |
pattern_locale = None | |
if not debugging: | |
try: | |
# Do we know what keyword arguments are needed? | |
args_key = pattern, type(pattern), flags | |
args_needed = _named_args[args_key] | |
# Are we being provided with its required keyword arguments? | |
args_supplied = set() | |
if args_needed: | |
for k, v in args_needed: | |
try: | |
args_supplied.add((k, frozenset(kwargs[k]))) | |
except KeyError: | |
raise error("missing named list: {!r}".format(k)) | |
args_supplied = frozenset(args_supplied) | |
# Have we already seen this regular expression and named list? | |
pattern_key = (pattern, type(pattern), flags, args_supplied, | |
DEFAULT_VERSION, pattern_locale) | |
return _cache[pattern_key] | |
except KeyError: | |
# It's a new pattern, or new named list for a known pattern. | |
pass | |
# Guess the encoding from the class of the pattern string. | |
if isinstance(pattern, str): | |
guess_encoding = UNICODE | |
elif isinstance(pattern, bytes): | |
guess_encoding = ASCII | |
elif isinstance(pattern, Pattern): | |
if flags: | |
raise ValueError("cannot process flags argument with a compiled pattern") | |
return pattern | |
else: | |
raise TypeError("first argument must be a string or compiled pattern") | |
# Set the default version in the core code in case it has been changed. | |
_regex_core.DEFAULT_VERSION = DEFAULT_VERSION | |
global_flags = flags | |
while True: | |
caught_exception = None | |
try: | |
source = _Source(pattern) | |
info = _Info(global_flags, source.char_type, kwargs) | |
info.guess_encoding = guess_encoding | |
source.ignore_space = bool(info.flags & VERBOSE) | |
parsed = _parse_pattern(source, info) | |
break | |
except _UnscopedFlagSet: | |
# Remember the global flags for the next attempt. | |
global_flags = info.global_flags | |
except error as e: | |
caught_exception = e | |
if caught_exception: | |
raise error(caught_exception.msg, caught_exception.pattern, | |
caught_exception.pos) | |
if not source.at_end(): | |
raise error("unbalanced parenthesis", pattern, source.pos) | |
# Check the global flags for conflicts. | |
version = (info.flags & _ALL_VERSIONS) or DEFAULT_VERSION | |
if version not in (0, VERSION0, VERSION1): | |
raise ValueError("VERSION0 and VERSION1 flags are mutually incompatible") | |
if (info.flags & _ALL_ENCODINGS) not in (0, ASCII, LOCALE, UNICODE): | |
raise ValueError("ASCII, LOCALE and UNICODE flags are mutually incompatible") | |
if isinstance(pattern, bytes) and (info.flags & UNICODE): | |
raise ValueError("cannot use UNICODE flag with a bytes pattern") | |
if not (info.flags & _ALL_ENCODINGS): | |
if isinstance(pattern, str): | |
info.flags |= UNICODE | |
else: | |
info.flags |= ASCII | |
reverse = bool(info.flags & REVERSE) | |
fuzzy = isinstance(parsed, _Fuzzy) | |
# Remember whether this pattern as an inline locale flag. | |
_locale_sensitive[locale_key] = info.inline_locale | |
# Fix the group references. | |
caught_exception = None | |
try: | |
parsed.fix_groups(pattern, reverse, False) | |
except error as e: | |
caught_exception = e | |
if caught_exception: | |
raise error(caught_exception.msg, caught_exception.pattern, | |
caught_exception.pos) | |
# Should we print the parsed pattern? | |
if flags & DEBUG: | |
parsed.dump(indent=0, reverse=reverse) | |
# Optimise the parsed pattern. | |
parsed = parsed.optimise(info, reverse) | |
parsed = parsed.pack_characters(info) | |
# Get the required string. | |
req_offset, req_chars, req_flags = _get_required_string(parsed, info.flags) | |
# Build the named lists. | |
named_lists = {} | |
named_list_indexes = [None] * len(info.named_lists_used) | |
args_needed = set() | |
for key, index in info.named_lists_used.items(): | |
name, case_flags = key | |
values = frozenset(kwargs[name]) | |
if case_flags: | |
items = frozenset(_fold_case(info, v) for v in values) | |
else: | |
items = values | |
named_lists[name] = values | |
named_list_indexes[index] = items | |
args_needed.add((name, values)) | |
# Any unused keyword arguments, possibly resulting from a typo? | |
unused_kwargs = set(kwargs) - set(named_lists) | |
if unused_kwargs and not ignore_unused: | |
any_one = next(iter(unused_kwargs)) | |
> raise ValueError('unused keyword argument {!a}'.format(any_one)) | |
E ValueError: unused keyword argument 'name' | |
/usr/lib/python3.8/site-packages/regex/regex.py:585: ValueError | |
__________________________________________________________ test_matches_2 __________________________________________________________ | |
def test_matches_2(): | |
> rebulk = Rebulk() \ | |
.regex_defaults(flags=re.IGNORECASE) \ | |
.defaults(children=True, formatter={'episode': int, 'version': int}) \ | |
.chain() \ | |
.regex(r'e(?P<episode>\d{1,4})') \ | |
.regex(r'v(?P<version>\d+)').repeater('?') \ | |
.regex(r'[ex-](?P<episode>\d{1,4})').repeater('*') \ | |
.close() | |
rebulk/test/test_chain.py:188: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
rebulk/builder.py:179: in regex | |
return self.pattern(self.build_re(*pattern, **kwargs)) | |
rebulk/builder.py:107: in build_re | |
return RePattern(*pattern, **kwargs) | |
rebulk/pattern.py:441: in __init__ | |
pattern = call(re.compile, pattern, **self._kwargs) | |
rebulk/loose.py:60: in call | |
return function(*call_args, **call_kwargs) | |
/usr/lib/python3.8/site-packages/regex/regex.py:348: in compile | |
return _compile(pattern, flags, ignore_unused, kwargs) | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
pattern = 'e(?P<episode>\\d{1,4})', flags = re.IGNORECASE, ignore_unused = False | |
kwargs = {'children': True, 'formatter': {'episode': <class 'int'>, 'version': <class 'int'>}} | |
def _compile(pattern, flags, ignore_unused, kwargs): | |
"Compiles a regular expression to a PatternObject." | |
global DEFAULT_VERSION | |
try: | |
from regex import DEFAULT_VERSION | |
except ImportError: | |
pass | |
# We won't bother to cache the pattern if we're debugging. | |
debugging = (flags & DEBUG) != 0 | |
# What locale is this pattern using? | |
locale_key = (type(pattern), pattern) | |
if _locale_sensitive.get(locale_key, True) or (flags & LOCALE) != 0: | |
# This pattern is, or might be, locale-sensitive. | |
pattern_locale = _getpreferredencoding() | |
else: | |
# This pattern is definitely not locale-sensitive. | |
pattern_locale = None | |
if not debugging: | |
try: | |
# Do we know what keyword arguments are needed? | |
args_key = pattern, type(pattern), flags | |
args_needed = _named_args[args_key] | |
# Are we being provided with its required keyword arguments? | |
args_supplied = set() | |
if args_needed: | |
for k, v in args_needed: | |
try: | |
args_supplied.add((k, frozenset(kwargs[k]))) | |
except KeyError: | |
raise error("missing named list: {!r}".format(k)) | |
args_supplied = frozenset(args_supplied) | |
# Have we already seen this regular expression and named list? | |
pattern_key = (pattern, type(pattern), flags, args_supplied, | |
DEFAULT_VERSION, pattern_locale) | |
return _cache[pattern_key] | |
except KeyError: | |
# It's a new pattern, or new named list for a known pattern. | |
pass | |
# Guess the encoding from the class of the pattern string. | |
if isinstance(pattern, str): | |
guess_encoding = UNICODE | |
elif isinstance(pattern, bytes): | |
guess_encoding = ASCII | |
elif isinstance(pattern, Pattern): | |
if flags: | |
raise ValueError("cannot process flags argument with a compiled pattern") | |
return pattern | |
else: | |
raise TypeError("first argument must be a string or compiled pattern") | |
# Set the default version in the core code in case it has been changed. | |
_regex_core.DEFAULT_VERSION = DEFAULT_VERSION | |
global_flags = flags | |
while True: | |
caught_exception = None | |
try: | |
source = _Source(pattern) | |
info = _Info(global_flags, source.char_type, kwargs) | |
info.guess_encoding = guess_encoding | |
source.ignore_space = bool(info.flags & VERBOSE) | |
parsed = _parse_pattern(source, info) | |
break | |
except _UnscopedFlagSet: | |
# Remember the global flags for the next attempt. | |
global_flags = info.global_flags | |
except error as e: | |
caught_exception = e | |
if caught_exception: | |
raise error(caught_exception.msg, caught_exception.pattern, | |
caught_exception.pos) | |
if not source.at_end(): | |
raise error("unbalanced parenthesis", pattern, source.pos) | |
# Check the global flags for conflicts. | |
version = (info.flags & _ALL_VERSIONS) or DEFAULT_VERSION | |
if version not in (0, VERSION0, VERSION1): | |
raise ValueError("VERSION0 and VERSION1 flags are mutually incompatible") | |
if (info.flags & _ALL_ENCODINGS) not in (0, ASCII, LOCALE, UNICODE): | |
raise ValueError("ASCII, LOCALE and UNICODE flags are mutually incompatible") | |
if isinstance(pattern, bytes) and (info.flags & UNICODE): | |
raise ValueError("cannot use UNICODE flag with a bytes pattern") | |
if not (info.flags & _ALL_ENCODINGS): | |
if isinstance(pattern, str): | |
info.flags |= UNICODE | |
else: | |
info.flags |= ASCII | |
reverse = bool(info.flags & REVERSE) | |
fuzzy = isinstance(parsed, _Fuzzy) | |
# Remember whether this pattern as an inline locale flag. | |
_locale_sensitive[locale_key] = info.inline_locale | |
# Fix the group references. | |
caught_exception = None | |
try: | |
parsed.fix_groups(pattern, reverse, False) | |
except error as e: | |
caught_exception = e | |
if caught_exception: | |
raise error(caught_exception.msg, caught_exception.pattern, | |
caught_exception.pos) | |
# Should we print the parsed pattern? | |
if flags & DEBUG: | |
parsed.dump(indent=0, reverse=reverse) | |
# Optimise the parsed pattern. | |
parsed = parsed.optimise(info, reverse) | |
parsed = parsed.pack_characters(info) | |
# Get the required string. | |
req_offset, req_chars, req_flags = _get_required_string(parsed, info.flags) | |
# Build the named lists. | |
named_lists = {} | |
named_list_indexes = [None] * len(info.named_lists_used) | |
args_needed = set() | |
for key, index in info.named_lists_used.items(): | |
name, case_flags = key | |
values = frozenset(kwargs[name]) | |
if case_flags: | |
items = frozenset(_fold_case(info, v) for v in values) | |
else: | |
items = values | |
named_lists[name] = values | |
named_list_indexes[index] = items | |
args_needed.add((name, values)) | |
# Any unused keyword arguments, possibly resulting from a typo? | |
unused_kwargs = set(kwargs) - set(named_lists) | |
if unused_kwargs and not ignore_unused: | |
any_one = next(iter(unused_kwargs)) | |
> raise ValueError('unused keyword argument {!a}'.format(any_one)) | |
E ValueError: unused keyword argument 'formatter' | |
/usr/lib/python3.8/site-packages/regex/regex.py:585: ValueError | |
__________________________________________________________ test_matches_3 __________________________________________________________ | |
def test_matches_3(): | |
alt_dash = (r'@', r'[\W_]') # abbreviation | |
match_names = ['season', 'episode'] | |
other_names = ['screen_size', 'video_codec', 'audio_codec', 'audio_channels', 'container', 'date'] | |
rebulk = Rebulk() | |
rebulk.defaults(formatter={'season': int, 'episode': int}, | |
tags=['SxxExx'], | |
abbreviations=[alt_dash], | |
private_names=['episodeSeparator', 'seasonSeparator'], | |
children=True, | |
private_parent=True, | |
conflict_solver=lambda match, other: match | |
if match.name in match_names and other.name in other_names | |
else '__default__') | |
> rebulk.chain() \ | |
.defaults(children=True, private_parent=True) \ | |
.regex(r'(?P<season>\d+)@?x@?(?P<episode>\d+)') \ | |
.regex(r'(?P<episodeSeparator>x|-|\+|&)(?P<episode>\d+)').repeater('*') \ | |
.close() \ | |
.chain() \ | |
.defaults(children=True, private_parent=True) \ | |
.regex(r'S(?P<season>\d+)@?(?:xE|Ex|E|x)@?(?P<episode>\d+)') \ | |
.regex(r'(?:(?P<episodeSeparator>xE|Ex|E|x|-|\+|&)(?P<episode>\d+))').repeater('*') \ | |
.close() \ | |
.chain() \ | |
.defaults(children=True, private_parent=True) \ | |
.regex(r'S(?P<season>\d+)') \ | |
.regex(r'(?P<seasonSeparator>S|-|\+|&)(?P<season>\d+)').repeater('*') | |
rebulk/test/test_chain.py:233: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
rebulk/builder.py:179: in regex | |
return self.pattern(self.build_re(*pattern, **kwargs)) | |
rebulk/builder.py:107: in build_re | |
return RePattern(*pattern, **kwargs) | |
rebulk/pattern.py:441: in __init__ | |
pattern = call(re.compile, pattern, **self._kwargs) | |
rebulk/loose.py:60: in call | |
return function(*call_args, **call_kwargs) | |
/usr/lib/python3.8/site-packages/regex/regex.py:348: in compile | |
return _compile(pattern, flags, ignore_unused, kwargs) | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
pattern = '(?P<season>\\d+)[\\W_]?x[\\W_]?(?P<episode>\\d+)', flags = 0, ignore_unused = False | |
kwargs = {'abbreviations': [('@', '[\\W_]')], 'children': True, 'conflict_solver': <function test_matches_3.<locals>.<lambda> at 0x7ff81aeb8c10>, 'formatter': {'episode': <class 'int'>, 'season': <class 'int'>}, ...} | |
def _compile(pattern, flags, ignore_unused, kwargs): | |
"Compiles a regular expression to a PatternObject." | |
global DEFAULT_VERSION | |
try: | |
from regex import DEFAULT_VERSION | |
except ImportError: | |
pass | |
# We won't bother to cache the pattern if we're debugging. | |
debugging = (flags & DEBUG) != 0 | |
# What locale is this pattern using? | |
locale_key = (type(pattern), pattern) | |
if _locale_sensitive.get(locale_key, True) or (flags & LOCALE) != 0: | |
# This pattern is, or might be, locale-sensitive. | |
pattern_locale = _getpreferredencoding() | |
else: | |
# This pattern is definitely not locale-sensitive. | |
pattern_locale = None | |
if not debugging: | |
try: | |
# Do we know what keyword arguments are needed? | |
args_key = pattern, type(pattern), flags | |
args_needed = _named_args[args_key] | |
# Are we being provided with its required keyword arguments? | |
args_supplied = set() | |
if args_needed: | |
for k, v in args_needed: | |
try: | |
args_supplied.add((k, frozenset(kwargs[k]))) | |
except KeyError: | |
raise error("missing named list: {!r}".format(k)) | |
args_supplied = frozenset(args_supplied) | |
# Have we already seen this regular expression and named list? | |
pattern_key = (pattern, type(pattern), flags, args_supplied, | |
DEFAULT_VERSION, pattern_locale) | |
return _cache[pattern_key] | |
except KeyError: | |
# It's a new pattern, or new named list for a known pattern. | |
pass | |
# Guess the encoding from the class of the pattern string. | |
if isinstance(pattern, str): | |
guess_encoding = UNICODE | |
elif isinstance(pattern, bytes): | |
guess_encoding = ASCII | |
elif isinstance(pattern, Pattern): | |
if flags: | |
raise ValueError("cannot process flags argument with a compiled pattern") | |
return pattern | |
else: | |
raise TypeError("first argument must be a string or compiled pattern") | |
# Set the default version in the core code in case it has been changed. | |
_regex_core.DEFAULT_VERSION = DEFAULT_VERSION | |
global_flags = flags | |
while True: | |
caught_exception = None | |
try: | |
source = _Source(pattern) | |
info = _Info(global_flags, source.char_type, kwargs) | |
info.guess_encoding = guess_encoding | |
source.ignore_space = bool(info.flags & VERBOSE) | |
parsed = _parse_pattern(source, info) | |
break | |
except _UnscopedFlagSet: | |
# Remember the global flags for the next attempt. | |
global_flags = info.global_flags | |
except error as e: | |
caught_exception = e | |
if caught_exception: | |
raise error(caught_exception.msg, caught_exception.pattern, | |
caught_exception.pos) | |
if not source.at_end(): | |
raise error("unbalanced parenthesis", pattern, source.pos) | |
# Check the global flags for conflicts. | |
version = (info.flags & _ALL_VERSIONS) or DEFAULT_VERSION | |
if version not in (0, VERSION0, VERSION1): | |
raise ValueError("VERSION0 and VERSION1 flags are mutually incompatible") | |
if (info.flags & _ALL_ENCODINGS) not in (0, ASCII, LOCALE, UNICODE): | |
raise ValueError("ASCII, LOCALE and UNICODE flags are mutually incompatible") | |
if isinstance(pattern, bytes) and (info.flags & UNICODE): | |
raise ValueError("cannot use UNICODE flag with a bytes pattern") | |
if not (info.flags & _ALL_ENCODINGS): | |
if isinstance(pattern, str): | |
info.flags |= UNICODE | |
else: | |
info.flags |= ASCII | |
reverse = bool(info.flags & REVERSE) | |
fuzzy = isinstance(parsed, _Fuzzy) | |
# Remember whether this pattern as an inline locale flag. | |
_locale_sensitive[locale_key] = info.inline_locale | |
# Fix the group references. | |
caught_exception = None | |
try: | |
parsed.fix_groups(pattern, reverse, False) | |
except error as e: | |
caught_exception = e | |
if caught_exception: | |
raise error(caught_exception.msg, caught_exception.pattern, | |
caught_exception.pos) | |
# Should we print the parsed pattern? | |
if flags & DEBUG: | |
parsed.dump(indent=0, reverse=reverse) | |
# Optimise the parsed pattern. | |
parsed = parsed.optimise(info, reverse) | |
parsed = parsed.pack_characters(info) | |
# Get the required string. | |
req_offset, req_chars, req_flags = _get_required_string(parsed, info.flags) | |
# Build the named lists. | |
named_lists = {} | |
named_list_indexes = [None] * len(info.named_lists_used) | |
args_needed = set() | |
for key, index in info.named_lists_used.items(): | |
name, case_flags = key | |
values = frozenset(kwargs[name]) | |
if case_flags: | |
items = frozenset(_fold_case(info, v) for v in values) | |
else: | |
items = values | |
named_lists[name] = values | |
named_list_indexes[index] = items | |
args_needed.add((name, values)) | |
# Any unused keyword arguments, possibly resulting from a typo? | |
unused_kwargs = set(kwargs) - set(named_lists) | |
if unused_kwargs and not ignore_unused: | |
any_one = next(iter(unused_kwargs)) | |
> raise ValueError('unused keyword argument {!a}'.format(any_one)) | |
E ValueError: unused keyword argument 'private_parent' | |
/usr/lib/python3.8/site-packages/regex/regex.py:585: ValueError | |
__________________________________________________________ test_matches_4 __________________________________________________________ | |
def test_matches_4(): | |
seps_surround = partial(chars_surround, " ") | |
rebulk = Rebulk() | |
rebulk.regex_defaults(flags=re.IGNORECASE) | |
rebulk.defaults(validate_all=True, children=True) | |
rebulk.defaults(private_names=['episodeSeparator', 'seasonSeparator'], private_parent=True) | |
> rebulk.chain(validator={'__parent__': seps_surround}, formatter={'episode': int, 'version': int}) \ | |
.defaults(formatter={'episode': int, 'version': int}) \ | |
.regex(r'e(?P<episode>\d{1,4})') \ | |
.regex(r'v(?P<version>\d+)').repeater('?') \ | |
.regex(r'(?P<episodeSeparator>e|x|-)(?P<episode>\d{1,4})').repeater('*') | |
rebulk/test/test_chain.py:296: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
rebulk/builder.py:179: in regex | |
return self.pattern(self.build_re(*pattern, **kwargs)) | |
rebulk/builder.py:107: in build_re | |
return RePattern(*pattern, **kwargs) | |
rebulk/pattern.py:441: in __init__ | |
pattern = call(re.compile, pattern, **self._kwargs) | |
rebulk/loose.py:60: in call | |
return function(*call_args, **call_kwargs) | |
/usr/lib/python3.8/site-packages/regex/regex.py:348: in compile | |
return _compile(pattern, flags, ignore_unused, kwargs) | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
pattern = 'e(?P<episode>\\d{1,4})', flags = re.IGNORECASE, ignore_unused = False | |
kwargs = {'children': True, 'formatter': {'episode': <class 'int'>, 'version': <class 'int'>}, 'private_names': ['episodeSeparator', 'seasonSeparator'], 'private_parent': True, ...} | |
def _compile(pattern, flags, ignore_unused, kwargs): | |
"Compiles a regular expression to a PatternObject." | |
global DEFAULT_VERSION | |
try: | |
from regex import DEFAULT_VERSION | |
except ImportError: | |
pass | |
# We won't bother to cache the pattern if we're debugging. | |
debugging = (flags & DEBUG) != 0 | |
# What locale is this pattern using? | |
locale_key = (type(pattern), pattern) | |
if _locale_sensitive.get(locale_key, True) or (flags & LOCALE) != 0: | |
# This pattern is, or might be, locale-sensitive. | |
pattern_locale = _getpreferredencoding() | |
else: | |
# This pattern is definitely not locale-sensitive. | |
pattern_locale = None | |
if not debugging: | |
try: | |
# Do we know what keyword arguments are needed? | |
args_key = pattern, type(pattern), flags | |
args_needed = _named_args[args_key] | |
# Are we being provided with its required keyword arguments? | |
args_supplied = set() | |
if args_needed: | |
for k, v in args_needed: | |
try: | |
args_supplied.add((k, frozenset(kwargs[k]))) | |
except KeyError: | |
raise error("missing named list: {!r}".format(k)) | |
args_supplied = frozenset(args_supplied) | |
# Have we already seen this regular expression and named list? | |
pattern_key = (pattern, type(pattern), flags, args_supplied, | |
DEFAULT_VERSION, pattern_locale) | |
return _cache[pattern_key] | |
except KeyError: | |
# It's a new pattern, or new named list for a known pattern. | |
pass | |
# Guess the encoding from the class of the pattern string. | |
if isinstance(pattern, str): | |
guess_encoding = UNICODE | |
elif isinstance(pattern, bytes): | |
guess_encoding = ASCII | |
elif isinstance(pattern, Pattern): | |
if flags: | |
raise ValueError("cannot process flags argument with a compiled pattern") | |
return pattern | |
else: | |
raise TypeError("first argument must be a string or compiled pattern") | |
# Set the default version in the core code in case it has been changed. | |
_regex_core.DEFAULT_VERSION = DEFAULT_VERSION | |
global_flags = flags | |
while True: | |
caught_exception = None | |
try: | |
source = _Source(pattern) | |
info = _Info(global_flags, source.char_type, kwargs) | |
info.guess_encoding = guess_encoding | |
source.ignore_space = bool(info.flags & VERBOSE) | |
parsed = _parse_pattern(source, info) | |
break | |
except _UnscopedFlagSet: | |
# Remember the global flags for the next attempt. | |
global_flags = info.global_flags | |
except error as e: | |
caught_exception = e | |
if caught_exception: | |
raise error(caught_exception.msg, caught_exception.pattern, | |
caught_exception.pos) | |
if not source.at_end(): | |
raise error("unbalanced parenthesis", pattern, source.pos) | |
# Check the global flags for conflicts. | |
version = (info.flags & _ALL_VERSIONS) or DEFAULT_VERSION | |
if version not in (0, VERSION0, VERSION1): | |
raise ValueError("VERSION0 and VERSION1 flags are mutually incompatible") | |
if (info.flags & _ALL_ENCODINGS) not in (0, ASCII, LOCALE, UNICODE): | |
raise ValueError("ASCII, LOCALE and UNICODE flags are mutually incompatible") | |
if isinstance(pattern, bytes) and (info.flags & UNICODE): | |
raise ValueError("cannot use UNICODE flag with a bytes pattern") | |
if not (info.flags & _ALL_ENCODINGS): | |
if isinstance(pattern, str): | |
info.flags |= UNICODE | |
else: | |
info.flags |= ASCII | |
reverse = bool(info.flags & REVERSE) | |
fuzzy = isinstance(parsed, _Fuzzy) | |
# Remember whether this pattern as an inline locale flag. | |
_locale_sensitive[locale_key] = info.inline_locale | |
# Fix the group references. | |
caught_exception = None | |
try: | |
parsed.fix_groups(pattern, reverse, False) | |
except error as e: | |
caught_exception = e | |
if caught_exception: | |
raise error(caught_exception.msg, caught_exception.pattern, | |
caught_exception.pos) | |
# Should we print the parsed pattern? | |
if flags & DEBUG: | |
parsed.dump(indent=0, reverse=reverse) | |
# Optimise the parsed pattern. | |
parsed = parsed.optimise(info, reverse) | |
parsed = parsed.pack_characters(info) | |
# Get the required string. | |
req_offset, req_chars, req_flags = _get_required_string(parsed, info.flags) | |
# Build the named lists. | |
named_lists = {} | |
named_list_indexes = [None] * len(info.named_lists_used) | |
args_needed = set() | |
for key, index in info.named_lists_used.items(): | |
name, case_flags = key | |
values = frozenset(kwargs[name]) | |
if case_flags: | |
items = frozenset(_fold_case(info, v) for v in values) | |
else: | |
items = values | |
named_lists[name] = values | |
named_list_indexes[index] = items | |
args_needed.add((name, values)) | |
# Any unused keyword arguments, possibly resulting from a typo? | |
unused_kwargs = set(kwargs) - set(named_lists) | |
if unused_kwargs and not ignore_unused: | |
any_one = next(iter(unused_kwargs)) | |
> raise ValueError('unused keyword argument {!a}'.format(any_one)) | |
E ValueError: unused keyword argument 'private_parent' | |
/usr/lib/python3.8/site-packages/regex/regex.py:585: ValueError | |
__________________________________________________________ test_matches_5 __________________________________________________________ | |
def test_matches_5(): | |
seps_surround = partial(chars_surround, " ") | |
rebulk = Rebulk() | |
rebulk.regex_defaults(flags=re.IGNORECASE) | |
> rebulk.chain(private_names=['episodeSeparator', 'seasonSeparator'], validate_all=True, | |
validator={'__parent__': seps_surround}, children=True, private_parent=True, | |
formatter={'episode': int, 'version': int}) \ | |
.defaults(children=True, private_parent=True) \ | |
.regex(r'e(?P<episode>\d{1,4})') \ | |
.regex(r'v(?P<version>\d+)').repeater('?') \ | |
.regex(r'(?P<episodeSeparator>e|x|-)(?P<episode>\d{1,4})').repeater('{2,3}') | |
rebulk/test/test_chain.py:316: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
rebulk/builder.py:179: in regex | |
return self.pattern(self.build_re(*pattern, **kwargs)) | |
rebulk/builder.py:107: in build_re | |
return RePattern(*pattern, **kwargs) | |
rebulk/pattern.py:441: in __init__ | |
pattern = call(re.compile, pattern, **self._kwargs) | |
rebulk/loose.py:60: in call | |
return function(*call_args, **call_kwargs) | |
/usr/lib/python3.8/site-packages/regex/regex.py:348: in compile | |
return _compile(pattern, flags, ignore_unused, kwargs) | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
pattern = 'e(?P<episode>\\d{1,4})', flags = re.IGNORECASE, ignore_unused = False | |
kwargs = {'children': True, 'private_parent': True} | |
def _compile(pattern, flags, ignore_unused, kwargs): | |
"Compiles a regular expression to a PatternObject." | |
global DEFAULT_VERSION | |
try: | |
from regex import DEFAULT_VERSION | |
except ImportError: | |
pass | |
# We won't bother to cache the pattern if we're debugging. | |
debugging = (flags & DEBUG) != 0 | |
# What locale is this pattern using? | |
locale_key = (type(pattern), pattern) | |
if _locale_sensitive.get(locale_key, True) or (flags & LOCALE) != 0: | |
# This pattern is, or might be, locale-sensitive. | |
pattern_locale = _getpreferredencoding() | |
else: | |
# This pattern is definitely not locale-sensitive. | |
pattern_locale = None | |
if not debugging: | |
try: | |
# Do we know what keyword arguments are needed? | |
args_key = pattern, type(pattern), flags | |
args_needed = _named_args[args_key] | |
# Are we being provided with its required keyword arguments? | |
args_supplied = set() | |
if args_needed: | |
for k, v in args_needed: | |
try: | |
args_supplied.add((k, frozenset(kwargs[k]))) | |
except KeyError: | |
raise error("missing named list: {!r}".format(k)) | |
args_supplied = frozenset(args_supplied) | |
# Have we already seen this regular expression and named list? | |
pattern_key = (pattern, type(pattern), flags, args_supplied, | |
DEFAULT_VERSION, pattern_locale) | |
return _cache[pattern_key] | |
except KeyError: | |
# It's a new pattern, or new named list for a known pattern. | |
pass | |
# Guess the encoding from the class of the pattern string. | |
if isinstance(pattern, str): | |
guess_encoding = UNICODE | |
elif isinstance(pattern, bytes): | |
guess_encoding = ASCII | |
elif isinstance(pattern, Pattern): | |
if flags: | |
raise ValueError("cannot process flags argument with a compiled pattern") | |
return pattern | |
else: | |
raise TypeError("first argument must be a string or compiled pattern") | |
# Set the default version in the core code in case it has been changed. | |
_regex_core.DEFAULT_VERSION = DEFAULT_VERSION | |
global_flags = flags | |
while True: | |
caught_exception = None | |
try: | |
source = _Source(pattern) | |
info = _Info(global_flags, source.char_type, kwargs) | |
info.guess_encoding = guess_encoding | |
source.ignore_space = bool(info.flags & VERBOSE) | |
parsed = _parse_pattern(source, info) | |
break | |
except _UnscopedFlagSet: | |
# Remember the global flags for the next attempt. | |
global_flags = info.global_flags | |
except error as e: | |
caught_exception = e | |
if caught_exception: | |
raise error(caught_exception.msg, caught_exception.pattern, | |
caught_exception.pos) | |
if not source.at_end(): | |
raise error("unbalanced parenthesis", pattern, source.pos) | |
# Check the global flags for conflicts. | |
version = (info.flags & _ALL_VERSIONS) or DEFAULT_VERSION | |
if version not in (0, VERSION0, VERSION1): | |
raise ValueError("VERSION0 and VERSION1 flags are mutually incompatible") | |
if (info.flags & _ALL_ENCODINGS) not in (0, ASCII, LOCALE, UNICODE): | |
raise ValueError("ASCII, LOCALE and UNICODE flags are mutually incompatible") | |
if isinstance(pattern, bytes) and (info.flags & UNICODE): | |
raise ValueError("cannot use UNICODE flag with a bytes pattern") | |
if not (info.flags & _ALL_ENCODINGS): | |
if isinstance(pattern, str): | |
info.flags |= UNICODE | |
else: | |
info.flags |= ASCII | |
reverse = bool(info.flags & REVERSE) | |
fuzzy = isinstance(parsed, _Fuzzy) | |
# Remember whether this pattern as an inline locale flag. | |
_locale_sensitive[locale_key] = info.inline_locale | |
# Fix the group references. | |
caught_exception = None | |
try: | |
parsed.fix_groups(pattern, reverse, False) | |
except error as e: | |
caught_exception = e | |
if caught_exception: | |
raise error(caught_exception.msg, caught_exception.pattern, | |
caught_exception.pos) | |
# Should we print the parsed pattern? | |
if flags & DEBUG: | |
parsed.dump(indent=0, reverse=reverse) | |
# Optimise the parsed pattern. | |
parsed = parsed.optimise(info, reverse) | |
parsed = parsed.pack_characters(info) | |
# Get the required string. | |
req_offset, req_chars, req_flags = _get_required_string(parsed, info.flags) | |
# Build the named lists. | |
named_lists = {} | |
named_list_indexes = [None] * len(info.named_lists_used) | |
args_needed = set() | |
for key, index in info.named_lists_used.items(): | |
name, case_flags = key | |
values = frozenset(kwargs[name]) | |
if case_flags: | |
items = frozenset(_fold_case(info, v) for v in values) | |
else: | |
items = values | |
named_lists[name] = values | |
named_list_indexes[index] = items | |
args_needed.add((name, values)) | |
# Any unused keyword arguments, possibly resulting from a typo? | |
unused_kwargs = set(kwargs) - set(named_lists) | |
if unused_kwargs and not ignore_unused: | |
any_one = next(iter(unused_kwargs)) | |
> raise ValueError('unused keyword argument {!a}'.format(any_one)) | |
E ValueError: unused keyword argument 'private_parent' | |
/usr/lib/python3.8/site-packages/regex/regex.py:585: ValueError | |
__________________________________________________________ test_matches_6 __________________________________________________________ | |
def test_matches_6(): | |
rebulk = Rebulk() | |
rebulk.regex_defaults(flags=re.IGNORECASE) | |
rebulk.defaults(private_names=['episodeSeparator', 'seasonSeparator'], validate_all=True, | |
validator=None, children=True, private_parent=True) | |
> rebulk.chain(formatter={'episode': int, 'version': int}) \ | |
.defaults(children=True, private_parent=True) \ | |
.regex(r'e(?P<episode>\d{1,4})') \ | |
.regex(r'v(?P<version>\d+)').repeater('?') \ | |
.regex(r'(?P<episodeSeparator>e|x|-)(?P<episode>\d{1,4})').repeater('{2,3}') | |
rebulk/test/test_chain.py:340: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
rebulk/builder.py:179: in regex | |
return self.pattern(self.build_re(*pattern, **kwargs)) | |
rebulk/builder.py:107: in build_re | |
return RePattern(*pattern, **kwargs) | |
rebulk/pattern.py:441: in __init__ | |
pattern = call(re.compile, pattern, **self._kwargs) | |
rebulk/loose.py:60: in call | |
return function(*call_args, **call_kwargs) | |
/usr/lib/python3.8/site-packages/regex/regex.py:348: in compile | |
return _compile(pattern, flags, ignore_unused, kwargs) | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
pattern = 'e(?P<episode>\\d{1,4})', flags = re.IGNORECASE, ignore_unused = False | |
kwargs = {'children': True, 'private_names': ['episodeSeparator', 'seasonSeparator'], 'private_parent': True, 'validate_all': True, ...} | |
def _compile(pattern, flags, ignore_unused, kwargs): | |
"Compiles a regular expression to a PatternObject." | |
global DEFAULT_VERSION | |
try: | |
from regex import DEFAULT_VERSION | |
except ImportError: | |
pass | |
# We won't bother to cache the pattern if we're debugging. | |
debugging = (flags & DEBUG) != 0 | |
# What locale is this pattern using? | |
locale_key = (type(pattern), pattern) | |
if _locale_sensitive.get(locale_key, True) or (flags & LOCALE) != 0: | |
# This pattern is, or might be, locale-sensitive. | |
pattern_locale = _getpreferredencoding() | |
else: | |
# This pattern is definitely not locale-sensitive. | |
pattern_locale = None | |
if not debugging: | |
try: | |
# Do we know what keyword arguments are needed? | |
args_key = pattern, type(pattern), flags | |
args_needed = _named_args[args_key] | |
# Are we being provided with its required keyword arguments? | |
args_supplied = set() | |
if args_needed: | |
for k, v in args_needed: | |
try: | |
args_supplied.add((k, frozenset(kwargs[k]))) | |
except KeyError: | |
raise error("missing named list: {!r}".format(k)) | |
args_supplied = frozenset(args_supplied) | |
# Have we already seen this regular expression and named list? | |
pattern_key = (pattern, type(pattern), flags, args_supplied, | |
DEFAULT_VERSION, pattern_locale) | |
return _cache[pattern_key] | |
except KeyError: | |
# It's a new pattern, or new named list for a known pattern. | |
pass | |
# Guess the encoding from the class of the pattern string. | |
if isinstance(pattern, str): | |
guess_encoding = UNICODE | |
elif isinstance(pattern, bytes): | |
guess_encoding = ASCII | |
elif isinstance(pattern, Pattern): | |
if flags: | |
raise ValueError("cannot process flags argument with a compiled pattern") | |
return pattern | |
else: | |
raise TypeError("first argument must be a string or compiled pattern") | |
# Set the default version in the core code in case it has been changed. | |
_regex_core.DEFAULT_VERSION = DEFAULT_VERSION | |
global_flags = flags | |
while True: | |
caught_exception = None | |
try: | |
source = _Source(pattern) | |
info = _Info(global_flags, source.char_type, kwargs) | |
info.guess_encoding = guess_encoding | |
source.ignore_space = bool(info.flags & VERBOSE) | |
parsed = _parse_pattern(source, info) | |
break | |
except _UnscopedFlagSet: | |
# Remember the global flags for the next attempt. | |
global_flags = info.global_flags | |
except error as e: | |
caught_exception = e | |
if caught_exception: | |
raise error(caught_exception.msg, caught_exception.pattern, | |
caught_exception.pos) | |
if not source.at_end(): | |
raise error("unbalanced parenthesis", pattern, source.pos) | |
# Check the global flags for conflicts. | |
version = (info.flags & _ALL_VERSIONS) or DEFAULT_VERSION | |
if version not in (0, VERSION0, VERSION1): | |
raise ValueError("VERSION0 and VERSION1 flags are mutually incompatible") | |
if (info.flags & _ALL_ENCODINGS) not in (0, ASCII, LOCALE, UNICODE): | |
raise ValueError("ASCII, LOCALE and UNICODE flags are mutually incompatible") | |
if isinstance(pattern, bytes) and (info.flags & UNICODE): | |
raise ValueError("cannot use UNICODE flag with a bytes pattern") | |
if not (info.flags & _ALL_ENCODINGS): | |
if isinstance(pattern, str): | |
info.flags |= UNICODE | |
else: | |
info.flags |= ASCII | |
reverse = bool(info.flags & REVERSE) | |
fuzzy = isinstance(parsed, _Fuzzy) | |
# Remember whether this pattern as an inline locale flag. | |
_locale_sensitive[locale_key] = info.inline_locale | |
# Fix the group references. | |
caught_exception = None | |
try: | |
parsed.fix_groups(pattern, reverse, False) | |
except error as e: | |
caught_exception = e | |
if caught_exception: | |
raise error(caught_exception.msg, caught_exception.pattern, | |
caught_exception.pos) | |
# Should we print the parsed pattern? | |
if flags & DEBUG: | |
parsed.dump(indent=0, reverse=reverse) | |
# Optimise the parsed pattern. | |
parsed = parsed.optimise(info, reverse) | |
parsed = parsed.pack_characters(info) | |
# Get the required string. | |
req_offset, req_chars, req_flags = _get_required_string(parsed, info.flags) | |
# Build the named lists. | |
named_lists = {} | |
named_list_indexes = [None] * len(info.named_lists_used) | |
args_needed = set() | |
for key, index in info.named_lists_used.items(): | |
name, case_flags = key | |
values = frozenset(kwargs[name]) | |
if case_flags: | |
items = frozenset(_fold_case(info, v) for v in values) | |
else: | |
items = values | |
named_lists[name] = values | |
named_list_indexes[index] = items | |
args_needed.add((name, values)) | |
# Any unused keyword arguments, possibly resulting from a typo? | |
unused_kwargs = set(kwargs) - set(named_lists) | |
if unused_kwargs and not ignore_unused: | |
any_one = next(iter(unused_kwargs)) | |
> raise ValueError('unused keyword argument {!a}'.format(any_one)) | |
E ValueError: unused keyword argument 'private_parent' | |
/usr/lib/python3.8/site-packages/regex/regex.py:585: ValueError | |
__________________________________________________________ test_matches_7 __________________________________________________________ | |
def test_matches_7(): | |
seps_surround = partial(chars_surround, ' .-/') | |
rebulk = Rebulk() | |
rebulk.regex_defaults(flags=re.IGNORECASE) | |
rebulk.defaults(children=True, private_parent=True) | |
> rebulk.chain(). \ | |
regex(r'S(?P<season>\d+)', validate_all=True, validator={'__parent__': seps_surround}). \ | |
regex(r'[ -](?P<season>\d+)', validator=seps_surround).repeater('*') | |
rebulk/test/test_chain.py:362: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
rebulk/builder.py:179: in regex | |
return self.pattern(self.build_re(*pattern, **kwargs)) | |
rebulk/builder.py:107: in build_re | |
return RePattern(*pattern, **kwargs) | |
rebulk/pattern.py:441: in __init__ | |
pattern = call(re.compile, pattern, **self._kwargs) | |
rebulk/loose.py:60: in call | |
return function(*call_args, **call_kwargs) | |
/usr/lib/python3.8/site-packages/regex/regex.py:348: in compile | |
return _compile(pattern, flags, ignore_unused, kwargs) | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
pattern = 'S(?P<season>\\d+)', flags = re.IGNORECASE, ignore_unused = False | |
kwargs = {'children': True, 'private_parent': True, 'validate_all': True, 'validator': {'__parent__': functools.partial(<function chars_surround at 0x7ff81b20f4c0>, ' .-/')}} | |
def _compile(pattern, flags, ignore_unused, kwargs): | |
"Compiles a regular expression to a PatternObject." | |
global DEFAULT_VERSION | |
try: | |
from regex import DEFAULT_VERSION | |
except ImportError: | |
pass | |
# We won't bother to cache the pattern if we're debugging. | |
debugging = (flags & DEBUG) != 0 | |
# What locale is this pattern using? | |
locale_key = (type(pattern), pattern) | |
if _locale_sensitive.get(locale_key, True) or (flags & LOCALE) != 0: | |
# This pattern is, or might be, locale-sensitive. | |
pattern_locale = _getpreferredencoding() | |
else: | |
# This pattern is definitely not locale-sensitive. | |
pattern_locale = None | |
if not debugging: | |
try: | |
# Do we know what keyword arguments are needed? | |
args_key = pattern, type(pattern), flags | |
args_needed = _named_args[args_key] | |
# Are we being provided with its required keyword arguments? | |
args_supplied = set() | |
if args_needed: | |
for k, v in args_needed: | |
try: | |
args_supplied.add((k, frozenset(kwargs[k]))) | |
except KeyError: | |
raise error("missing named list: {!r}".format(k)) | |
args_supplied = frozenset(args_supplied) | |
# Have we already seen this regular expression and named list? | |
pattern_key = (pattern, type(pattern), flags, args_supplied, | |
DEFAULT_VERSION, pattern_locale) | |
return _cache[pattern_key] | |
except KeyError: | |
# It's a new pattern, or new named list for a known pattern. | |
pass | |
# Guess the encoding from the class of the pattern string. | |
if isinstance(pattern, str): | |
guess_encoding = UNICODE | |
elif isinstance(pattern, bytes): | |
guess_encoding = ASCII | |
elif isinstance(pattern, Pattern): | |
if flags: | |
raise ValueError("cannot process flags argument with a compiled pattern") | |
return pattern | |
else: | |
raise TypeError("first argument must be a string or compiled pattern") | |
# Set the default version in the core code in case it has been changed. | |
_regex_core.DEFAULT_VERSION = DEFAULT_VERSION | |
global_flags = flags | |
while True: | |
caught_exception = None | |
try: | |
source = _Source(pattern) | |
info = _Info(global_flags, source.char_type, kwargs) | |
info.guess_encoding = guess_encoding | |
source.ignore_space = bool(info.flags & VERBOSE) | |
parsed = _parse_pattern(source, info) | |
break | |
except _UnscopedFlagSet: | |
# Remember the global flags for the next attempt. | |
global_flags = info.global_flags | |
except error as e: | |
caught_exception = e | |
if caught_exception: | |
raise error(caught_exception.msg, caught_exception.pattern, | |
caught_exception.pos) | |
if not source.at_end(): | |
raise error("unbalanced parenthesis", pattern, source.pos) | |
# Check the global flags for conflicts. | |
version = (info.flags & _ALL_VERSIONS) or DEFAULT_VERSION | |
if version not in (0, VERSION0, VERSION1): | |
raise ValueError("VERSION0 and VERSION1 flags are mutually incompatible") | |
if (info.flags & _ALL_ENCODINGS) not in (0, ASCII, LOCALE, UNICODE): | |
raise ValueError("ASCII, LOCALE and UNICODE flags are mutually incompatible") | |
if isinstance(pattern, bytes) and (info.flags & UNICODE): | |
raise ValueError("cannot use UNICODE flag with a bytes pattern") | |
if not (info.flags & _ALL_ENCODINGS): | |
if isinstance(pattern, str): | |
info.flags |= UNICODE | |
else: | |
info.flags |= ASCII | |
reverse = bool(info.flags & REVERSE) | |
fuzzy = isinstance(parsed, _Fuzzy) | |
# Remember whether this pattern as an inline locale flag. | |
_locale_sensitive[locale_key] = info.inline_locale | |
# Fix the group references. | |
caught_exception = None | |
try: | |
parsed.fix_groups(pattern, reverse, False) | |
except error as e: | |
caught_exception = e | |
if caught_exception: | |
raise error(caught_exception.msg, caught_exception.pattern, | |
caught_exception.pos) | |
# Should we print the parsed pattern? | |
if flags & DEBUG: | |
parsed.dump(indent=0, reverse=reverse) | |
# Optimise the parsed pattern. | |
parsed = parsed.optimise(info, reverse) | |
parsed = parsed.pack_characters(info) | |
# Get the required string. | |
req_offset, req_chars, req_flags = _get_required_string(parsed, info.flags) | |
# Build the named lists. | |
named_lists = {} | |
named_list_indexes = [None] * len(info.named_lists_used) | |
args_needed = set() | |
for key, index in info.named_lists_used.items(): | |
name, case_flags = key | |
values = frozenset(kwargs[name]) | |
if case_flags: | |
items = frozenset(_fold_case(info, v) for v in values) | |
else: | |
items = values | |
named_lists[name] = values | |
named_list_indexes[index] = items | |
args_needed.add((name, values)) | |
# Any unused keyword arguments, possibly resulting from a typo? | |
unused_kwargs = set(kwargs) - set(named_lists) | |
if unused_kwargs and not ignore_unused: | |
any_one = next(iter(unused_kwargs)) | |
> raise ValueError('unused keyword argument {!a}'.format(any_one)) | |
E ValueError: unused keyword argument 'private_parent' | |
/usr/lib/python3.8/site-packages/regex/regex.py:585: ValueError | |
________________________________________________________ test_chain_breaker ________________________________________________________ | |
def test_chain_breaker(): | |
def chain_breaker(matches): | |
seasons = matches.named('season') | |
if len(seasons) > 1: | |
if seasons[-1].value - seasons[-2].value > 10: | |
return True | |
return False | |
seps_surround = partial(chars_surround, ' .-/') | |
rebulk = Rebulk() | |
rebulk.regex_defaults(flags=re.IGNORECASE) | |
rebulk.defaults(children=True, private_parent=True, formatter={'season': int}) | |
> rebulk.chain(chain_breaker=chain_breaker). \ | |
regex(r'S(?P<season>\d+)', validate_all=True, validator={'__parent__': seps_surround}). \ | |
regex(r'[ -](?P<season>\d+)', validator=seps_surround).repeater('*') | |
rebulk/test/test_chain.py:404: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
rebulk/builder.py:179: in regex | |
return self.pattern(self.build_re(*pattern, **kwargs)) | |
rebulk/builder.py:107: in build_re | |
return RePattern(*pattern, **kwargs) | |
rebulk/pattern.py:441: in __init__ | |
pattern = call(re.compile, pattern, **self._kwargs) | |
rebulk/loose.py:60: in call | |
return function(*call_args, **call_kwargs) | |
/usr/lib/python3.8/site-packages/regex/regex.py:348: in compile | |
return _compile(pattern, flags, ignore_unused, kwargs) | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
pattern = 'S(?P<season>\\d+)', flags = re.IGNORECASE, ignore_unused = False | |
kwargs = {'children': True, 'formatter': {'season': <class 'int'>}, 'private_parent': True, 'validate_all': True, ...} | |
def _compile(pattern, flags, ignore_unused, kwargs): | |
"Compiles a regular expression to a PatternObject." | |
global DEFAULT_VERSION | |
try: | |
from regex import DEFAULT_VERSION | |
except ImportError: | |
pass | |
# We won't bother to cache the pattern if we're debugging. | |
debugging = (flags & DEBUG) != 0 | |
# What locale is this pattern using? | |
locale_key = (type(pattern), pattern) | |
if _locale_sensitive.get(locale_key, True) or (flags & LOCALE) != 0: | |
# This pattern is, or might be, locale-sensitive. | |
pattern_locale = _getpreferredencoding() | |
else: | |
# This pattern is definitely not locale-sensitive. | |
pattern_locale = None | |
if not debugging: | |
try: | |
# Do we know what keyword arguments are needed? | |
args_key = pattern, type(pattern), flags | |
args_needed = _named_args[args_key] | |
# Are we being provided with its required keyword arguments? | |
args_supplied = set() | |
if args_needed: | |
for k, v in args_needed: | |
try: | |
args_supplied.add((k, frozenset(kwargs[k]))) | |
except KeyError: | |
raise error("missing named list: {!r}".format(k)) | |
args_supplied = frozenset(args_supplied) | |
# Have we already seen this regular expression and named list? | |
pattern_key = (pattern, type(pattern), flags, args_supplied, | |
DEFAULT_VERSION, pattern_locale) | |
return _cache[pattern_key] | |
except KeyError: | |
# It's a new pattern, or new named list for a known pattern. | |
pass | |
# Guess the encoding from the class of the pattern string. | |
if isinstance(pattern, str): | |
guess_encoding = UNICODE | |
elif isinstance(pattern, bytes): | |
guess_encoding = ASCII | |
elif isinstance(pattern, Pattern): | |
if flags: | |
raise ValueError("cannot process flags argument with a compiled pattern") | |
return pattern | |
else: | |
raise TypeError("first argument must be a string or compiled pattern") | |
# Set the default version in the core code in case it has been changed. | |
_regex_core.DEFAULT_VERSION = DEFAULT_VERSION | |
global_flags = flags | |
while True: | |
caught_exception = None | |
try: | |
source = _Source(pattern) | |
info = _Info(global_flags, source.char_type, kwargs) | |
info.guess_encoding = guess_encoding | |
source.ignore_space = bool(info.flags & VERBOSE) | |
parsed = _parse_pattern(source, info) | |
break | |
except _UnscopedFlagSet: | |
# Remember the global flags for the next attempt. | |
global_flags = info.global_flags | |
except error as e: | |
caught_exception = e | |
if caught_exception: | |
raise error(caught_exception.msg, caught_exception.pattern, | |
caught_exception.pos) | |
if not source.at_end(): | |
raise error("unbalanced parenthesis", pattern, source.pos) | |
# Check the global flags for conflicts. | |
version = (info.flags & _ALL_VERSIONS) or DEFAULT_VERSION | |
if version not in (0, VERSION0, VERSION1): | |
raise ValueError("VERSION0 and VERSION1 flags are mutually incompatible") | |
if (info.flags & _ALL_ENCODINGS) not in (0, ASCII, LOCALE, UNICODE): | |
raise ValueError("ASCII, LOCALE and UNICODE flags are mutually incompatible") | |
if isinstance(pattern, bytes) and (info.flags & UNICODE): | |
raise ValueError("cannot use UNICODE flag with a bytes pattern") | |
if not (info.flags & _ALL_ENCODINGS): | |
if isinstance(pattern, str): | |
info.flags |= UNICODE | |
else: | |
info.flags |= ASCII | |
reverse = bool(info.flags & REVERSE) | |
fuzzy = isinstance(parsed, _Fuzzy) | |
# Remember whether this pattern as an inline locale flag. | |
_locale_sensitive[locale_key] = info.inline_locale | |
# Fix the group references. | |
caught_exception = None | |
try: | |
parsed.fix_groups(pattern, reverse, False) | |
except error as e: | |
caught_exception = e | |
if caught_exception: | |
raise error(caught_exception.msg, caught_exception.pattern, | |
caught_exception.pos) | |
# Should we print the parsed pattern? | |
if flags & DEBUG: | |
parsed.dump(indent=0, reverse=reverse) | |
# Optimise the parsed pattern. | |
parsed = parsed.optimise(info, reverse) | |
parsed = parsed.pack_characters(info) | |
# Get the required string. | |
req_offset, req_chars, req_flags = _get_required_string(parsed, info.flags) | |
# Build the named lists. | |
named_lists = {} | |
named_list_indexes = [None] * len(info.named_lists_used) | |
args_needed = set() | |
for key, index in info.named_lists_used.items(): | |
name, case_flags = key | |
values = frozenset(kwargs[name]) | |
if case_flags: | |
items = frozenset(_fold_case(info, v) for v in values) | |
else: | |
items = values | |
named_lists[name] = values | |
named_list_indexes[index] = items | |
args_needed.add((name, values)) | |
# Any unused keyword arguments, possibly resulting from a typo? | |
unused_kwargs = set(kwargs) - set(named_lists) | |
if unused_kwargs and not ignore_unused: | |
any_one = next(iter(unused_kwargs)) | |
> raise ValueError('unused keyword argument {!a}'.format(any_one)) | |
E ValueError: unused keyword argument 'private_parent' | |
/usr/lib/python3.8/site-packages/regex/regex.py:585: ValueError | |
___________________________________________________ test_chain_breaker_defaults ____________________________________________________ | |
def test_chain_breaker_defaults(): | |
def chain_breaker(matches): | |
seasons = matches.named('season') | |
if len(seasons) > 1: | |
if seasons[-1].value - seasons[-2].value > 10: | |
return True | |
return False | |
seps_surround = partial(chars_surround, ' .-/') | |
rebulk = Rebulk() | |
rebulk.regex_defaults(flags=re.IGNORECASE) | |
rebulk.defaults(chain_breaker=chain_breaker, children=True, private_parent=True, formatter={'season': int}) | |
> rebulk.chain(). \ | |
regex(r'S(?P<season>\d+)', validate_all=True, validator={'__parent__': seps_surround}). \ | |
regex(r'[ -](?P<season>\d+)', validator=seps_surround).repeater('*') | |
rebulk/test/test_chain.py:428: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
rebulk/builder.py:179: in regex | |
return self.pattern(self.build_re(*pattern, **kwargs)) | |
rebulk/builder.py:107: in build_re | |
return RePattern(*pattern, **kwargs) | |
rebulk/pattern.py:441: in __init__ | |
pattern = call(re.compile, pattern, **self._kwargs) | |
rebulk/loose.py:60: in call | |
return function(*call_args, **call_kwargs) | |
/usr/lib/python3.8/site-packages/regex/regex.py:348: in compile | |
return _compile(pattern, flags, ignore_unused, kwargs) | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
pattern = 'S(?P<season>\\d+)', flags = re.IGNORECASE, ignore_unused = False | |
kwargs = {'chain_breaker': <function test_chain_breaker_defaults.<locals>.chain_breaker at 0x7ff81afd9dc0>, 'children': True, 'formatter': {'season': <class 'int'>}, 'private_parent': True, ...} | |
def _compile(pattern, flags, ignore_unused, kwargs): | |
"Compiles a regular expression to a PatternObject." | |
global DEFAULT_VERSION | |
try: | |
from regex import DEFAULT_VERSION | |
except ImportError: | |
pass | |
# We won't bother to cache the pattern if we're debugging. | |
debugging = (flags & DEBUG) != 0 | |
# What locale is this pattern using? | |
locale_key = (type(pattern), pattern) | |
if _locale_sensitive.get(locale_key, True) or (flags & LOCALE) != 0: | |
# This pattern is, or might be, locale-sensitive. | |
pattern_locale = _getpreferredencoding() | |
else: | |
# This pattern is definitely not locale-sensitive. | |
pattern_locale = None | |
if not debugging: | |
try: | |
# Do we know what keyword arguments are needed? | |
args_key = pattern, type(pattern), flags | |
args_needed = _named_args[args_key] | |
# Are we being provided with its required keyword arguments? | |
args_supplied = set() | |
if args_needed: | |
for k, v in args_needed: | |
try: | |
args_supplied.add((k, frozenset(kwargs[k]))) | |
except KeyError: | |
raise error("missing named list: {!r}".format(k)) | |
args_supplied = frozenset(args_supplied) | |
# Have we already seen this regular expression and named list? | |
pattern_key = (pattern, type(pattern), flags, args_supplied, | |
DEFAULT_VERSION, pattern_locale) | |
return _cache[pattern_key] | |
except KeyError: | |
# It's a new pattern, or new named list for a known pattern. | |
pass | |
# Guess the encoding from the class of the pattern string. | |
if isinstance(pattern, str): | |
guess_encoding = UNICODE | |
elif isinstance(pattern, bytes): | |
guess_encoding = ASCII | |
elif isinstance(pattern, Pattern): | |
if flags: | |
raise ValueError("cannot process flags argument with a compiled pattern") | |
return pattern | |
else: | |
raise TypeError("first argument must be a string or compiled pattern") | |
# Set the default version in the core code in case it has been changed. | |
_regex_core.DEFAULT_VERSION = DEFAULT_VERSION | |
global_flags = flags | |
while True: | |
caught_exception = None | |
try: | |
source = _Source(pattern) | |
info = _Info(global_flags, source.char_type, kwargs) | |
info.guess_encoding = guess_encoding | |
source.ignore_space = bool(info.flags & VERBOSE) | |
parsed = _parse_pattern(source, info) | |
break | |
except _UnscopedFlagSet: | |
# Remember the global flags for the next attempt. | |
global_flags = info.global_flags | |
except error as e: | |
caught_exception = e | |
if caught_exception: | |
raise error(caught_exception.msg, caught_exception.pattern, | |
caught_exception.pos) | |
if not source.at_end(): | |
raise error("unbalanced parenthesis", pattern, source.pos) | |
# Check the global flags for conflicts. | |
version = (info.flags & _ALL_VERSIONS) or DEFAULT_VERSION | |
if version not in (0, VERSION0, VERSION1): | |
raise ValueError("VERSION0 and VERSION1 flags are mutually incompatible") | |
if (info.flags & _ALL_ENCODINGS) not in (0, ASCII, LOCALE, UNICODE): | |
raise ValueError("ASCII, LOCALE and UNICODE flags are mutually incompatible") | |
if isinstance(pattern, bytes) and (info.flags & UNICODE): | |
raise ValueError("cannot use UNICODE flag with a bytes pattern") | |
if not (info.flags & _ALL_ENCODINGS): | |
if isinstance(pattern, str): | |
info.flags |= UNICODE | |
else: | |
info.flags |= ASCII | |
reverse = bool(info.flags & REVERSE) | |
fuzzy = isinstance(parsed, _Fuzzy) | |
# Remember whether this pattern as an inline locale flag. | |
_locale_sensitive[locale_key] = info.inline_locale | |
# Fix the group references. | |
caught_exception = None | |
try: | |
parsed.fix_groups(pattern, reverse, False) | |
except error as e: | |
caught_exception = e | |
if caught_exception: | |
raise error(caught_exception.msg, caught_exception.pattern, | |
caught_exception.pos) | |
# Should we print the parsed pattern? | |
if flags & DEBUG: | |
parsed.dump(indent=0, reverse=reverse) | |
# Optimise the parsed pattern. | |
parsed = parsed.optimise(info, reverse) | |
parsed = parsed.pack_characters(info) | |
# Get the required string. | |
req_offset, req_chars, req_flags = _get_required_string(parsed, info.flags) | |
# Build the named lists. | |
named_lists = {} | |
named_list_indexes = [None] * len(info.named_lists_used) | |
args_needed = set() | |
for key, index in info.named_lists_used.items(): | |
name, case_flags = key | |
values = frozenset(kwargs[name]) | |
if case_flags: | |
items = frozenset(_fold_case(info, v) for v in values) | |
else: | |
items = values | |
named_lists[name] = values | |
named_list_indexes[index] = items | |
args_needed.add((name, values)) | |
# Any unused keyword arguments, possibly resulting from a typo? | |
unused_kwargs = set(kwargs) - set(named_lists) | |
if unused_kwargs and not ignore_unused: | |
any_one = next(iter(unused_kwargs)) | |
> raise ValueError('unused keyword argument {!a}'.format(any_one)) | |
E ValueError: unused keyword argument 'private_parent' | |
/usr/lib/python3.8/site-packages/regex/regex.py:585: ValueError | |
___________________________________________________ test_chain_breaker_defaults2 ___________________________________________________ | |
def test_chain_breaker_defaults2(): | |
def chain_breaker(matches): | |
seasons = matches.named('season') | |
if len(seasons) > 1: | |
if seasons[-1].value - seasons[-2].value > 10: | |
return True | |
return False | |
seps_surround = partial(chars_surround, ' .-/') | |
rebulk = Rebulk() | |
rebulk.regex_defaults(flags=re.IGNORECASE) | |
rebulk.chain_defaults(chain_breaker=chain_breaker) | |
rebulk.defaults(children=True, private_parent=True, formatter={'season': int}) | |
> rebulk.chain(). \ | |
regex(r'S(?P<season>\d+)', validate_all=True, validator={'__parent__': seps_surround}). \ | |
regex(r'[ -](?P<season>\d+)', validator=seps_surround).repeater('*') | |
rebulk/test/test_chain.py:453: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
rebulk/builder.py:179: in regex | |
return self.pattern(self.build_re(*pattern, **kwargs)) | |
rebulk/builder.py:107: in build_re | |
return RePattern(*pattern, **kwargs) | |
rebulk/pattern.py:441: in __init__ | |
pattern = call(re.compile, pattern, **self._kwargs) | |
rebulk/loose.py:60: in call | |
return function(*call_args, **call_kwargs) | |
/usr/lib/python3.8/site-packages/regex/regex.py:348: in compile | |
return _compile(pattern, flags, ignore_unused, kwargs) | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
pattern = 'S(?P<season>\\d+)', flags = re.IGNORECASE, ignore_unused = False | |
kwargs = {'children': True, 'formatter': {'season': <class 'int'>}, 'private_parent': True, 'validate_all': True, ...} | |
def _compile(pattern, flags, ignore_unused, kwargs): | |
"Compiles a regular expression to a PatternObject." | |
global DEFAULT_VERSION | |
try: | |
from regex import DEFAULT_VERSION | |
except ImportError: | |
pass | |
# We won't bother to cache the pattern if we're debugging. | |
debugging = (flags & DEBUG) != 0 | |
# What locale is this pattern using? | |
locale_key = (type(pattern), pattern) | |
if _locale_sensitive.get(locale_key, True) or (flags & LOCALE) != 0: | |
# This pattern is, or might be, locale-sensitive. | |
pattern_locale = _getpreferredencoding() | |
else: | |
# This pattern is definitely not locale-sensitive. | |
pattern_locale = None | |
if not debugging: | |
try: | |
# Do we know what keyword arguments are needed? | |
args_key = pattern, type(pattern), flags | |
args_needed = _named_args[args_key] | |
# Are we being provided with its required keyword arguments? | |
args_supplied = set() | |
if args_needed: | |
for k, v in args_needed: | |
try: | |
args_supplied.add((k, frozenset(kwargs[k]))) | |
except KeyError: | |
raise error("missing named list: {!r}".format(k)) | |
args_supplied = frozenset(args_supplied) | |
# Have we already seen this regular expression and named list? | |
pattern_key = (pattern, type(pattern), flags, args_supplied, | |
DEFAULT_VERSION, pattern_locale) | |
return _cache[pattern_key] | |
except KeyError: | |
# It's a new pattern, or new named list for a known pattern. | |
pass | |
# Guess the encoding from the class of the pattern string. | |
if isinstance(pattern, str): | |
guess_encoding = UNICODE | |
elif isinstance(pattern, bytes): | |
guess_encoding = ASCII | |
elif isinstance(pattern, Pattern): | |
if flags: | |
raise ValueError("cannot process flags argument with a compiled pattern") | |
return pattern | |
else: | |
raise TypeError("first argument must be a string or compiled pattern") | |
# Set the default version in the core code in case it has been changed. | |
_regex_core.DEFAULT_VERSION = DEFAULT_VERSION | |
global_flags = flags | |
while True: | |
caught_exception = None | |
try: | |
source = _Source(pattern) | |
info = _Info(global_flags, source.char_type, kwargs) | |
info.guess_encoding = guess_encoding | |
source.ignore_space = bool(info.flags & VERBOSE) | |
parsed = _parse_pattern(source, info) | |
break | |
except _UnscopedFlagSet: | |
# Remember the global flags for the next attempt. | |
global_flags = info.global_flags | |
except error as e: | |
caught_exception = e | |
if caught_exception: | |
raise error(caught_exception.msg, caught_exception.pattern, | |
caught_exception.pos) | |
if not source.at_end(): | |
raise error("unbalanced parenthesis", pattern, source.pos) | |
# Check the global flags for conflicts. | |
version = (info.flags & _ALL_VERSIONS) or DEFAULT_VERSION | |
if version not in (0, VERSION0, VERSION1): | |
raise ValueError("VERSION0 and VERSION1 flags are mutually incompatible") | |
if (info.flags & _ALL_ENCODINGS) not in (0, ASCII, LOCALE, UNICODE): | |
raise ValueError("ASCII, LOCALE and UNICODE flags are mutually incompatible") | |
if isinstance(pattern, bytes) and (info.flags & UNICODE): | |
raise ValueError("cannot use UNICODE flag with a bytes pattern") | |
if not (info.flags & _ALL_ENCODINGS): | |
if isinstance(pattern, str): | |
info.flags |= UNICODE | |
else: | |
info.flags |= ASCII | |
reverse = bool(info.flags & REVERSE) | |
fuzzy = isinstance(parsed, _Fuzzy) | |
# Remember whether this pattern as an inline locale flag. | |
_locale_sensitive[locale_key] = info.inline_locale | |
# Fix the group references. | |
caught_exception = None | |
try: | |
parsed.fix_groups(pattern, reverse, False) | |
except error as e: | |
caught_exception = e | |
if caught_exception: | |
raise error(caught_exception.msg, caught_exception.pattern, | |
caught_exception.pos) | |
# Should we print the parsed pattern? | |
if flags & DEBUG: | |
parsed.dump(indent=0, reverse=reverse) | |
# Optimise the parsed pattern. | |
parsed = parsed.optimise(info, reverse) | |
parsed = parsed.pack_characters(info) | |
# Get the required string. | |
req_offset, req_chars, req_flags = _get_required_string(parsed, info.flags) | |
# Build the named lists. | |
named_lists = {} | |
named_list_indexes = [None] * len(info.named_lists_used) | |
args_needed = set() | |
for key, index in info.named_lists_used.items(): | |
name, case_flags = key | |
values = frozenset(kwargs[name]) | |
if case_flags: | |
items = frozenset(_fold_case(info, v) for v in values) | |
else: | |
items = values | |
named_lists[name] = values | |
named_list_indexes[index] = items | |
args_needed.add((name, values)) | |
# Any unused keyword arguments, possibly resulting from a typo? | |
unused_kwargs = set(kwargs) - set(named_lists) | |
if unused_kwargs and not ignore_unused: | |
any_one = next(iter(unused_kwargs)) | |
> raise ValueError('unused keyword argument {!a}'.format(any_one)) | |
E ValueError: unused keyword argument 'private_parent' | |
/usr/lib/python3.8/site-packages/regex/regex.py:585: ValueError | |
_______________________________________________________ test_various_pattern _______________________________________________________ | |
def test_various_pattern(): | |
> rebulk = Rebulk()\ | |
.regex('One', 'Two', 'Three', name='first', value="string") \ | |
.string('1', '2', '3', name='second', value="digit") \ | |
.string('4', '5', '6', name='third') \ | |
.string('private', private=True) \ | |
.functional(lambda string: (0, 5), name='func', value='test') \ | |
.regex('One', 'Two', 'Three', name='regex_name') \ | |
.regex('(?P<one>One)(?P<two>Two)(?P<three>Three)') \ | |
.functional(lambda string: (6, 10), name='func2') \ | |
.string('7', name='third') | |
rebulk/test/test_introspector.py:57: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
rebulk/builder.py:179: in regex | |
return self.pattern(self.build_re(*pattern, **kwargs)) | |
rebulk/builder.py:107: in build_re | |
return RePattern(*pattern, **kwargs) | |
rebulk/pattern.py:441: in __init__ | |
pattern = call(re.compile, pattern, **self._kwargs) | |
rebulk/loose.py:60: in call | |
return function(*call_args, **call_kwargs) | |
/usr/lib/python3.8/site-packages/regex/regex.py:348: in compile | |
return _compile(pattern, flags, ignore_unused, kwargs) | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
pattern = 'One', flags = 0, ignore_unused = False, kwargs = {'name': 'first', 'value': 'string'} | |
def _compile(pattern, flags, ignore_unused, kwargs): | |
"Compiles a regular expression to a PatternObject." | |
global DEFAULT_VERSION | |
try: | |
from regex import DEFAULT_VERSION | |
except ImportError: | |
pass | |
# We won't bother to cache the pattern if we're debugging. | |
debugging = (flags & DEBUG) != 0 | |
# What locale is this pattern using? | |
locale_key = (type(pattern), pattern) | |
if _locale_sensitive.get(locale_key, True) or (flags & LOCALE) != 0: | |
# This pattern is, or might be, locale-sensitive. | |
pattern_locale = _getpreferredencoding() | |
else: | |
# This pattern is definitely not locale-sensitive. | |
pattern_locale = None | |
if not debugging: | |
try: | |
# Do we know what keyword arguments are needed? | |
args_key = pattern, type(pattern), flags | |
args_needed = _named_args[args_key] | |
# Are we being provided with its required keyword arguments? | |
args_supplied = set() | |
if args_needed: | |
for k, v in args_needed: | |
try: | |
args_supplied.add((k, frozenset(kwargs[k]))) | |
except KeyError: | |
raise error("missing named list: {!r}".format(k)) | |
args_supplied = frozenset(args_supplied) | |
# Have we already seen this regular expression and named list? | |
pattern_key = (pattern, type(pattern), flags, args_supplied, | |
DEFAULT_VERSION, pattern_locale) | |
return _cache[pattern_key] | |
except KeyError: | |
# It's a new pattern, or new named list for a known pattern. | |
pass | |
# Guess the encoding from the class of the pattern string. | |
if isinstance(pattern, str): | |
guess_encoding = UNICODE | |
elif isinstance(pattern, bytes): | |
guess_encoding = ASCII | |
elif isinstance(pattern, Pattern): | |
if flags: | |
raise ValueError("cannot process flags argument with a compiled pattern") | |
return pattern | |
else: | |
raise TypeError("first argument must be a string or compiled pattern") | |
# Set the default version in the core code in case it has been changed. | |
_regex_core.DEFAULT_VERSION = DEFAULT_VERSION | |
global_flags = flags | |
while True: | |
caught_exception = None | |
try: | |
source = _Source(pattern) | |
info = _Info(global_flags, source.char_type, kwargs) | |
info.guess_encoding = guess_encoding | |
source.ignore_space = bool(info.flags & VERBOSE) | |
parsed = _parse_pattern(source, info) | |
break | |
except _UnscopedFlagSet: | |
# Remember the global flags for the next attempt. | |
global_flags = info.global_flags | |
except error as e: | |
caught_exception = e | |
if caught_exception: | |
raise error(caught_exception.msg, caught_exception.pattern, | |
caught_exception.pos) | |
if not source.at_end(): | |
raise error("unbalanced parenthesis", pattern, source.pos) | |
# Check the global flags for conflicts. | |
version = (info.flags & _ALL_VERSIONS) or DEFAULT_VERSION | |
if version not in (0, VERSION0, VERSION1): | |
raise ValueError("VERSION0 and VERSION1 flags are mutually incompatible") | |
if (info.flags & _ALL_ENCODINGS) not in (0, ASCII, LOCALE, UNICODE): | |
raise ValueError("ASCII, LOCALE and UNICODE flags are mutually incompatible") | |
if isinstance(pattern, bytes) and (info.flags & UNICODE): | |
raise ValueError("cannot use UNICODE flag with a bytes pattern") | |
if not (info.flags & _ALL_ENCODINGS): | |
if isinstance(pattern, str): | |
info.flags |= UNICODE | |
else: | |
info.flags |= ASCII | |
reverse = bool(info.flags & REVERSE) | |
fuzzy = isinstance(parsed, _Fuzzy) | |
# Remember whether this pattern as an inline locale flag. | |
_locale_sensitive[locale_key] = info.inline_locale | |
# Fix the group references. | |
caught_exception = None | |
try: | |
parsed.fix_groups(pattern, reverse, False) | |
except error as e: | |
caught_exception = e | |
if caught_exception: | |
raise error(caught_exception.msg, caught_exception.pattern, | |
caught_exception.pos) | |
# Should we print the parsed pattern? | |
if flags & DEBUG: | |
parsed.dump(indent=0, reverse=reverse) | |
# Optimise the parsed pattern. | |
parsed = parsed.optimise(info, reverse) | |
parsed = parsed.pack_characters(info) | |
# Get the required string. | |
req_offset, req_chars, req_flags = _get_required_string(parsed, info.flags) | |
# Build the named lists. | |
named_lists = {} | |
named_list_indexes = [None] * len(info.named_lists_used) | |
args_needed = set() | |
for key, index in info.named_lists_used.items(): | |
name, case_flags = key | |
values = frozenset(kwargs[name]) | |
if case_flags: | |
items = frozenset(_fold_case(info, v) for v in values) | |
else: | |
items = values | |
named_lists[name] = values | |
named_list_indexes[index] = items | |
args_needed.add((name, values)) | |
# Any unused keyword arguments, possibly resulting from a typo? | |
unused_kwargs = set(kwargs) - set(named_lists) | |
if unused_kwargs and not ignore_unused: | |
any_one = next(iter(unused_kwargs)) | |
> raise ValueError('unused keyword argument {!a}'.format(any_one)) | |
E ValueError: unused keyword argument 'value' | |
/usr/lib/python3.8/site-packages/regex/regex.py:585: ValueError | |
______________________________________________________ TestMaches.test_names _______________________________________________________ | |
self = <rebulk.test.test_match.TestMaches object at 0x7ff81aee1fd0> | |
def test_names(self): | |
input_string = "One Two Three" | |
matches = Matches() | |
matches.extend(StringPattern("One", name="1-str", tags=["One", "str"]).matches(input_string)) | |
> matches.extend(RePattern("One", name="1-re", tags=["One", "re"]).matches(input_string)) | |
rebulk/test/test_match.py:314: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
rebulk/pattern.py:441: in __init__ | |
pattern = call(re.compile, pattern, **self._kwargs) | |
rebulk/loose.py:60: in call | |
return function(*call_args, **call_kwargs) | |
/usr/lib/python3.8/site-packages/regex/regex.py:348: in compile | |
return _compile(pattern, flags, ignore_unused, kwargs) | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
pattern = 'One', flags = 0, ignore_unused = False, kwargs = {'name': '1-re', 'tags': ['One', 're']} | |
def _compile(pattern, flags, ignore_unused, kwargs): | |
"Compiles a regular expression to a PatternObject." | |
global DEFAULT_VERSION | |
try: | |
from regex import DEFAULT_VERSION | |
except ImportError: | |
pass | |
# We won't bother to cache the pattern if we're debugging. | |
debugging = (flags & DEBUG) != 0 | |
# What locale is this pattern using? | |
locale_key = (type(pattern), pattern) | |
if _locale_sensitive.get(locale_key, True) or (flags & LOCALE) != 0: | |
# This pattern is, or might be, locale-sensitive. | |
pattern_locale = _getpreferredencoding() | |
else: | |
# This pattern is definitely not locale-sensitive. | |
pattern_locale = None | |
if not debugging: | |
try: | |
# Do we know what keyword arguments are needed? | |
args_key = pattern, type(pattern), flags | |
args_needed = _named_args[args_key] | |
# Are we being provided with its required keyword arguments? | |
args_supplied = set() | |
if args_needed: | |
for k, v in args_needed: | |
try: | |
args_supplied.add((k, frozenset(kwargs[k]))) | |
except KeyError: | |
raise error("missing named list: {!r}".format(k)) | |
args_supplied = frozenset(args_supplied) | |
# Have we already seen this regular expression and named list? | |
pattern_key = (pattern, type(pattern), flags, args_supplied, | |
DEFAULT_VERSION, pattern_locale) | |
return _cache[pattern_key] | |
except KeyError: | |
# It's a new pattern, or new named list for a known pattern. | |
pass | |
# Guess the encoding from the class of the pattern string. | |
if isinstance(pattern, str): | |
guess_encoding = UNICODE | |
elif isinstance(pattern, bytes): | |
guess_encoding = ASCII | |
elif isinstance(pattern, Pattern): | |
if flags: | |
raise ValueError("cannot process flags argument with a compiled pattern") | |
return pattern | |
else: | |
raise TypeError("first argument must be a string or compiled pattern") | |
# Set the default version in the core code in case it has been changed. | |
_regex_core.DEFAULT_VERSION = DEFAULT_VERSION | |
global_flags = flags | |
while True: | |
caught_exception = None | |
try: | |
source = _Source(pattern) | |
info = _Info(global_flags, source.char_type, kwargs) | |
info.guess_encoding = guess_encoding | |
source.ignore_space = bool(info.flags & VERBOSE) | |
parsed = _parse_pattern(source, info) | |
break | |
except _UnscopedFlagSet: | |
# Remember the global flags for the next attempt. | |
global_flags = info.global_flags | |
except error as e: | |
caught_exception = e | |
if caught_exception: | |
raise error(caught_exception.msg, caught_exception.pattern, | |
caught_exception.pos) | |
if not source.at_end(): | |
raise error("unbalanced parenthesis", pattern, source.pos) | |
# Check the global flags for conflicts. | |
version = (info.flags & _ALL_VERSIONS) or DEFAULT_VERSION | |
if version not in (0, VERSION0, VERSION1): | |
raise ValueError("VERSION0 and VERSION1 flags are mutually incompatible") | |
if (info.flags & _ALL_ENCODINGS) not in (0, ASCII, LOCALE, UNICODE): | |
raise ValueError("ASCII, LOCALE and UNICODE flags are mutually incompatible") | |
if isinstance(pattern, bytes) and (info.flags & UNICODE): | |
raise ValueError("cannot use UNICODE flag with a bytes pattern") | |
if not (info.flags & _ALL_ENCODINGS): | |
if isinstance(pattern, str): | |
info.flags |= UNICODE | |
else: | |
info.flags |= ASCII | |
reverse = bool(info.flags & REVERSE) | |
fuzzy = isinstance(parsed, _Fuzzy) | |
# Remember whether this pattern as an inline locale flag. | |
_locale_sensitive[locale_key] = info.inline_locale | |
# Fix the group references. | |
caught_exception = None | |
try: | |
parsed.fix_groups(pattern, reverse, False) | |
except error as e: | |
caught_exception = e | |
if caught_exception: | |
raise error(caught_exception.msg, caught_exception.pattern, | |
caught_exception.pos) | |
# Should we print the parsed pattern? | |
if flags & DEBUG: | |
parsed.dump(indent=0, reverse=reverse) | |
# Optimise the parsed pattern. | |
parsed = parsed.optimise(info, reverse) | |
parsed = parsed.pack_characters(info) | |
# Get the required string. | |
req_offset, req_chars, req_flags = _get_required_string(parsed, info.flags) | |
# Build the named lists. | |
named_lists = {} | |
named_list_indexes = [None] * len(info.named_lists_used) | |
args_needed = set() | |
for key, index in info.named_lists_used.items(): | |
name, case_flags = key | |
values = frozenset(kwargs[name]) | |
if case_flags: | |
items = frozenset(_fold_case(info, v) for v in values) | |
else: | |
items = values | |
named_lists[name] = values | |
named_list_indexes[index] = items | |
args_needed.add((name, values)) | |
# Any unused keyword arguments, possibly resulting from a typo? | |
unused_kwargs = set(kwargs) - set(named_lists) | |
if unused_kwargs and not ignore_unused: | |
any_one = next(iter(unused_kwargs)) | |
> raise ValueError('unused keyword argument {!a}'.format(any_one)) | |
E ValueError: unused keyword argument 'tags' | |
/usr/lib/python3.8/site-packages/regex/regex.py:585: ValueError | |
_____________________________________________________ TestMaches.test_filters ______________________________________________________ | |
self = <rebulk.test.test_match.TestMaches object at 0x7ff81afa7850> | |
def test_filters(self): | |
input_string = "One Two Three" | |
matches = Matches() | |
matches.extend(StringPattern("One", name="1-str", tags=["One", "str"]).matches(input_string)) | |
> matches.extend(RePattern("One", name="1-re", tags=["One", "re"]).matches(input_string)) | |
rebulk/test/test_match.py:328: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
rebulk/pattern.py:441: in __init__ | |
pattern = call(re.compile, pattern, **self._kwargs) | |
rebulk/loose.py:60: in call | |
return function(*call_args, **call_kwargs) | |
/usr/lib/python3.8/site-packages/regex/regex.py:348: in compile | |
return _compile(pattern, flags, ignore_unused, kwargs) | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
pattern = 'One', flags = 0, ignore_unused = False, kwargs = {'name': '1-re', 'tags': ['One', 're']} | |
def _compile(pattern, flags, ignore_unused, kwargs): | |
"Compiles a regular expression to a PatternObject." | |
global DEFAULT_VERSION | |
try: | |
from regex import DEFAULT_VERSION | |
except ImportError: | |
pass | |
# We won't bother to cache the pattern if we're debugging. | |
debugging = (flags & DEBUG) != 0 | |
# What locale is this pattern using? | |
locale_key = (type(pattern), pattern) | |
if _locale_sensitive.get(locale_key, True) or (flags & LOCALE) != 0: | |
# This pattern is, or might be, locale-sensitive. | |
pattern_locale = _getpreferredencoding() | |
else: | |
# This pattern is definitely not locale-sensitive. | |
pattern_locale = None | |
if not debugging: | |
try: | |
# Do we know what keyword arguments are needed? | |
args_key = pattern, type(pattern), flags | |
args_needed = _named_args[args_key] | |
# Are we being provided with its required keyword arguments? | |
args_supplied = set() | |
if args_needed: | |
for k, v in args_needed: | |
try: | |
args_supplied.add((k, frozenset(kwargs[k]))) | |
except KeyError: | |
raise error("missing named list: {!r}".format(k)) | |
args_supplied = frozenset(args_supplied) | |
# Have we already seen this regular expression and named list? | |
pattern_key = (pattern, type(pattern), flags, args_supplied, | |
DEFAULT_VERSION, pattern_locale) | |
return _cache[pattern_key] | |
except KeyError: | |
# It's a new pattern, or new named list for a known pattern. | |
pass | |
# Guess the encoding from the class of the pattern string. | |
if isinstance(pattern, str): | |
guess_encoding = UNICODE | |
elif isinstance(pattern, bytes): | |
guess_encoding = ASCII | |
elif isinstance(pattern, Pattern): | |
if flags: | |
raise ValueError("cannot process flags argument with a compiled pattern") | |
return pattern | |
else: | |
raise TypeError("first argument must be a string or compiled pattern") | |
# Set the default version in the core code in case it has been changed. | |
_regex_core.DEFAULT_VERSION = DEFAULT_VERSION | |
global_flags = flags | |
while True: | |
caught_exception = None | |
try: | |
source = _Source(pattern) | |
info = _Info(global_flags, source.char_type, kwargs) | |
info.guess_encoding = guess_encoding | |
source.ignore_space = bool(info.flags & VERBOSE) | |
parsed = _parse_pattern(source, info) | |
break | |
except _UnscopedFlagSet: | |
# Remember the global flags for the next attempt. | |
global_flags = info.global_flags | |
except error as e: | |
caught_exception = e | |
if caught_exception: | |
raise error(caught_exception.msg, caught_exception.pattern, | |
caught_exception.pos) | |
if not source.at_end(): | |
raise error("unbalanced parenthesis", pattern, source.pos) | |
# Check the global flags for conflicts. | |
version = (info.flags & _ALL_VERSIONS) or DEFAULT_VERSION | |
if version not in (0, VERSION0, VERSION1): | |
raise ValueError("VERSION0 and VERSION1 flags are mutually incompatible") | |
if (info.flags & _ALL_ENCODINGS) not in (0, ASCII, LOCALE, UNICODE): | |
raise ValueError("ASCII, LOCALE and UNICODE flags are mutually incompatible") | |
if isinstance(pattern, bytes) and (info.flags & UNICODE): | |
raise ValueError("cannot use UNICODE flag with a bytes pattern") | |
if not (info.flags & _ALL_ENCODINGS): | |
if isinstance(pattern, str): | |
info.flags |= UNICODE | |
else: | |
info.flags |= ASCII | |
reverse = bool(info.flags & REVERSE) | |
fuzzy = isinstance(parsed, _Fuzzy) | |
# Remember whether this pattern as an inline locale flag. | |
_locale_sensitive[locale_key] = info.inline_locale | |
# Fix the group references. | |
caught_exception = None | |
try: | |
parsed.fix_groups(pattern, reverse, False) | |
except error as e: | |
caught_exception = e | |
if caught_exception: | |
raise error(caught_exception.msg, caught_exception.pattern, | |
caught_exception.pos) | |
# Should we print the parsed pattern? | |
if flags & DEBUG: | |
parsed.dump(indent=0, reverse=reverse) | |
# Optimise the parsed pattern. | |
parsed = parsed.optimise(info, reverse) | |
parsed = parsed.pack_characters(info) | |
# Get the required string. | |
req_offset, req_chars, req_flags = _get_required_string(parsed, info.flags) | |
# Build the named lists. | |
named_lists = {} | |
named_list_indexes = [None] * len(info.named_lists_used) | |
args_needed = set() | |
for key, index in info.named_lists_used.items(): | |
name, case_flags = key | |
values = frozenset(kwargs[name]) | |
if case_flags: | |
items = frozenset(_fold_case(info, v) for v in values) | |
else: | |
items = values | |
named_lists[name] = values | |
named_list_indexes[index] = items | |
args_needed.add((name, values)) | |
# Any unused keyword arguments, possibly resulting from a typo? | |
unused_kwargs = set(kwargs) - set(named_lists) | |
if unused_kwargs and not ignore_unused: | |
any_one = next(iter(unused_kwargs)) | |
> raise ValueError('unused keyword argument {!a}'.format(any_one)) | |
E ValueError: unused keyword argument 'tags' | |
/usr/lib/python3.8/site-packages/regex/regex.py:585: ValueError | |
_____________________________________________________ TestMaches.test_to_dict ______________________________________________________ | |
self = <rebulk.test.test_match.TestMaches object at 0x7ff81ab686a0> | |
def test_to_dict(self): | |
input_string = "One Two Two Three" | |
matches = Matches() | |
matches.extend(StringPattern("One", name="1", tags=["One", "str"]).matches(input_string)) | |
> matches.extend(RePattern("One", name="1", tags=["One", "re"]).matches(input_string)) | |
rebulk/test/test_match.py:417: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
rebulk/pattern.py:441: in __init__ | |
pattern = call(re.compile, pattern, **self._kwargs) | |
rebulk/loose.py:60: in call | |
return function(*call_args, **call_kwargs) | |
/usr/lib/python3.8/site-packages/regex/regex.py:348: in compile | |
return _compile(pattern, flags, ignore_unused, kwargs) | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
pattern = 'One', flags = 0, ignore_unused = False, kwargs = {'name': '1', 'tags': ['One', 're']} | |
def _compile(pattern, flags, ignore_unused, kwargs): | |
"Compiles a regular expression to a PatternObject." | |
global DEFAULT_VERSION | |
try: | |
from regex import DEFAULT_VERSION | |
except ImportError: | |
pass | |
# We won't bother to cache the pattern if we're debugging. | |
debugging = (flags & DEBUG) != 0 | |
# What locale is this pattern using? | |
locale_key = (type(pattern), pattern) | |
if _locale_sensitive.get(locale_key, True) or (flags & LOCALE) != 0: | |
# This pattern is, or might be, locale-sensitive. | |
pattern_locale = _getpreferredencoding() | |
else: | |
# This pattern is definitely not locale-sensitive. | |
pattern_locale = None | |
if not debugging: | |
try: | |
# Do we know what keyword arguments are needed? | |
args_key = pattern, type(pattern), flags | |
args_needed = _named_args[args_key] | |
# Are we being provided with its required keyword arguments? | |
args_supplied = set() | |
if args_needed: | |
for k, v in args_needed: | |
try: | |
args_supplied.add((k, frozenset(kwargs[k]))) | |
except KeyError: | |
raise error("missing named list: {!r}".format(k)) | |
args_supplied = frozenset(args_supplied) | |
# Have we already seen this regular expression and named list? | |
pattern_key = (pattern, type(pattern), flags, args_supplied, | |
DEFAULT_VERSION, pattern_locale) | |
return _cache[pattern_key] | |
except KeyError: | |
# It's a new pattern, or new named list for a known pattern. | |
pass | |
# Guess the encoding from the class of the pattern string. | |
if isinstance(pattern, str): | |
guess_encoding = UNICODE | |
elif isinstance(pattern, bytes): | |
guess_encoding = ASCII | |
elif isinstance(pattern, Pattern): | |
if flags: | |
raise ValueError("cannot process flags argument with a compiled pattern") | |
return pattern | |
else: | |
raise TypeError("first argument must be a string or compiled pattern") | |
# Set the default version in the core code in case it has been changed. | |
_regex_core.DEFAULT_VERSION = DEFAULT_VERSION | |
global_flags = flags | |
while True: | |
caught_exception = None | |
try: | |
source = _Source(pattern) | |
info = _Info(global_flags, source.char_type, kwargs) | |
info.guess_encoding = guess_encoding | |
source.ignore_space = bool(info.flags & VERBOSE) | |
parsed = _parse_pattern(source, info) | |
break | |
except _UnscopedFlagSet: | |
# Remember the global flags for the next attempt. | |
global_flags = info.global_flags | |
except error as e: | |
caught_exception = e | |
if caught_exception: | |
raise error(caught_exception.msg, caught_exception.pattern, | |
caught_exception.pos) | |
if not source.at_end(): | |
raise error("unbalanced parenthesis", pattern, source.pos) | |
# Check the global flags for conflicts. | |
version = (info.flags & _ALL_VERSIONS) or DEFAULT_VERSION | |
if version not in (0, VERSION0, VERSION1): | |
raise ValueError("VERSION0 and VERSION1 flags are mutually incompatible") | |
if (info.flags & _ALL_ENCODINGS) not in (0, ASCII, LOCALE, UNICODE): | |
raise ValueError("ASCII, LOCALE and UNICODE flags are mutually incompatible") | |
if isinstance(pattern, bytes) and (info.flags & UNICODE): | |
raise ValueError("cannot use UNICODE flag with a bytes pattern") | |
if not (info.flags & _ALL_ENCODINGS): | |
if isinstance(pattern, str): | |
info.flags |= UNICODE | |
else: | |
info.flags |= ASCII | |
reverse = bool(info.flags & REVERSE) | |
fuzzy = isinstance(parsed, _Fuzzy) | |
# Remember whether this pattern as an inline locale flag. | |
_locale_sensitive[locale_key] = info.inline_locale | |
# Fix the group references. | |
caught_exception = None | |
try: | |
parsed.fix_groups(pattern, reverse, False) | |
except error as e: | |
caught_exception = e | |
if caught_exception: | |
raise error(caught_exception.msg, caught_exception.pattern, | |
caught_exception.pos) | |
# Should we print the parsed pattern? | |
if flags & DEBUG: | |
parsed.dump(indent=0, reverse=reverse) | |
# Optimise the parsed pattern. | |
parsed = parsed.optimise(info, reverse) | |
parsed = parsed.pack_characters(info) | |
# Get the required string. | |
req_offset, req_chars, req_flags = _get_required_string(parsed, info.flags) | |
# Build the named lists. | |
named_lists = {} | |
named_list_indexes = [None] * len(info.named_lists_used) | |
args_needed = set() | |
for key, index in info.named_lists_used.items(): | |
name, case_flags = key | |
values = frozenset(kwargs[name]) | |
if case_flags: | |
items = frozenset(_fold_case(info, v) for v in values) | |
else: | |
items = values | |
named_lists[name] = values | |
named_list_indexes[index] = items | |
args_needed.add((name, values)) | |
# Any unused keyword arguments, possibly resulting from a typo? | |
unused_kwargs = set(kwargs) - set(named_lists) | |
if unused_kwargs and not ignore_unused: | |
any_one = next(iter(unused_kwargs)) | |
> raise ValueError('unused keyword argument {!a}'.format(any_one)) | |
E ValueError: unused keyword argument 'tags' | |
/usr/lib/python3.8/site-packages/regex/regex.py:585: ValueError | |
______________________________________________________ TestMaches.test_chains ______________________________________________________ | |
self = <rebulk.test.test_match.TestMaches object at 0x7ff81abfc7c0> | |
def test_chains(self): | |
input_string = "wordX 10 20 30 40 wordA, wordB, wordC 70 80 wordX" | |
matches = Matches(input_string=input_string) | |
> matches.extend(RePattern(r"\d+", name="digit").matches(input_string)) | |
rebulk/test/test_match.py:473: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
rebulk/pattern.py:441: in __init__ | |
pattern = call(re.compile, pattern, **self._kwargs) | |
rebulk/loose.py:60: in call | |
return function(*call_args, **call_kwargs) | |
/usr/lib/python3.8/site-packages/regex/regex.py:348: in compile | |
return _compile(pattern, flags, ignore_unused, kwargs) | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
pattern = '\\d+', flags = 0, ignore_unused = False, kwargs = {'name': 'digit'} | |
def _compile(pattern, flags, ignore_unused, kwargs): | |
"Compiles a regular expression to a PatternObject." | |
global DEFAULT_VERSION | |
try: | |
from regex import DEFAULT_VERSION | |
except ImportError: | |
pass | |
# We won't bother to cache the pattern if we're debugging. | |
debugging = (flags & DEBUG) != 0 | |
# What locale is this pattern using? | |
locale_key = (type(pattern), pattern) | |
if _locale_sensitive.get(locale_key, True) or (flags & LOCALE) != 0: | |
# This pattern is, or might be, locale-sensitive. | |
pattern_locale = _getpreferredencoding() | |
else: | |
# This pattern is definitely not locale-sensitive. | |
pattern_locale = None | |
if not debugging: | |
try: | |
# Do we know what keyword arguments are needed? | |
args_key = pattern, type(pattern), flags | |
args_needed = _named_args[args_key] | |
# Are we being provided with its required keyword arguments? | |
args_supplied = set() | |
if args_needed: | |
for k, v in args_needed: | |
try: | |
args_supplied.add((k, frozenset(kwargs[k]))) | |
except KeyError: | |
raise error("missing named list: {!r}".format(k)) | |
args_supplied = frozenset(args_supplied) | |
# Have we already seen this regular expression and named list? | |
pattern_key = (pattern, type(pattern), flags, args_supplied, | |
DEFAULT_VERSION, pattern_locale) | |
return _cache[pattern_key] | |
except KeyError: | |
# It's a new pattern, or new named list for a known pattern. | |
pass | |
# Guess the encoding from the class of the pattern string. | |
if isinstance(pattern, str): | |
guess_encoding = UNICODE | |
elif isinstance(pattern, bytes): | |
guess_encoding = ASCII | |
elif isinstance(pattern, Pattern): | |
if flags: | |
raise ValueError("cannot process flags argument with a compiled pattern") | |
return pattern | |
else: | |
raise TypeError("first argument must be a string or compiled pattern") | |
# Set the default version in the core code in case it has been changed. | |
_regex_core.DEFAULT_VERSION = DEFAULT_VERSION | |
global_flags = flags | |
while True: | |
caught_exception = None | |
try: | |
source = _Source(pattern) | |
info = _Info(global_flags, source.char_type, kwargs) | |
info.guess_encoding = guess_encoding | |
source.ignore_space = bool(info.flags & VERBOSE) | |
parsed = _parse_pattern(source, info) | |
break | |
except _UnscopedFlagSet: | |
# Remember the global flags for the next attempt. | |
global_flags = info.global_flags | |
except error as e: | |
caught_exception = e | |
if caught_exception: | |
raise error(caught_exception.msg, caught_exception.pattern, | |
caught_exception.pos) | |
if not source.at_end(): | |
raise error("unbalanced parenthesis", pattern, source.pos) | |
# Check the global flags for conflicts. | |
version = (info.flags & _ALL_VERSIONS) or DEFAULT_VERSION | |
if version not in (0, VERSION0, VERSION1): | |
raise ValueError("VERSION0 and VERSION1 flags are mutually incompatible") | |
if (info.flags & _ALL_ENCODINGS) not in (0, ASCII, LOCALE, UNICODE): | |
raise ValueError("ASCII, LOCALE and UNICODE flags are mutually incompatible") | |
if isinstance(pattern, bytes) and (info.flags & UNICODE): | |
raise ValueError("cannot use UNICODE flag with a bytes pattern") | |
if not (info.flags & _ALL_ENCODINGS): | |
if isinstance(pattern, str): | |
info.flags |= UNICODE | |
else: | |
info.flags |= ASCII | |
reverse = bool(info.flags & REVERSE) | |
fuzzy = isinstance(parsed, _Fuzzy) | |
# Remember whether this pattern as an inline locale flag. | |
_locale_sensitive[locale_key] = info.inline_locale | |
# Fix the group references. | |
caught_exception = None | |
try: | |
parsed.fix_groups(pattern, reverse, False) | |
except error as e: | |
caught_exception = e | |
if caught_exception: | |
raise error(caught_exception.msg, caught_exception.pattern, | |
caught_exception.pos) | |
# Should we print the parsed pattern? | |
if flags & DEBUG: | |
parsed.dump(indent=0, reverse=reverse) | |
# Optimise the parsed pattern. | |
parsed = parsed.optimise(info, reverse) | |
parsed = parsed.pack_characters(info) | |
# Get the required string. | |
req_offset, req_chars, req_flags = _get_required_string(parsed, info.flags) | |
# Build the named lists. | |
named_lists = {} | |
named_list_indexes = [None] * len(info.named_lists_used) | |
args_needed = set() | |
for key, index in info.named_lists_used.items(): | |
name, case_flags = key | |
values = frozenset(kwargs[name]) | |
if case_flags: | |
items = frozenset(_fold_case(info, v) for v in values) | |
else: | |
items = values | |
named_lists[name] = values | |
named_list_indexes[index] = items | |
args_needed.add((name, values)) | |
# Any unused keyword arguments, possibly resulting from a typo? | |
unused_kwargs = set(kwargs) - set(named_lists) | |
if unused_kwargs and not ignore_unused: | |
any_one = next(iter(unused_kwargs)) | |
> raise ValueError('unused keyword argument {!a}'.format(any_one)) | |
E ValueError: unused keyword argument 'name' | |
/usr/lib/python3.8/site-packages/regex/regex.py:585: ValueError | |
___________________________________________________ TestRePattern.test_shortcuts ___________________________________________________ | |
self = <rebulk.test.test_pattern.TestRePattern object at 0x7ff81ab2a8e0> | |
def test_shortcuts(self): | |
> pattern = RePattern("Celtic-violin", abbreviations=[("-", r"[\W_]+")]) | |
rebulk/test/test_pattern.py:168: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
rebulk/pattern.py:441: in __init__ | |
pattern = call(re.compile, pattern, **self._kwargs) | |
rebulk/loose.py:60: in call | |
return function(*call_args, **call_kwargs) | |
/usr/lib/python3.8/site-packages/regex/regex.py:348: in compile | |
return _compile(pattern, flags, ignore_unused, kwargs) | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
pattern = 'Celtic[\\W_]+violin', flags = 0, ignore_unused = False, kwargs = {'abbreviations': [('-', '[\\W_]+')]} | |
def _compile(pattern, flags, ignore_unused, kwargs): | |
"Compiles a regular expression to a PatternObject." | |
global DEFAULT_VERSION | |
try: | |
from regex import DEFAULT_VERSION | |
except ImportError: | |
pass | |
# We won't bother to cache the pattern if we're debugging. | |
debugging = (flags & DEBUG) != 0 | |
# What locale is this pattern using? | |
locale_key = (type(pattern), pattern) | |
if _locale_sensitive.get(locale_key, True) or (flags & LOCALE) != 0: | |
# This pattern is, or might be, locale-sensitive. | |
pattern_locale = _getpreferredencoding() | |
else: | |
# This pattern is definitely not locale-sensitive. | |
pattern_locale = None | |
if not debugging: | |
try: | |
# Do we know what keyword arguments are needed? | |
args_key = pattern, type(pattern), flags | |
args_needed = _named_args[args_key] | |
# Are we being provided with its required keyword arguments? | |
args_supplied = set() | |
if args_needed: | |
for k, v in args_needed: | |
try: | |
args_supplied.add((k, frozenset(kwargs[k]))) | |
except KeyError: | |
raise error("missing named list: {!r}".format(k)) | |
args_supplied = frozenset(args_supplied) | |
# Have we already seen this regular expression and named list? | |
pattern_key = (pattern, type(pattern), flags, args_supplied, | |
DEFAULT_VERSION, pattern_locale) | |
return _cache[pattern_key] | |
except KeyError: | |
# It's a new pattern, or new named list for a known pattern. | |
pass | |
# Guess the encoding from the class of the pattern string. | |
if isinstance(pattern, str): | |
guess_encoding = UNICODE | |
elif isinstance(pattern, bytes): | |
guess_encoding = ASCII | |
elif isinstance(pattern, Pattern): | |
if flags: | |
raise ValueError("cannot process flags argument with a compiled pattern") | |
return pattern | |
else: | |
raise TypeError("first argument must be a string or compiled pattern") | |
# Set the default version in the core code in case it has been changed. | |
_regex_core.DEFAULT_VERSION = DEFAULT_VERSION | |
global_flags = flags | |
while True: | |
caught_exception = None | |
try: | |
source = _Source(pattern) | |
info = _Info(global_flags, source.char_type, kwargs) | |
info.guess_encoding = guess_encoding | |
source.ignore_space = bool(info.flags & VERBOSE) | |
parsed = _parse_pattern(source, info) | |
break | |
except _UnscopedFlagSet: | |
# Remember the global flags for the next attempt. | |
global_flags = info.global_flags | |
except error as e: | |
caught_exception = e | |
if caught_exception: | |
raise error(caught_exception.msg, caught_exception.pattern, | |
caught_exception.pos) | |
if not source.at_end(): | |
raise error("unbalanced parenthesis", pattern, source.pos) | |
# Check the global flags for conflicts. | |
version = (info.flags & _ALL_VERSIONS) or DEFAULT_VERSION | |
if version not in (0, VERSION0, VERSION1): | |
raise ValueError("VERSION0 and VERSION1 flags are mutually incompatible") | |
if (info.flags & _ALL_ENCODINGS) not in (0, ASCII, LOCALE, UNICODE): | |
raise ValueError("ASCII, LOCALE and UNICODE flags are mutually incompatible") | |
if isinstance(pattern, bytes) and (info.flags & UNICODE): | |
raise ValueError("cannot use UNICODE flag with a bytes pattern") | |
if not (info.flags & _ALL_ENCODINGS): | |
if isinstance(pattern, str): | |
info.flags |= UNICODE | |
else: | |
info.flags |= ASCII | |
reverse = bool(info.flags & REVERSE) | |
fuzzy = isinstance(parsed, _Fuzzy) | |
# Remember whether this pattern as an inline locale flag. | |
_locale_sensitive[locale_key] = info.inline_locale | |
# Fix the group references. | |
caught_exception = None | |
try: | |
parsed.fix_groups(pattern, reverse, False) | |
except error as e: | |
caught_exception = e | |
if caught_exception: | |
raise error(caught_exception.msg, caught_exception.pattern, | |
caught_exception.pos) | |
# Should we print the parsed pattern? | |
if flags & DEBUG: | |
parsed.dump(indent=0, reverse=reverse) | |
# Optimise the parsed pattern. | |
parsed = parsed.optimise(info, reverse) | |
parsed = parsed.pack_characters(info) | |
# Get the required string. | |
req_offset, req_chars, req_flags = _get_required_string(parsed, info.flags) | |
# Build the named lists. | |
named_lists = {} | |
named_list_indexes = [None] * len(info.named_lists_used) | |
args_needed = set() | |
for key, index in info.named_lists_used.items(): | |
name, case_flags = key | |
values = frozenset(kwargs[name]) | |
if case_flags: | |
items = frozenset(_fold_case(info, v) for v in values) | |
else: | |
items = values | |
named_lists[name] = values | |
named_list_indexes[index] = items | |
args_needed.add((name, values)) | |
# Any unused keyword arguments, possibly resulting from a typo? | |
unused_kwargs = set(kwargs) - set(named_lists) | |
if unused_kwargs and not ignore_unused: | |
any_one = next(iter(unused_kwargs)) | |
> raise ValueError('unused keyword argument {!a}'.format(any_one)) | |
E ValueError: unused keyword argument 'abbreviations' | |
/usr/lib/python3.8/site-packages/regex/regex.py:585: ValueError | |
________________________________________________ TestRePattern.test_matches_kwargs _________________________________________________ | |
self = <rebulk.test.test_pattern.TestRePattern object at 0x7ff81ab14730> | |
def test_matches_kwargs(self): | |
> pattern = RePattern("He.rew", name="test", value="HE") | |
rebulk/test/test_pattern.py:383: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
rebulk/pattern.py:441: in __init__ | |
pattern = call(re.compile, pattern, **self._kwargs) | |
rebulk/loose.py:60: in call | |
return function(*call_args, **call_kwargs) | |
/usr/lib/python3.8/site-packages/regex/regex.py:348: in compile | |
return _compile(pattern, flags, ignore_unused, kwargs) | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
pattern = 'He.rew', flags = 0, ignore_unused = False, kwargs = {'name': 'test', 'value': 'HE'} | |
def _compile(pattern, flags, ignore_unused, kwargs): | |
"Compiles a regular expression to a PatternObject." | |
global DEFAULT_VERSION | |
try: | |
from regex import DEFAULT_VERSION | |
except ImportError: | |
pass | |
# We won't bother to cache the pattern if we're debugging. | |
debugging = (flags & DEBUG) != 0 | |
# What locale is this pattern using? | |
locale_key = (type(pattern), pattern) | |
if _locale_sensitive.get(locale_key, True) or (flags & LOCALE) != 0: | |
# This pattern is, or might be, locale-sensitive. | |
pattern_locale = _getpreferredencoding() | |
else: | |
# This pattern is definitely not locale-sensitive. | |
pattern_locale = None | |
if not debugging: | |
try: | |
# Do we know what keyword arguments are needed? | |
args_key = pattern, type(pattern), flags | |
args_needed = _named_args[args_key] | |
# Are we being provided with its required keyword arguments? | |
args_supplied = set() | |
if args_needed: | |
for k, v in args_needed: | |
try: | |
args_supplied.add((k, frozenset(kwargs[k]))) | |
except KeyError: | |
raise error("missing named list: {!r}".format(k)) | |
args_supplied = frozenset(args_supplied) | |
# Have we already seen this regular expression and named list? | |
pattern_key = (pattern, type(pattern), flags, args_supplied, | |
DEFAULT_VERSION, pattern_locale) | |
return _cache[pattern_key] | |
except KeyError: | |
# It's a new pattern, or new named list for a known pattern. | |
pass | |
# Guess the encoding from the class of the pattern string. | |
if isinstance(pattern, str): | |
guess_encoding = UNICODE | |
elif isinstance(pattern, bytes): | |
guess_encoding = ASCII | |
elif isinstance(pattern, Pattern): | |
if flags: | |
raise ValueError("cannot process flags argument with a compiled pattern") | |
return pattern | |
else: | |
raise TypeError("first argument must be a string or compiled pattern") | |
# Set the default version in the core code in case it has been changed. | |
_regex_core.DEFAULT_VERSION = DEFAULT_VERSION | |
global_flags = flags | |
while True: | |
caught_exception = None | |
try: | |
source = _Source(pattern) | |
info = _Info(global_flags, source.char_type, kwargs) | |
info.guess_encoding = guess_encoding | |
source.ignore_space = bool(info.flags & VERBOSE) | |
parsed = _parse_pattern(source, info) | |
break | |
except _UnscopedFlagSet: | |
# Remember the global flags for the next attempt. | |
global_flags = info.global_flags | |
except error as e: | |
caught_exception = e | |
if caught_exception: | |
raise error(caught_exception.msg, caught_exception.pattern, | |
caught_exception.pos) | |
if not source.at_end(): | |
raise error("unbalanced parenthesis", pattern, source.pos) | |
# Check the global flags for conflicts. | |
version = (info.flags & _ALL_VERSIONS) or DEFAULT_VERSION | |
if version not in (0, VERSION0, VERSION1): | |
raise ValueError("VERSION0 and VERSION1 flags are mutually incompatible") | |
if (info.flags & _ALL_ENCODINGS) not in (0, ASCII, LOCALE, UNICODE): | |
raise ValueError("ASCII, LOCALE and UNICODE flags are mutually incompatible") | |
if isinstance(pattern, bytes) and (info.flags & UNICODE): | |
raise ValueError("cannot use UNICODE flag with a bytes pattern") | |
if not (info.flags & _ALL_ENCODINGS): | |
if isinstance(pattern, str): | |
info.flags |= UNICODE | |
else: | |
info.flags |= ASCII | |
reverse = bool(info.flags & REVERSE) | |
fuzzy = isinstance(parsed, _Fuzzy) | |
# Remember whether this pattern as an inline locale flag. | |
_locale_sensitive[locale_key] = info.inline_locale | |
# Fix the group references. | |
caught_exception = None | |
try: | |
parsed.fix_groups(pattern, reverse, False) | |
except error as e: | |
caught_exception = e | |
if caught_exception: | |
raise error(caught_exception.msg, caught_exception.pattern, | |
caught_exception.pos) | |
# Should we print the parsed pattern? | |
if flags & DEBUG: | |
parsed.dump(indent=0, reverse=reverse) | |
# Optimise the parsed pattern. | |
parsed = parsed.optimise(info, reverse) | |
parsed = parsed.pack_characters(info) | |
# Get the required string. | |
req_offset, req_chars, req_flags = _get_required_string(parsed, info.flags) | |
# Build the named lists. | |
named_lists = {} | |
named_list_indexes = [None] * len(info.named_lists_used) | |
args_needed = set() | |
for key, index in info.named_lists_used.items(): | |
name, case_flags = key | |
values = frozenset(kwargs[name]) | |
if case_flags: | |
items = frozenset(_fold_case(info, v) for v in values) | |
else: | |
items = values | |
named_lists[name] = values | |
named_list_indexes[index] = items | |
args_needed.add((name, values)) | |
# Any unused keyword arguments, possibly resulting from a typo? | |
unused_kwargs = set(kwargs) - set(named_lists) | |
if unused_kwargs and not ignore_unused: | |
any_one = next(iter(unused_kwargs)) | |
> raise ValueError('unused keyword argument {!a}'.format(any_one)) | |
E ValueError: unused keyword argument 'value' | |
/usr/lib/python3.8/site-packages/regex/regex.py:585: ValueError | |
_________________________________________________ TestValue.test_dict_child_value __________________________________________________ | |
self = <rebulk.test.test_pattern.TestValue object at 0x7ff81ab2c340> | |
def test_dict_child_value(self): | |
> pattern = RePattern(r"(?P<strParam>cont.?ins)\s+(?P<intParam>\d+)", | |
formatter={'intParam': lambda x: int(x) * 2, | |
'strParam': lambda x: "really " + x}, | |
format_all=True, | |
value={'intParam': 'INT_PARAM_VALUE'}) | |
rebulk/test/test_pattern.py:601: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
rebulk/pattern.py:441: in __init__ | |
pattern = call(re.compile, pattern, **self._kwargs) | |
rebulk/loose.py:60: in call | |
return function(*call_args, **call_kwargs) | |
/usr/lib/python3.8/site-packages/regex/regex.py:348: in compile | |
return _compile(pattern, flags, ignore_unused, kwargs) | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
pattern = '(?P<strParam>cont.?ins)\\s+(?P<intParam>\\d+)', flags = 0, ignore_unused = False | |
kwargs = {'format_all': True, 'formatter': {'intParam': <function TestValue.test_dict_child_value.<locals>.<lambda> at 0x7ff81a...nction TestValue.test_dict_child_value.<locals>.<lambda> at 0x7ff81aab1b80>}, 'value': {'intParam': 'INT_PARAM_VALUE'}} | |
def _compile(pattern, flags, ignore_unused, kwargs): | |
"Compiles a regular expression to a PatternObject." | |
global DEFAULT_VERSION | |
try: | |
from regex import DEFAULT_VERSION | |
except ImportError: | |
pass | |
# We won't bother to cache the pattern if we're debugging. | |
debugging = (flags & DEBUG) != 0 | |
# What locale is this pattern using? | |
locale_key = (type(pattern), pattern) | |
if _locale_sensitive.get(locale_key, True) or (flags & LOCALE) != 0: | |
# This pattern is, or might be, locale-sensitive. | |
pattern_locale = _getpreferredencoding() | |
else: | |
# This pattern is definitely not locale-sensitive. | |
pattern_locale = None | |
if not debugging: | |
try: | |
# Do we know what keyword arguments are needed? | |
args_key = pattern, type(pattern), flags | |
args_needed = _named_args[args_key] | |
# Are we being provided with its required keyword arguments? | |
args_supplied = set() | |
if args_needed: | |
for k, v in args_needed: | |
try: | |
args_supplied.add((k, frozenset(kwargs[k]))) | |
except KeyError: | |
raise error("missing named list: {!r}".format(k)) | |
args_supplied = frozenset(args_supplied) | |
# Have we already seen this regular expression and named list? | |
pattern_key = (pattern, type(pattern), flags, args_supplied, | |
DEFAULT_VERSION, pattern_locale) | |
return _cache[pattern_key] | |
except KeyError: | |
# It's a new pattern, or new named list for a known pattern. | |
pass | |
# Guess the encoding from the class of the pattern string. | |
if isinstance(pattern, str): | |
guess_encoding = UNICODE | |
elif isinstance(pattern, bytes): | |
guess_encoding = ASCII | |
elif isinstance(pattern, Pattern): | |
if flags: | |
raise ValueError("cannot process flags argument with a compiled pattern") | |
return pattern | |
else: | |
raise TypeError("first argument must be a string or compiled pattern") | |
# Set the default version in the core code in case it has been changed. | |
_regex_core.DEFAULT_VERSION = DEFAULT_VERSION | |
global_flags = flags | |
while True: | |
caught_exception = None | |
try: | |
source = _Source(pattern) | |
info = _Info(global_flags, source.char_type, kwargs) | |
info.guess_encoding = guess_encoding | |
source.ignore_space = bool(info.flags & VERBOSE) | |
parsed = _parse_pattern(source, info) | |
break | |
except _UnscopedFlagSet: | |
# Remember the global flags for the next attempt. | |
global_flags = info.global_flags | |
except error as e: | |
caught_exception = e | |
if caught_exception: | |
raise error(caught_exception.msg, caught_exception.pattern, | |
caught_exception.pos) | |
if not source.at_end(): | |
raise error("unbalanced parenthesis", pattern, source.pos) | |
# Check the global flags for conflicts. | |
version = (info.flags & _ALL_VERSIONS) or DEFAULT_VERSION | |
if version not in (0, VERSION0, VERSION1): | |
raise ValueError("VERSION0 and VERSION1 flags are mutually incompatible") | |
if (info.flags & _ALL_ENCODINGS) not in (0, ASCII, LOCALE, UNICODE): | |
raise ValueError("ASCII, LOCALE and UNICODE flags are mutually incompatible") | |
if isinstance(pattern, bytes) and (info.flags & UNICODE): | |
raise ValueError("cannot use UNICODE flag with a bytes pattern") | |
if not (info.flags & _ALL_ENCODINGS): | |
if isinstance(pattern, str): | |
info.flags |= UNICODE | |
else: | |
info.flags |= ASCII | |
reverse = bool(info.flags & REVERSE) | |
fuzzy = isinstance(parsed, _Fuzzy) | |
# Remember whether this pattern as an inline locale flag. | |
_locale_sensitive[locale_key] = info.inline_locale | |
# Fix the group references. | |
caught_exception = None | |
try: | |
parsed.fix_groups(pattern, reverse, False) | |
except error as e: | |
caught_exception = e | |
if caught_exception: | |
raise error(caught_exception.msg, caught_exception.pattern, | |
caught_exception.pos) | |
# Should we print the parsed pattern? | |
if flags & DEBUG: | |
parsed.dump(indent=0, reverse=reverse) | |
# Optimise the parsed pattern. | |
parsed = parsed.optimise(info, reverse) | |
parsed = parsed.pack_characters(info) | |
# Get the required string. | |
req_offset, req_chars, req_flags = _get_required_string(parsed, info.flags) | |
# Build the named lists. | |
named_lists = {} | |
named_list_indexes = [None] * len(info.named_lists_used) | |
args_needed = set() | |
for key, index in info.named_lists_used.items(): | |
name, case_flags = key | |
values = frozenset(kwargs[name]) | |
if case_flags: | |
items = frozenset(_fold_case(info, v) for v in values) | |
else: | |
items = values | |
named_lists[name] = values | |
named_list_indexes[index] = items | |
args_needed.add((name, values)) | |
# Any unused keyword arguments, possibly resulting from a typo? | |
unused_kwargs = set(kwargs) - set(named_lists) | |
if unused_kwargs and not ignore_unused: | |
any_one = next(iter(unused_kwargs)) | |
> raise ValueError('unused keyword argument {!a}'.format(any_one)) | |
E ValueError: unused keyword argument 'formatter' | |
/usr/lib/python3.8/site-packages/regex/regex.py:585: ValueError | |
________________________________________________ TestValue.test_dict_default_value _________________________________________________ | |
self = <rebulk.test.test_pattern.TestValue object at 0x7ff81ab299a0> | |
def test_dict_default_value(self): | |
> pattern = RePattern(r"(?P<strParam>cont.?ins)\s+(?P<intParam>\d+)", | |
formatter={'intParam': lambda x: int(x) * 2, | |
'strParam': lambda x: "really " + x}, | |
format_all=True, | |
value={'__children__': 'CHILD', 'strParam': 'STR_VALUE', '__parent__': 'PARENT'}) | |
rebulk/test/test_pattern.py:626: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
rebulk/pattern.py:441: in __init__ | |
pattern = call(re.compile, pattern, **self._kwargs) | |
rebulk/loose.py:60: in call | |
return function(*call_args, **call_kwargs) | |
/usr/lib/python3.8/site-packages/regex/regex.py:348: in compile | |
return _compile(pattern, flags, ignore_unused, kwargs) | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
pattern = '(?P<strParam>cont.?ins)\\s+(?P<intParam>\\d+)', flags = 0, ignore_unused = False | |
kwargs = {'format_all': True, 'formatter': {'intParam': <function TestValue.test_dict_default_value.<locals>.<lambda> at 0x7ff8...als>.<lambda> at 0x7ff81afbd790>}, 'value': {'__children__': 'CHILD', '__parent__': 'PARENT', 'strParam': 'STR_VALUE'}} | |
def _compile(pattern, flags, ignore_unused, kwargs): | |
"Compiles a regular expression to a PatternObject." | |
global DEFAULT_VERSION | |
try: | |
from regex import DEFAULT_VERSION | |
except ImportError: | |
pass | |
# We won't bother to cache the pattern if we're debugging. | |
debugging = (flags & DEBUG) != 0 | |
# What locale is this pattern using? | |
locale_key = (type(pattern), pattern) | |
if _locale_sensitive.get(locale_key, True) or (flags & LOCALE) != 0: | |
# This pattern is, or might be, locale-sensitive. | |
pattern_locale = _getpreferredencoding() | |
else: | |
# This pattern is definitely not locale-sensitive. | |
pattern_locale = None | |
if not debugging: | |
try: | |
# Do we know what keyword arguments are needed? | |
args_key = pattern, type(pattern), flags | |
args_needed = _named_args[args_key] | |
# Are we being provided with its required keyword arguments? | |
args_supplied = set() | |
if args_needed: | |
for k, v in args_needed: | |
try: | |
args_supplied.add((k, frozenset(kwargs[k]))) | |
except KeyError: | |
raise error("missing named list: {!r}".format(k)) | |
args_supplied = frozenset(args_supplied) | |
# Have we already seen this regular expression and named list? | |
pattern_key = (pattern, type(pattern), flags, args_supplied, | |
DEFAULT_VERSION, pattern_locale) | |
return _cache[pattern_key] | |
except KeyError: | |
# It's a new pattern, or new named list for a known pattern. | |
pass | |
# Guess the encoding from the class of the pattern string. | |
if isinstance(pattern, str): | |
guess_encoding = UNICODE | |
elif isinstance(pattern, bytes): | |
guess_encoding = ASCII | |
elif isinstance(pattern, Pattern): | |
if flags: | |
raise ValueError("cannot process flags argument with a compiled pattern") | |
return pattern | |
else: | |
raise TypeError("first argument must be a string or compiled pattern") | |
# Set the default version in the core code in case it has been changed. | |
_regex_core.DEFAULT_VERSION = DEFAULT_VERSION | |
global_flags = flags | |
while True: | |
caught_exception = None | |
try: | |
source = _Source(pattern) | |
info = _Info(global_flags, source.char_type, kwargs) | |
info.guess_encoding = guess_encoding | |
source.ignore_space = bool(info.flags & VERBOSE) | |
parsed = _parse_pattern(source, info) | |
break | |
except _UnscopedFlagSet: | |
# Remember the global flags for the next attempt. | |
global_flags = info.global_flags | |
except error as e: | |
caught_exception = e | |
if caught_exception: | |
raise error(caught_exception.msg, caught_exception.pattern, | |
caught_exception.pos) | |
if not source.at_end(): | |
raise error("unbalanced parenthesis", pattern, source.pos) | |
# Check the global flags for conflicts. | |
version = (info.flags & _ALL_VERSIONS) or DEFAULT_VERSION | |
if version not in (0, VERSION0, VERSION1): | |
raise ValueError("VERSION0 and VERSION1 flags are mutually incompatible") | |
if (info.flags & _ALL_ENCODINGS) not in (0, ASCII, LOCALE, UNICODE): | |
raise ValueError("ASCII, LOCALE and UNICODE flags are mutually incompatible") | |
if isinstance(pattern, bytes) and (info.flags & UNICODE): | |
raise ValueError("cannot use UNICODE flag with a bytes pattern") | |
if not (info.flags & _ALL_ENCODINGS): | |
if isinstance(pattern, str): | |
info.flags |= UNICODE | |
else: | |
info.flags |= ASCII | |
reverse = bool(info.flags & REVERSE) | |
fuzzy = isinstance(parsed, _Fuzzy) | |
# Remember whether this pattern as an inline locale flag. | |
_locale_sensitive[locale_key] = info.inline_locale | |
# Fix the group references. | |
caught_exception = None | |
try: | |
parsed.fix_groups(pattern, reverse, False) | |
except error as e: | |
caught_exception = e | |
if caught_exception: | |
raise error(caught_exception.msg, caught_exception.pattern, | |
caught_exception.pos) | |
# Should we print the parsed pattern? | |
if flags & DEBUG: | |
parsed.dump(indent=0, reverse=reverse) | |
# Optimise the parsed pattern. | |
parsed = parsed.optimise(info, reverse) | |
parsed = parsed.pack_characters(info) | |
# Get the required string. | |
req_offset, req_chars, req_flags = _get_required_string(parsed, info.flags) | |
# Build the named lists. | |
named_lists = {} | |
named_list_indexes = [None] * len(info.named_lists_used) | |
args_needed = set() | |
for key, index in info.named_lists_used.items(): | |
name, case_flags = key | |
values = frozenset(kwargs[name]) | |
if case_flags: | |
items = frozenset(_fold_case(info, v) for v in values) | |
else: | |
items = values | |
named_lists[name] = values | |
named_list_indexes[index] = items | |
args_needed.add((name, values)) | |
# Any unused keyword arguments, possibly resulting from a typo? | |
unused_kwargs = set(kwargs) - set(named_lists) | |
if unused_kwargs and not ignore_unused: | |
any_one = next(iter(unused_kwargs)) | |
> raise ValueError('unused keyword argument {!a}'.format(any_one)) | |
E ValueError: unused keyword argument 'formatter' | |
/usr/lib/python3.8/site-packages/regex/regex.py:585: ValueError | |
______________________________________________ TestFormatter.test_single_re_no_group _______________________________________________ | |
self = <rebulk.test.test_pattern.TestFormatter object at 0x7ff81b026d30> | |
def test_single_re_no_group(self): | |
> pattern = RePattern(r"\d+", formatter=lambda x: int(x) * 2) | |
rebulk/test/test_pattern.py:670: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
rebulk/pattern.py:441: in __init__ | |
pattern = call(re.compile, pattern, **self._kwargs) | |
rebulk/loose.py:60: in call | |
return function(*call_args, **call_kwargs) | |
/usr/lib/python3.8/site-packages/regex/regex.py:348: in compile | |
return _compile(pattern, flags, ignore_unused, kwargs) | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
pattern = '\\d+', flags = 0, ignore_unused = False | |
kwargs = {'formatter': <function TestFormatter.test_single_re_no_group.<locals>.<lambda> at 0x7ff81aec14c0>} | |
def _compile(pattern, flags, ignore_unused, kwargs): | |
"Compiles a regular expression to a PatternObject." | |
global DEFAULT_VERSION | |
try: | |
from regex import DEFAULT_VERSION | |
except ImportError: | |
pass | |
# We won't bother to cache the pattern if we're debugging. | |
debugging = (flags & DEBUG) != 0 | |
# What locale is this pattern using? | |
locale_key = (type(pattern), pattern) | |
if _locale_sensitive.get(locale_key, True) or (flags & LOCALE) != 0: | |
# This pattern is, or might be, locale-sensitive. | |
pattern_locale = _getpreferredencoding() | |
else: | |
# This pattern is definitely not locale-sensitive. | |
pattern_locale = None | |
if not debugging: | |
try: | |
# Do we know what keyword arguments are needed? | |
args_key = pattern, type(pattern), flags | |
args_needed = _named_args[args_key] | |
# Are we being provided with its required keyword arguments? | |
args_supplied = set() | |
if args_needed: | |
for k, v in args_needed: | |
try: | |
args_supplied.add((k, frozenset(kwargs[k]))) | |
except KeyError: | |
raise error("missing named list: {!r}".format(k)) | |
args_supplied = frozenset(args_supplied) | |
# Have we already seen this regular expression and named list? | |
pattern_key = (pattern, type(pattern), flags, args_supplied, | |
DEFAULT_VERSION, pattern_locale) | |
return _cache[pattern_key] | |
except KeyError: | |
# It's a new pattern, or new named list for a known pattern. | |
pass | |
# Guess the encoding from the class of the pattern string. | |
if isinstance(pattern, str): | |
guess_encoding = UNICODE | |
elif isinstance(pattern, bytes): | |
guess_encoding = ASCII | |
elif isinstance(pattern, Pattern): | |
if flags: | |
raise ValueError("cannot process flags argument with a compiled pattern") | |
return pattern | |
else: | |
raise TypeError("first argument must be a string or compiled pattern") | |
# Set the default version in the core code in case it has been changed. | |
_regex_core.DEFAULT_VERSION = DEFAULT_VERSION | |
global_flags = flags | |
while True: | |
caught_exception = None | |
try: | |
source = _Source(pattern) | |
info = _Info(global_flags, source.char_type, kwargs) | |
info.guess_encoding = guess_encoding | |
source.ignore_space = bool(info.flags & VERBOSE) | |
parsed = _parse_pattern(source, info) | |
break | |
except _UnscopedFlagSet: | |
# Remember the global flags for the next attempt. | |
global_flags = info.global_flags | |
except error as e: | |
caught_exception = e | |
if caught_exception: | |
raise error(caught_exception.msg, caught_exception.pattern, | |
caught_exception.pos) | |
if not source.at_end(): | |
raise error("unbalanced parenthesis", pattern, source.pos) | |
# Check the global flags for conflicts. | |
version = (info.flags & _ALL_VERSIONS) or DEFAULT_VERSION | |
if version not in (0, VERSION0, VERSION1): | |
raise ValueError("VERSION0 and VERSION1 flags are mutually incompatible") | |
if (info.flags & _ALL_ENCODINGS) not in (0, ASCII, LOCALE, UNICODE): | |
raise ValueError("ASCII, LOCALE and UNICODE flags are mutually incompatible") | |
if isinstance(pattern, bytes) and (info.flags & UNICODE): | |
raise ValueError("cannot use UNICODE flag with a bytes pattern") | |
if not (info.flags & _ALL_ENCODINGS): | |
if isinstance(pattern, str): | |
info.flags |= UNICODE | |
else: | |
info.flags |= ASCII | |
reverse = bool(info.flags & REVERSE) | |
fuzzy = isinstance(parsed, _Fuzzy) | |
# Remember whether this pattern as an inline locale flag. | |
_locale_sensitive[locale_key] = info.inline_locale | |
# Fix the group references. | |
caught_exception = None | |
try: | |
parsed.fix_groups(pattern, reverse, False) | |
except error as e: | |
caught_exception = e | |
if caught_exception: | |
raise error(caught_exception.msg, caught_exception.pattern, | |
caught_exception.pos) | |
# Should we print the parsed pattern? | |
if flags & DEBUG: | |
parsed.dump(indent=0, reverse=reverse) | |
# Optimise the parsed pattern. | |
parsed = parsed.optimise(info, reverse) | |
parsed = parsed.pack_characters(info) | |
# Get the required string. | |
req_offset, req_chars, req_flags = _get_required_string(parsed, info.flags) | |
# Build the named lists. | |
named_lists = {} | |
named_list_indexes = [None] * len(info.named_lists_used) | |
args_needed = set() | |
for key, index in info.named_lists_used.items(): | |
name, case_flags = key | |
values = frozenset(kwargs[name]) | |
if case_flags: | |
items = frozenset(_fold_case(info, v) for v in values) | |
else: | |
items = values | |
named_lists[name] = values | |
named_list_indexes[index] = items | |
args_needed.add((name, values)) | |
# Any unused keyword arguments, possibly resulting from a typo? | |
unused_kwargs = set(kwargs) - set(named_lists) | |
if unused_kwargs and not ignore_unused: | |
any_one = next(iter(unused_kwargs)) | |
> raise ValueError('unused keyword argument {!a}'.format(any_one)) | |
E ValueError: unused keyword argument 'formatter' | |
/usr/lib/python3.8/site-packages/regex/regex.py:585: ValueError | |
____________________________________________ TestFormatter.test_single_re_named_groups _____________________________________________ | |
self = <rebulk.test.test_pattern.TestFormatter object at 0x7ff81af91880> | |
def test_single_re_named_groups(self): | |
> pattern = RePattern(r"(?P<strParam>cont.?ins)\s+(?P<intParam>\d+)", | |
formatter={'intParam': lambda x: int(x) * 2, | |
'strParam': lambda x: "really " + x}, format_all=True) | |
rebulk/test/test_pattern.py:680: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
rebulk/pattern.py:441: in __init__ | |
pattern = call(re.compile, pattern, **self._kwargs) | |
rebulk/loose.py:60: in call | |
return function(*call_args, **call_kwargs) | |
/usr/lib/python3.8/site-packages/regex/regex.py:348: in compile | |
return _compile(pattern, flags, ignore_unused, kwargs) | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
pattern = '(?P<strParam>cont.?ins)\\s+(?P<intParam>\\d+)', flags = 0, ignore_unused = False | |
kwargs = {'format_all': True, 'formatter': {'intParam': <function TestFormatter.test_single_re_named_groups.<locals>.<lambda> at 0x7ff81afbde50>, 'strParam': <function TestFormatter.test_single_re_named_groups.<locals>.<lambda> at 0x7ff81afbd040>}} | |
def _compile(pattern, flags, ignore_unused, kwargs): | |
"Compiles a regular expression to a PatternObject." | |
global DEFAULT_VERSION | |
try: | |
from regex import DEFAULT_VERSION | |
except ImportError: | |
pass | |
# We won't bother to cache the pattern if we're debugging. | |
debugging = (flags & DEBUG) != 0 | |
# What locale is this pattern using? | |
locale_key = (type(pattern), pattern) | |
if _locale_sensitive.get(locale_key, True) or (flags & LOCALE) != 0: | |
# This pattern is, or might be, locale-sensitive. | |
pattern_locale = _getpreferredencoding() | |
else: | |
# This pattern is definitely not locale-sensitive. | |
pattern_locale = None | |
if not debugging: | |
try: | |
# Do we know what keyword arguments are needed? | |
args_key = pattern, type(pattern), flags | |
args_needed = _named_args[args_key] | |
# Are we being provided with its required keyword arguments? | |
args_supplied = set() | |
if args_needed: | |
for k, v in args_needed: | |
try: | |
args_supplied.add((k, frozenset(kwargs[k]))) | |
except KeyError: | |
raise error("missing named list: {!r}".format(k)) | |
args_supplied = frozenset(args_supplied) | |
# Have we already seen this regular expression and named list? | |
pattern_key = (pattern, type(pattern), flags, args_supplied, | |
DEFAULT_VERSION, pattern_locale) | |
return _cache[pattern_key] | |
except KeyError: | |
# It's a new pattern, or new named list for a known pattern. | |
pass | |
# Guess the encoding from the class of the pattern string. | |
if isinstance(pattern, str): | |
guess_encoding = UNICODE | |
elif isinstance(pattern, bytes): | |
guess_encoding = ASCII | |
elif isinstance(pattern, Pattern): | |
if flags: | |
raise ValueError("cannot process flags argument with a compiled pattern") | |
return pattern | |
else: | |
raise TypeError("first argument must be a string or compiled pattern") | |
# Set the default version in the core code in case it has been changed. | |
_regex_core.DEFAULT_VERSION = DEFAULT_VERSION | |
global_flags = flags | |
while True: | |
caught_exception = None | |
try: | |
source = _Source(pattern) | |
info = _Info(global_flags, source.char_type, kwargs) | |
info.guess_encoding = guess_encoding | |
source.ignore_space = bool(info.flags & VERBOSE) | |
parsed = _parse_pattern(source, info) | |
break | |
except _UnscopedFlagSet: | |
# Remember the global flags for the next attempt. | |
global_flags = info.global_flags | |
except error as e: | |
caught_exception = e | |
if caught_exception: | |
raise error(caught_exception.msg, caught_exception.pattern, | |
caught_exception.pos) | |
if not source.at_end(): | |
raise error("unbalanced parenthesis", pattern, source.pos) | |
# Check the global flags for conflicts. | |
version = (info.flags & _ALL_VERSIONS) or DEFAULT_VERSION | |
if version not in (0, VERSION0, VERSION1): | |
raise ValueError("VERSION0 and VERSION1 flags are mutually incompatible") | |
if (info.flags & _ALL_ENCODINGS) not in (0, ASCII, LOCALE, UNICODE): | |
raise ValueError("ASCII, LOCALE and UNICODE flags are mutually incompatible") | |
if isinstance(pattern, bytes) and (info.flags & UNICODE): | |
raise ValueError("cannot use UNICODE flag with a bytes pattern") | |
if not (info.flags & _ALL_ENCODINGS): | |
if isinstance(pattern, str): | |
info.flags |= UNICODE | |
else: | |
info.flags |= ASCII | |
reverse = bool(info.flags & REVERSE) | |
fuzzy = isinstance(parsed, _Fuzzy) | |
# Remember whether this pattern as an inline locale flag. | |
_locale_sensitive[locale_key] = info.inline_locale | |
# Fix the group references. | |
caught_exception = None | |
try: | |
parsed.fix_groups(pattern, reverse, False) | |
except error as e: | |
caught_exception = e | |
if caught_exception: | |
raise error(caught_exception.msg, caught_exception.pattern, | |
caught_exception.pos) | |
# Should we print the parsed pattern? | |
if flags & DEBUG: | |
parsed.dump(indent=0, reverse=reverse) | |
# Optimise the parsed pattern. | |
parsed = parsed.optimise(info, reverse) | |
parsed = parsed.pack_characters(info) | |
# Get the required string. | |
req_offset, req_chars, req_flags = _get_required_string(parsed, info.flags) | |
# Build the named lists. | |
named_lists = {} | |
named_list_indexes = [None] * len(info.named_lists_used) | |
args_needed = set() | |
for key, index in info.named_lists_used.items(): | |
name, case_flags = key | |
values = frozenset(kwargs[name]) | |
if case_flags: | |
items = frozenset(_fold_case(info, v) for v in values) | |
else: | |
items = values | |
named_lists[name] = values | |
named_list_indexes[index] = items | |
args_needed.add((name, values)) | |
# Any unused keyword arguments, possibly resulting from a typo? | |
unused_kwargs = set(kwargs) - set(named_lists) | |
if unused_kwargs and not ignore_unused: | |
any_one = next(iter(unused_kwargs)) | |
> raise ValueError('unused keyword argument {!a}'.format(any_one)) | |
E ValueError: unused keyword argument 'formatter' | |
/usr/lib/python3.8/site-packages/regex/regex.py:585: ValueError | |
______________________________________________ TestValidator.test_single_re_no_group _______________________________________________ | |
self = <rebulk.test.test_pattern.TestValidator object at 0x7ff81aa9d640> | |
def test_single_re_no_group(self): | |
> pattern = RePattern(r"\d+", validator=self.false_validator) | |
rebulk/test/test_pattern.py:771: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
rebulk/pattern.py:441: in __init__ | |
pattern = call(re.compile, pattern, **self._kwargs) | |
rebulk/loose.py:60: in call | |
return function(*call_args, **call_kwargs) | |
/usr/lib/python3.8/site-packages/regex/regex.py:348: in compile | |
return _compile(pattern, flags, ignore_unused, kwargs) | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
pattern = '\\d+', flags = 0, ignore_unused = False | |
kwargs = {'validator': <function TestValidator.false_validator at 0x7ff81a853310>} | |
def _compile(pattern, flags, ignore_unused, kwargs): | |
"Compiles a regular expression to a PatternObject." | |
global DEFAULT_VERSION | |
try: | |
from regex import DEFAULT_VERSION | |
except ImportError: | |
pass | |
# We won't bother to cache the pattern if we're debugging. | |
debugging = (flags & DEBUG) != 0 | |
# What locale is this pattern using? | |
locale_key = (type(pattern), pattern) | |
if _locale_sensitive.get(locale_key, True) or (flags & LOCALE) != 0: | |
# This pattern is, or might be, locale-sensitive. | |
pattern_locale = _getpreferredencoding() | |
else: | |
# This pattern is definitely not locale-sensitive. | |
pattern_locale = None | |
if not debugging: | |
try: | |
# Do we know what keyword arguments are needed? | |
args_key = pattern, type(pattern), flags | |
args_needed = _named_args[args_key] | |
# Are we being provided with its required keyword arguments? | |
args_supplied = set() | |
if args_needed: | |
for k, v in args_needed: | |
try: | |
args_supplied.add((k, frozenset(kwargs[k]))) | |
except KeyError: | |
raise error("missing named list: {!r}".format(k)) | |
args_supplied = frozenset(args_supplied) | |
# Have we already seen this regular expression and named list? | |
pattern_key = (pattern, type(pattern), flags, args_supplied, | |
DEFAULT_VERSION, pattern_locale) | |
return _cache[pattern_key] | |
except KeyError: | |
# It's a new pattern, or new named list for a known pattern. | |
pass | |
# Guess the encoding from the class of the pattern string. | |
if isinstance(pattern, str): | |
guess_encoding = UNICODE | |
elif isinstance(pattern, bytes): | |
guess_encoding = ASCII | |
elif isinstance(pattern, Pattern): | |
if flags: | |
raise ValueError("cannot process flags argument with a compiled pattern") | |
return pattern | |
else: | |
raise TypeError("first argument must be a string or compiled pattern") | |
# Set the default version in the core code in case it has been changed. | |
_regex_core.DEFAULT_VERSION = DEFAULT_VERSION | |
global_flags = flags | |
while True: | |
caught_exception = None | |
try: | |
source = _Source(pattern) | |
info = _Info(global_flags, source.char_type, kwargs) | |
info.guess_encoding = guess_encoding | |
source.ignore_space = bool(info.flags & VERBOSE) | |
parsed = _parse_pattern(source, info) | |
break | |
except _UnscopedFlagSet: | |
# Remember the global flags for the next attempt. | |
global_flags = info.global_flags | |
except error as e: | |
caught_exception = e | |
if caught_exception: | |
raise error(caught_exception.msg, caught_exception.pattern, | |
caught_exception.pos) | |
if not source.at_end(): | |
raise error("unbalanced parenthesis", pattern, source.pos) | |
# Check the global flags for conflicts. | |
version = (info.flags & _ALL_VERSIONS) or DEFAULT_VERSION | |
if version not in (0, VERSION0, VERSION1): | |
raise ValueError("VERSION0 and VERSION1 flags are mutually incompatible") | |
if (info.flags & _ALL_ENCODINGS) not in (0, ASCII, LOCALE, UNICODE): | |
raise ValueError("ASCII, LOCALE and UNICODE flags are mutually incompatible") | |
if isinstance(pattern, bytes) and (info.flags & UNICODE): | |
raise ValueError("cannot use UNICODE flag with a bytes pattern") | |
if not (info.flags & _ALL_ENCODINGS): | |
if isinstance(pattern, str): | |
info.flags |= UNICODE | |
else: | |
info.flags |= ASCII | |
reverse = bool(info.flags & REVERSE) | |
fuzzy = isinstance(parsed, _Fuzzy) | |
# Remember whether this pattern as an inline locale flag. | |
_locale_sensitive[locale_key] = info.inline_locale | |
# Fix the group references. | |
caught_exception = None | |
try: | |
parsed.fix_groups(pattern, reverse, False) | |
except error as e: | |
caught_exception = e | |
if caught_exception: | |
raise error(caught_exception.msg, caught_exception.pattern, | |
caught_exception.pos) | |
# Should we print the parsed pattern? | |
if flags & DEBUG: | |
parsed.dump(indent=0, reverse=reverse) | |
# Optimise the parsed pattern. | |
parsed = parsed.optimise(info, reverse) | |
parsed = parsed.pack_characters(info) | |
# Get the required string. | |
req_offset, req_chars, req_flags = _get_required_string(parsed, info.flags) | |
# Build the named lists. | |
named_lists = {} | |
named_list_indexes = [None] * len(info.named_lists_used) | |
args_needed = set() | |
for key, index in info.named_lists_used.items(): | |
name, case_flags = key | |
values = frozenset(kwargs[name]) | |
if case_flags: | |
items = frozenset(_fold_case(info, v) for v in values) | |
else: | |
items = values | |
named_lists[name] = values | |
named_list_indexes[index] = items | |
args_needed.add((name, values)) | |
# Any unused keyword arguments, possibly resulting from a typo? | |
unused_kwargs = set(kwargs) - set(named_lists) | |
if unused_kwargs and not ignore_unused: | |
any_one = next(iter(unused_kwargs)) | |
> raise ValueError('unused keyword argument {!a}'.format(any_one)) | |
E ValueError: unused keyword argument 'validator' | |
/usr/lib/python3.8/site-packages/regex/regex.py:585: ValueError | |
____________________________________________ TestValidator.test_single_re_named_groups _____________________________________________ | |
self = <rebulk.test.test_pattern.TestValidator object at 0x7ff81ab512e0> | |
def test_single_re_named_groups(self): | |
> pattern = RePattern(r"(?P<strParam>cont.?ins)\s+(?P<intParam>\d+)", | |
validator={'intParam': self.false_validator}, validate_all=True) | |
rebulk/test/test_pattern.py:782: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
rebulk/pattern.py:441: in __init__ | |
pattern = call(re.compile, pattern, **self._kwargs) | |
rebulk/loose.py:60: in call | |
return function(*call_args, **call_kwargs) | |
/usr/lib/python3.8/site-packages/regex/regex.py:348: in compile | |
return _compile(pattern, flags, ignore_unused, kwargs) | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
pattern = '(?P<strParam>cont.?ins)\\s+(?P<intParam>\\d+)', flags = 0, ignore_unused = False | |
kwargs = {'validate_all': True, 'validator': {'intParam': <function TestValidator.false_validator at 0x7ff81a853310>}} | |
def _compile(pattern, flags, ignore_unused, kwargs): | |
"Compiles a regular expression to a PatternObject." | |
global DEFAULT_VERSION | |
try: | |
from regex import DEFAULT_VERSION | |
except ImportError: | |
pass | |
# We won't bother to cache the pattern if we're debugging. | |
debugging = (flags & DEBUG) != 0 | |
# What locale is this pattern using? | |
locale_key = (type(pattern), pattern) | |
if _locale_sensitive.get(locale_key, True) or (flags & LOCALE) != 0: | |
# This pattern is, or might be, locale-sensitive. | |
pattern_locale = _getpreferredencoding() | |
else: | |
# This pattern is definitely not locale-sensitive. | |
pattern_locale = None | |
if not debugging: | |
try: | |
# Do we know what keyword arguments are needed? | |
args_key = pattern, type(pattern), flags | |
args_needed = _named_args[args_key] | |
# Are we being provided with its required keyword arguments? | |
args_supplied = set() | |
if args_needed: | |
for k, v in args_needed: | |
try: | |
args_supplied.add((k, frozenset(kwargs[k]))) | |
except KeyError: | |
raise error("missing named list: {!r}".format(k)) | |
args_supplied = frozenset(args_supplied) | |
# Have we already seen this regular expression and named list? | |
pattern_key = (pattern, type(pattern), flags, args_supplied, | |
DEFAULT_VERSION, pattern_locale) | |
return _cache[pattern_key] | |
except KeyError: | |
# It's a new pattern, or new named list for a known pattern. | |
pass | |
# Guess the encoding from the class of the pattern string. | |
if isinstance(pattern, str): | |
guess_encoding = UNICODE | |
elif isinstance(pattern, bytes): | |
guess_encoding = ASCII | |
elif isinstance(pattern, Pattern): | |
if flags: | |
raise ValueError("cannot process flags argument with a compiled pattern") | |
return pattern | |
else: | |
raise TypeError("first argument must be a string or compiled pattern") | |
# Set the default version in the core code in case it has been changed. | |
_regex_core.DEFAULT_VERSION = DEFAULT_VERSION | |
global_flags = flags | |
while True: | |
caught_exception = None | |
try: | |
source = _Source(pattern) | |
info = _Info(global_flags, source.char_type, kwargs) | |
info.guess_encoding = guess_encoding | |
source.ignore_space = bool(info.flags & VERBOSE) | |
parsed = _parse_pattern(source, info) | |
break | |
except _UnscopedFlagSet: | |
# Remember the global flags for the next attempt. | |
global_flags = info.global_flags | |
except error as e: | |
caught_exception = e | |
if caught_exception: | |
raise error(caught_exception.msg, caught_exception.pattern, | |
caught_exception.pos) | |
if not source.at_end(): | |
raise error("unbalanced parenthesis", pattern, source.pos) | |
# Check the global flags for conflicts. | |
version = (info.flags & _ALL_VERSIONS) or DEFAULT_VERSION | |
if version not in (0, VERSION0, VERSION1): | |
raise ValueError("VERSION0 and VERSION1 flags are mutually incompatible") | |
if (info.flags & _ALL_ENCODINGS) not in (0, ASCII, LOCALE, UNICODE): | |
raise ValueError("ASCII, LOCALE and UNICODE flags are mutually incompatible") | |
if isinstance(pattern, bytes) and (info.flags & UNICODE): | |
raise ValueError("cannot use UNICODE flag with a bytes pattern") | |
if not (info.flags & _ALL_ENCODINGS): | |
if isinstance(pattern, str): | |
info.flags |= UNICODE | |
else: | |
info.flags |= ASCII | |
reverse = bool(info.flags & REVERSE) | |
fuzzy = isinstance(parsed, _Fuzzy) | |
# Remember whether this pattern as an inline locale flag. | |
_locale_sensitive[locale_key] = info.inline_locale | |
# Fix the group references. | |
caught_exception = None | |
try: | |
parsed.fix_groups(pattern, reverse, False) | |
except error as e: | |
caught_exception = e | |
if caught_exception: | |
raise error(caught_exception.msg, caught_exception.pattern, | |
caught_exception.pos) | |
# Should we print the parsed pattern? | |
if flags & DEBUG: | |
parsed.dump(indent=0, reverse=reverse) | |
# Optimise the parsed pattern. | |
parsed = parsed.optimise(info, reverse) | |
parsed = parsed.pack_characters(info) | |
# Get the required string. | |
req_offset, req_chars, req_flags = _get_required_string(parsed, info.flags) | |
# Build the named lists. | |
named_lists = {} | |
named_list_indexes = [None] * len(info.named_lists_used) | |
args_needed = set() | |
for key, index in info.named_lists_used.items(): | |
name, case_flags = key | |
values = frozenset(kwargs[name]) | |
if case_flags: | |
items = frozenset(_fold_case(info, v) for v in values) | |
else: | |
items = values | |
named_lists[name] = values | |
named_list_indexes[index] = items | |
args_needed.add((name, values)) | |
# Any unused keyword arguments, possibly resulting from a typo? | |
unused_kwargs = set(kwargs) - set(named_lists) | |
if unused_kwargs and not ignore_unused: | |
any_one = next(iter(unused_kwargs)) | |
> raise ValueError('unused keyword argument {!a}'.format(any_one)) | |
E ValueError: unused keyword argument 'validator' | |
/usr/lib/python3.8/site-packages/regex/regex.py:585: ValueError | |
_________________________________________________ TestValidator.test_validate_all __________________________________________________ | |
self = <rebulk.test.test_pattern.TestValidator object at 0x7ff81adab850> | |
def test_validate_all(self): | |
> pattern = RePattern(r"contains (?P<intParam>\d+)", formatter=int, validator=lambda match: match.value < 100, | |
children=True) | |
rebulk/test/test_pattern.py:795: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
rebulk/pattern.py:441: in __init__ | |
pattern = call(re.compile, pattern, **self._kwargs) | |
rebulk/loose.py:60: in call | |
return function(*call_args, **call_kwargs) | |
/usr/lib/python3.8/site-packages/regex/regex.py:348: in compile | |
return _compile(pattern, flags, ignore_unused, kwargs) | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
pattern = 'contains (?P<intParam>\\d+)', flags = 0, ignore_unused = False | |
kwargs = {'children': True, 'formatter': <class 'int'>, 'validator': <function TestValidator.test_validate_all.<locals>.<lambda> at 0x7ff81aec1af0>} | |
def _compile(pattern, flags, ignore_unused, kwargs): | |
"Compiles a regular expression to a PatternObject." | |
global DEFAULT_VERSION | |
try: | |
from regex import DEFAULT_VERSION | |
except ImportError: | |
pass | |
# We won't bother to cache the pattern if we're debugging. | |
debugging = (flags & DEBUG) != 0 | |
# What locale is this pattern using? | |
locale_key = (type(pattern), pattern) | |
if _locale_sensitive.get(locale_key, True) or (flags & LOCALE) != 0: | |
# This pattern is, or might be, locale-sensitive. | |
pattern_locale = _getpreferredencoding() | |
else: | |
# This pattern is definitely not locale-sensitive. | |
pattern_locale = None | |
if not debugging: | |
try: | |
# Do we know what keyword arguments are needed? | |
args_key = pattern, type(pattern), flags | |
args_needed = _named_args[args_key] | |
# Are we being provided with its required keyword arguments? | |
args_supplied = set() | |
if args_needed: | |
for k, v in args_needed: | |
try: | |
args_supplied.add((k, frozenset(kwargs[k]))) | |
except KeyError: | |
raise error("missing named list: {!r}".format(k)) | |
args_supplied = frozenset(args_supplied) | |
# Have we already seen this regular expression and named list? | |
pattern_key = (pattern, type(pattern), flags, args_supplied, | |
DEFAULT_VERSION, pattern_locale) | |
return _cache[pattern_key] | |
except KeyError: | |
# It's a new pattern, or new named list for a known pattern. | |
pass | |
# Guess the encoding from the class of the pattern string. | |
if isinstance(pattern, str): | |
guess_encoding = UNICODE | |
elif isinstance(pattern, bytes): | |
guess_encoding = ASCII | |
elif isinstance(pattern, Pattern): | |
if flags: | |
raise ValueError("cannot process flags argument with a compiled pattern") | |
return pattern | |
else: | |
raise TypeError("first argument must be a string or compiled pattern") | |
# Set the default version in the core code in case it has been changed. | |
_regex_core.DEFAULT_VERSION = DEFAULT_VERSION | |
global_flags = flags | |
while True: | |
caught_exception = None | |
try: | |
source = _Source(pattern) | |
info = _Info(global_flags, source.char_type, kwargs) | |
info.guess_encoding = guess_encoding | |
source.ignore_space = bool(info.flags & VERBOSE) | |
parsed = _parse_pattern(source, info) | |
break | |
except _UnscopedFlagSet: | |
# Remember the global flags for the next attempt. | |
global_flags = info.global_flags | |
except error as e: | |
caught_exception = e | |
if caught_exception: | |
raise error(caught_exception.msg, caught_exception.pattern, | |
caught_exception.pos) | |
if not source.at_end(): | |
raise error("unbalanced parenthesis", pattern, source.pos) | |
# Check the global flags for conflicts. | |
version = (info.flags & _ALL_VERSIONS) or DEFAULT_VERSION | |
if version not in (0, VERSION0, VERSION1): | |
raise ValueError("VERSION0 and VERSION1 flags are mutually incompatible") | |
if (info.flags & _ALL_ENCODINGS) not in (0, ASCII, LOCALE, UNICODE): | |
raise ValueError("ASCII, LOCALE and UNICODE flags are mutually incompatible") | |
if isinstance(pattern, bytes) and (info.flags & UNICODE): | |
raise ValueError("cannot use UNICODE flag with a bytes pattern") | |
if not (info.flags & _ALL_ENCODINGS): | |
if isinstance(pattern, str): | |
info.flags |= UNICODE | |
else: | |
info.flags |= ASCII | |
reverse = bool(info.flags & REVERSE) | |
fuzzy = isinstance(parsed, _Fuzzy) | |
# Remember whether this pattern as an inline locale flag. | |
_locale_sensitive[locale_key] = info.inline_locale | |
# Fix the group references. | |
caught_exception = None | |
try: | |
parsed.fix_groups(pattern, reverse, False) | |
except error as e: | |
caught_exception = e | |
if caught_exception: | |
raise error(caught_exception.msg, caught_exception.pattern, | |
caught_exception.pos) | |
# Should we print the parsed pattern? | |
if flags & DEBUG: | |
parsed.dump(indent=0, reverse=reverse) | |
# Optimise the parsed pattern. | |
parsed = parsed.optimise(info, reverse) | |
parsed = parsed.pack_characters(info) | |
# Get the required string. | |
req_offset, req_chars, req_flags = _get_required_string(parsed, info.flags) | |
# Build the named lists. | |
named_lists = {} | |
named_list_indexes = [None] * len(info.named_lists_used) | |
args_needed = set() | |
for key, index in info.named_lists_used.items(): | |
name, case_flags = key | |
values = frozenset(kwargs[name]) | |
if case_flags: | |
items = frozenset(_fold_case(info, v) for v in values) | |
else: | |
items = values | |
named_lists[name] = values | |
named_list_indexes[index] = items | |
args_needed.add((name, values)) | |
# Any unused keyword arguments, possibly resulting from a typo? | |
unused_kwargs = set(kwargs) - set(named_lists) | |
if unused_kwargs and not ignore_unused: | |
any_one = next(iter(unused_kwargs)) | |
> raise ValueError('unused keyword argument {!a}'.format(any_one)) | |
E ValueError: unused keyword argument 'formatter' | |
/usr/lib/python3.8/site-packages/regex/regex.py:585: ValueError | |
__________________________________________________ TestValidator.test_format_all ___________________________________________________ | |
self = <rebulk.test.test_pattern.TestValidator object at 0x7ff81acc4100> | |
def test_format_all(self): | |
> pattern = RePattern(r"contains (?P<intParam>\d+)", formatter=int, | |
children=True) | |
rebulk/test/test_pattern.py:830: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
rebulk/pattern.py:441: in __init__ | |
pattern = call(re.compile, pattern, **self._kwargs) | |
rebulk/loose.py:60: in call | |
return function(*call_args, **call_kwargs) | |
/usr/lib/python3.8/site-packages/regex/regex.py:348: in compile | |
return _compile(pattern, flags, ignore_unused, kwargs) | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
pattern = 'contains (?P<intParam>\\d+)', flags = 0, ignore_unused = False, kwargs = {'children': True, 'formatter': <class 'int'>} | |
def _compile(pattern, flags, ignore_unused, kwargs): | |
"Compiles a regular expression to a PatternObject." | |
global DEFAULT_VERSION | |
try: | |
from regex import DEFAULT_VERSION | |
except ImportError: | |
pass | |
# We won't bother to cache the pattern if we're debugging. | |
debugging = (flags & DEBUG) != 0 | |
# What locale is this pattern using? | |
locale_key = (type(pattern), pattern) | |
if _locale_sensitive.get(locale_key, True) or (flags & LOCALE) != 0: | |
# This pattern is, or might be, locale-sensitive. | |
pattern_locale = _getpreferredencoding() | |
else: | |
# This pattern is definitely not locale-sensitive. | |
pattern_locale = None | |
if not debugging: | |
try: | |
# Do we know what keyword arguments are needed? | |
args_key = pattern, type(pattern), flags | |
args_needed = _named_args[args_key] | |
# Are we being provided with its required keyword arguments? | |
args_supplied = set() | |
if args_needed: | |
for k, v in args_needed: | |
try: | |
args_supplied.add((k, frozenset(kwargs[k]))) | |
except KeyError: | |
raise error("missing named list: {!r}".format(k)) | |
args_supplied = frozenset(args_supplied) | |
# Have we already seen this regular expression and named list? | |
pattern_key = (pattern, type(pattern), flags, args_supplied, | |
DEFAULT_VERSION, pattern_locale) | |
return _cache[pattern_key] | |
except KeyError: | |
# It's a new pattern, or new named list for a known pattern. | |
pass | |
# Guess the encoding from the class of the pattern string. | |
if isinstance(pattern, str): | |
guess_encoding = UNICODE | |
elif isinstance(pattern, bytes): | |
guess_encoding = ASCII | |
elif isinstance(pattern, Pattern): | |
if flags: | |
raise ValueError("cannot process flags argument with a compiled pattern") | |
return pattern | |
else: | |
raise TypeError("first argument must be a string or compiled pattern") | |
# Set the default version in the core code in case it has been changed. | |
_regex_core.DEFAULT_VERSION = DEFAULT_VERSION | |
global_flags = flags | |
while True: | |
caught_exception = None | |
try: | |
source = _Source(pattern) | |
info = _Info(global_flags, source.char_type, kwargs) | |
info.guess_encoding = guess_encoding | |
source.ignore_space = bool(info.flags & VERBOSE) | |
parsed = _parse_pattern(source, info) | |
break | |
except _UnscopedFlagSet: | |
# Remember the global flags for the next attempt. | |
global_flags = info.global_flags | |
except error as e: | |
caught_exception = e | |
if caught_exception: | |
raise error(caught_exception.msg, caught_exception.pattern, | |
caught_exception.pos) | |
if not source.at_end(): | |
raise error("unbalanced parenthesis", pattern, source.pos) | |
# Check the global flags for conflicts. | |
version = (info.flags & _ALL_VERSIONS) or DEFAULT_VERSION | |
if version not in (0, VERSION0, VERSION1): | |
raise ValueError("VERSION0 and VERSION1 flags are mutually incompatible") | |
if (info.flags & _ALL_ENCODINGS) not in (0, ASCII, LOCALE, UNICODE): | |
raise ValueError("ASCII, LOCALE and UNICODE flags are mutually incompatible") | |
if isinstance(pattern, bytes) and (info.flags & UNICODE): | |
raise ValueError("cannot use UNICODE flag with a bytes pattern") | |
if not (info.flags & _ALL_ENCODINGS): | |
if isinstance(pattern, str): | |
info.flags |= UNICODE | |
else: | |
info.flags |= ASCII | |
reverse = bool(info.flags & REVERSE) | |
fuzzy = isinstance(parsed, _Fuzzy) | |
# Remember whether this pattern as an inline locale flag. | |
_locale_sensitive[locale_key] = info.inline_locale | |
# Fix the group references. | |
caught_exception = None | |
try: | |
parsed.fix_groups(pattern, reverse, False) | |
except error as e: | |
caught_exception = e | |
if caught_exception: | |
raise error(caught_exception.msg, caught_exception.pattern, | |
caught_exception.pos) | |
# Should we print the parsed pattern? | |
if flags & DEBUG: | |
parsed.dump(indent=0, reverse=reverse) | |
# Optimise the parsed pattern. | |
parsed = parsed.optimise(info, reverse) | |
parsed = parsed.pack_characters(info) | |
# Get the required string. | |
req_offset, req_chars, req_flags = _get_required_string(parsed, info.flags) | |
# Build the named lists. | |
named_lists = {} | |
named_list_indexes = [None] * len(info.named_lists_used) | |
args_needed = set() | |
for key, index in info.named_lists_used.items(): | |
name, case_flags = key | |
values = frozenset(kwargs[name]) | |
if case_flags: | |
items = frozenset(_fold_case(info, v) for v in values) | |
else: | |
items = values | |
named_lists[name] = values | |
named_list_indexes[index] = items | |
args_needed.add((name, values)) | |
# Any unused keyword arguments, possibly resulting from a typo? | |
unused_kwargs = set(kwargs) - set(named_lists) | |
if unused_kwargs and not ignore_unused: | |
any_one = next(iter(unused_kwargs)) | |
> raise ValueError('unused keyword argument {!a}'.format(any_one)) | |
E ValueError: unused keyword argument 'formatter' | |
/usr/lib/python3.8/site-packages/regex/regex.py:585: ValueError | |
____________________________________________________ test_prefer_longer_parent _____________________________________________________ | |
def test_prefer_longer_parent(): | |
input_string = "xxx.1x02.xxx" | |
> re1 = RePattern("([0-9]+)x([0-9]+)", name='prefer', children=True, formatter=int) | |
rebulk/test/test_processors.py:77: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
rebulk/pattern.py:441: in __init__ | |
pattern = call(re.compile, pattern, **self._kwargs) | |
rebulk/loose.py:60: in call | |
return function(*call_args, **call_kwargs) | |
/usr/lib/python3.8/site-packages/regex/regex.py:348: in compile | |
return _compile(pattern, flags, ignore_unused, kwargs) | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
pattern = '([0-9]+)x([0-9]+)', flags = 0, ignore_unused = False | |
kwargs = {'children': True, 'formatter': <class 'int'>, 'name': 'prefer'} | |
def _compile(pattern, flags, ignore_unused, kwargs): | |
"Compiles a regular expression to a PatternObject." | |
global DEFAULT_VERSION | |
try: | |
from regex import DEFAULT_VERSION | |
except ImportError: | |
pass | |
# We won't bother to cache the pattern if we're debugging. | |
debugging = (flags & DEBUG) != 0 | |
# What locale is this pattern using? | |
locale_key = (type(pattern), pattern) | |
if _locale_sensitive.get(locale_key, True) or (flags & LOCALE) != 0: | |
# This pattern is, or might be, locale-sensitive. | |
pattern_locale = _getpreferredencoding() | |
else: | |
# This pattern is definitely not locale-sensitive. | |
pattern_locale = None | |
if not debugging: | |
try: | |
# Do we know what keyword arguments are needed? | |
args_key = pattern, type(pattern), flags | |
args_needed = _named_args[args_key] | |
# Are we being provided with its required keyword arguments? | |
args_supplied = set() | |
if args_needed: | |
for k, v in args_needed: | |
try: | |
args_supplied.add((k, frozenset(kwargs[k]))) | |
except KeyError: | |
raise error("missing named list: {!r}".format(k)) | |
args_supplied = frozenset(args_supplied) | |
# Have we already seen this regular expression and named list? | |
pattern_key = (pattern, type(pattern), flags, args_supplied, | |
DEFAULT_VERSION, pattern_locale) | |
return _cache[pattern_key] | |
except KeyError: | |
# It's a new pattern, or new named list for a known pattern. | |
pass | |
# Guess the encoding from the class of the pattern string. | |
if isinstance(pattern, str): | |
guess_encoding = UNICODE | |
elif isinstance(pattern, bytes): | |
guess_encoding = ASCII | |
elif isinstance(pattern, Pattern): | |
if flags: | |
raise ValueError("cannot process flags argument with a compiled pattern") | |
return pattern | |
else: | |
raise TypeError("first argument must be a string or compiled pattern") | |
# Set the default version in the core code in case it has been changed. | |
_regex_core.DEFAULT_VERSION = DEFAULT_VERSION | |
global_flags = flags | |
while True: | |
caught_exception = None | |
try: | |
source = _Source(pattern) | |
info = _Info(global_flags, source.char_type, kwargs) | |
info.guess_encoding = guess_encoding | |
source.ignore_space = bool(info.flags & VERBOSE) | |
parsed = _parse_pattern(source, info) | |
break | |
except _UnscopedFlagSet: | |
# Remember the global flags for the next attempt. | |
global_flags = info.global_flags | |
except error as e: | |
caught_exception = e | |
if caught_exception: | |
raise error(caught_exception.msg, caught_exception.pattern, | |
caught_exception.pos) | |
if not source.at_end(): | |
raise error("unbalanced parenthesis", pattern, source.pos) | |
# Check the global flags for conflicts. | |
version = (info.flags & _ALL_VERSIONS) or DEFAULT_VERSION | |
if version not in (0, VERSION0, VERSION1): | |
raise ValueError("VERSION0 and VERSION1 flags are mutually incompatible") | |
if (info.flags & _ALL_ENCODINGS) not in (0, ASCII, LOCALE, UNICODE): | |
raise ValueError("ASCII, LOCALE and UNICODE flags are mutually incompatible") | |
if isinstance(pattern, bytes) and (info.flags & UNICODE): | |
raise ValueError("cannot use UNICODE flag with a bytes pattern") | |
if not (info.flags & _ALL_ENCODINGS): | |
if isinstance(pattern, str): | |
info.flags |= UNICODE | |
else: | |
info.flags |= ASCII | |
reverse = bool(info.flags & REVERSE) | |
fuzzy = isinstance(parsed, _Fuzzy) | |
# Remember whether this pattern as an inline locale flag. | |
_locale_sensitive[locale_key] = info.inline_locale | |
# Fix the group references. | |
caught_exception = None | |
try: | |
parsed.fix_groups(pattern, reverse, False) | |
except error as e: | |
caught_exception = e | |
if caught_exception: | |
raise error(caught_exception.msg, caught_exception.pattern, | |
caught_exception.pos) | |
# Should we print the parsed pattern? | |
if flags & DEBUG: | |
parsed.dump(indent=0, reverse=reverse) | |
# Optimise the parsed pattern. | |
parsed = parsed.optimise(info, reverse) | |
parsed = parsed.pack_characters(info) | |
# Get the required string. | |
req_offset, req_chars, req_flags = _get_required_string(parsed, info.flags) | |
# Build the named lists. | |
named_lists = {} | |
named_list_indexes = [None] * len(info.named_lists_used) | |
args_needed = set() | |
for key, index in info.named_lists_used.items(): | |
name, case_flags = key | |
values = frozenset(kwargs[name]) | |
if case_flags: | |
items = frozenset(_fold_case(info, v) for v in values) | |
else: | |
items = values | |
named_lists[name] = values | |
named_list_indexes[index] = items | |
args_needed.add((name, values)) | |
# Any unused keyword arguments, possibly resulting from a typo? | |
unused_kwargs = set(kwargs) - set(named_lists) | |
if unused_kwargs and not ignore_unused: | |
any_one = next(iter(unused_kwargs)) | |
> raise ValueError('unused keyword argument {!a}'.format(any_one)) | |
E ValueError: unused keyword argument 'formatter' | |
/usr/lib/python3.8/site-packages/regex/regex.py:585: ValueError | |
_____________________________________________________ test_rebulk_empty_match ______________________________________________________ | |
def test_rebulk_empty_match(): | |
input_string = "The quick brown fox jumps over the lazy dog" | |
> matches = Rebulk(default_rules=False).string("quick").string("own").regex("br(.*?)own", children=True)\ | |
.matches(input_string) | |
rebulk/test/test_rebulk.py:152: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
rebulk/builder.py:179: in regex | |
return self.pattern(self.build_re(*pattern, **kwargs)) | |
rebulk/builder.py:107: in build_re | |
return RePattern(*pattern, **kwargs) | |
rebulk/pattern.py:441: in __init__ | |
pattern = call(re.compile, pattern, **self._kwargs) | |
rebulk/loose.py:60: in call | |
return function(*call_args, **call_kwargs) | |
/usr/lib/python3.8/site-packages/regex/regex.py:348: in compile | |
return _compile(pattern, flags, ignore_unused, kwargs) | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
pattern = 'br(.*?)own', flags = 0, ignore_unused = False, kwargs = {'children': True} | |
def _compile(pattern, flags, ignore_unused, kwargs): | |
"Compiles a regular expression to a PatternObject." | |
global DEFAULT_VERSION | |
try: | |
from regex import DEFAULT_VERSION | |
except ImportError: | |
pass | |
# We won't bother to cache the pattern if we're debugging. | |
debugging = (flags & DEBUG) != 0 | |
# What locale is this pattern using? | |
locale_key = (type(pattern), pattern) | |
if _locale_sensitive.get(locale_key, True) or (flags & LOCALE) != 0: | |
# This pattern is, or might be, locale-sensitive. | |
pattern_locale = _getpreferredencoding() | |
else: | |
# This pattern is definitely not locale-sensitive. | |
pattern_locale = None | |
if not debugging: | |
try: | |
# Do we know what keyword arguments are needed? | |
args_key = pattern, type(pattern), flags | |
args_needed = _named_args[args_key] | |
# Are we being provided with its required keyword arguments? | |
args_supplied = set() | |
if args_needed: | |
for k, v in args_needed: | |
try: | |
args_supplied.add((k, frozenset(kwargs[k]))) | |
except KeyError: | |
raise error("missing named list: {!r}".format(k)) | |
args_supplied = frozenset(args_supplied) | |
# Have we already seen this regular expression and named list? | |
pattern_key = (pattern, type(pattern), flags, args_supplied, | |
DEFAULT_VERSION, pattern_locale) | |
return _cache[pattern_key] | |
except KeyError: | |
# It's a new pattern, or new named list for a known pattern. | |
pass | |
# Guess the encoding from the class of the pattern string. | |
if isinstance(pattern, str): | |
guess_encoding = UNICODE | |
elif isinstance(pattern, bytes): | |
guess_encoding = ASCII | |
elif isinstance(pattern, Pattern): | |
if flags: | |
raise ValueError("cannot process flags argument with a compiled pattern") | |
return pattern | |
else: | |
raise TypeError("first argument must be a string or compiled pattern") | |
# Set the default version in the core code in case it has been changed. | |
_regex_core.DEFAULT_VERSION = DEFAULT_VERSION | |
global_flags = flags | |
while True: | |
caught_exception = None | |
try: | |
source = _Source(pattern) | |
info = _Info(global_flags, source.char_type, kwargs) | |
info.guess_encoding = guess_encoding | |
source.ignore_space = bool(info.flags & VERBOSE) | |
parsed = _parse_pattern(source, info) | |
break | |
except _UnscopedFlagSet: | |
# Remember the global flags for the next attempt. | |
global_flags = info.global_flags | |
except error as e: | |
caught_exception = e | |
if caught_exception: | |
raise error(caught_exception.msg, caught_exception.pattern, | |
caught_exception.pos) | |
if not source.at_end(): | |
raise error("unbalanced parenthesis", pattern, source.pos) | |
# Check the global flags for conflicts. | |
version = (info.flags & _ALL_VERSIONS) or DEFAULT_VERSION | |
if version not in (0, VERSION0, VERSION1): | |
raise ValueError("VERSION0 and VERSION1 flags are mutually incompatible") | |
if (info.flags & _ALL_ENCODINGS) not in (0, ASCII, LOCALE, UNICODE): | |
raise ValueError("ASCII, LOCALE and UNICODE flags are mutually incompatible") | |
if isinstance(pattern, bytes) and (info.flags & UNICODE): | |
raise ValueError("cannot use UNICODE flag with a bytes pattern") | |
if not (info.flags & _ALL_ENCODINGS): | |
if isinstance(pattern, str): | |
info.flags |= UNICODE | |
else: | |
info.flags |= ASCII | |
reverse = bool(info.flags & REVERSE) | |
fuzzy = isinstance(parsed, _Fuzzy) | |
# Remember whether this pattern as an inline locale flag. | |
_locale_sensitive[locale_key] = info.inline_locale | |
# Fix the group references. | |
caught_exception = None | |
try: | |
parsed.fix_groups(pattern, reverse, False) | |
except error as e: | |
caught_exception = e | |
if caught_exception: | |
raise error(caught_exception.msg, caught_exception.pattern, | |
caught_exception.pos) | |
# Should we print the parsed pattern? | |
if flags & DEBUG: | |
parsed.dump(indent=0, reverse=reverse) | |
# Optimise the parsed pattern. | |
parsed = parsed.optimise(info, reverse) | |
parsed = parsed.pack_characters(info) | |
# Get the required string. | |
req_offset, req_chars, req_flags = _get_required_string(parsed, info.flags) | |
# Build the named lists. | |
named_lists = {} | |
named_list_indexes = [None] * len(info.named_lists_used) | |
args_needed = set() | |
for key, index in info.named_lists_used.items(): | |
name, case_flags = key | |
values = frozenset(kwargs[name]) | |
if case_flags: | |
items = frozenset(_fold_case(info, v) for v in values) | |
else: | |
items = values | |
named_lists[name] = values | |
named_list_indexes[index] = items | |
args_needed.add((name, values)) | |
# Any unused keyword arguments, possibly resulting from a typo? | |
unused_kwargs = set(kwargs) - set(named_lists) | |
if unused_kwargs and not ignore_unused: | |
any_one = next(iter(unused_kwargs)) | |
> raise ValueError('unused keyword argument {!a}'.format(any_one)) | |
E ValueError: unused keyword argument 'children' | |
/usr/lib/python3.8/site-packages/regex/regex.py:585: ValueError | |
_______________________________________________________ test_rebulk_rules_1 ________________________________________________________ | |
def test_rebulk_rules_1(): | |
rebulk = Rebulk() | |
> rebulk.regex(r'\d{4}', name="year") | |
rebulk/test/test_rebulk.py:198: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
rebulk/builder.py:179: in regex | |
return self.pattern(self.build_re(*pattern, **kwargs)) | |
rebulk/builder.py:107: in build_re | |
return RePattern(*pattern, **kwargs) | |
rebulk/pattern.py:441: in __init__ | |
pattern = call(re.compile, pattern, **self._kwargs) | |
rebulk/loose.py:60: in call | |
return function(*call_args, **call_kwargs) | |
/usr/lib/python3.8/site-packages/regex/regex.py:348: in compile | |
return _compile(pattern, flags, ignore_unused, kwargs) | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
pattern = '\\d{4}', flags = 0, ignore_unused = False, kwargs = {'name': 'year'} | |
def _compile(pattern, flags, ignore_unused, kwargs): | |
"Compiles a regular expression to a PatternObject." | |
global DEFAULT_VERSION | |
try: | |
from regex import DEFAULT_VERSION | |
except ImportError: | |
pass | |
# We won't bother to cache the pattern if we're debugging. | |
debugging = (flags & DEBUG) != 0 | |
# What locale is this pattern using? | |
locale_key = (type(pattern), pattern) | |
if _locale_sensitive.get(locale_key, True) or (flags & LOCALE) != 0: | |
# This pattern is, or might be, locale-sensitive. | |
pattern_locale = _getpreferredencoding() | |
else: | |
# This pattern is definitely not locale-sensitive. | |
pattern_locale = None | |
if not debugging: | |
try: | |
# Do we know what keyword arguments are needed? | |
args_key = pattern, type(pattern), flags | |
args_needed = _named_args[args_key] | |
# Are we being provided with its required keyword arguments? | |
args_supplied = set() | |
if args_needed: | |
for k, v in args_needed: | |
try: | |
args_supplied.add((k, frozenset(kwargs[k]))) | |
except KeyError: | |
raise error("missing named list: {!r}".format(k)) | |
args_supplied = frozenset(args_supplied) | |
# Have we already seen this regular expression and named list? | |
pattern_key = (pattern, type(pattern), flags, args_supplied, | |
DEFAULT_VERSION, pattern_locale) | |
return _cache[pattern_key] | |
except KeyError: | |
# It's a new pattern, or new named list for a known pattern. | |
pass | |
# Guess the encoding from the class of the pattern string. | |
if isinstance(pattern, str): | |
guess_encoding = UNICODE | |
elif isinstance(pattern, bytes): | |
guess_encoding = ASCII | |
elif isinstance(pattern, Pattern): | |
if flags: | |
raise ValueError("cannot process flags argument with a compiled pattern") | |
return pattern | |
else: | |
raise TypeError("first argument must be a string or compiled pattern") | |
# Set the default version in the core code in case it has been changed. | |
_regex_core.DEFAULT_VERSION = DEFAULT_VERSION | |
global_flags = flags | |
while True: | |
caught_exception = None | |
try: | |
source = _Source(pattern) | |
info = _Info(global_flags, source.char_type, kwargs) | |
info.guess_encoding = guess_encoding | |
source.ignore_space = bool(info.flags & VERBOSE) | |
parsed = _parse_pattern(source, info) | |
break | |
except _UnscopedFlagSet: | |
# Remember the global flags for the next attempt. | |
global_flags = info.global_flags | |
except error as e: | |
caught_exception = e | |
if caught_exception: | |
raise error(caught_exception.msg, caught_exception.pattern, | |
caught_exception.pos) | |
if not source.at_end(): | |
raise error("unbalanced parenthesis", pattern, source.pos) | |
# Check the global flags for conflicts. | |
version = (info.flags & _ALL_VERSIONS) or DEFAULT_VERSION | |
if version not in (0, VERSION0, VERSION1): | |
raise ValueError("VERSION0 and VERSION1 flags are mutually incompatible") | |
if (info.flags & _ALL_ENCODINGS) not in (0, ASCII, LOCALE, UNICODE): | |
raise ValueError("ASCII, LOCALE and UNICODE flags are mutually incompatible") | |
if isinstance(pattern, bytes) and (info.flags & UNICODE): | |
raise ValueError("cannot use UNICODE flag with a bytes pattern") | |
if not (info.flags & _ALL_ENCODINGS): | |
if isinstance(pattern, str): | |
info.flags |= UNICODE | |
else: | |
info.flags |= ASCII | |
reverse = bool(info.flags & REVERSE) | |
fuzzy = isinstance(parsed, _Fuzzy) | |
# Remember whether this pattern as an inline locale flag. | |
_locale_sensitive[locale_key] = info.inline_locale | |
# Fix the group references. | |
caught_exception = None | |
try: | |
parsed.fix_groups(pattern, reverse, False) | |
except error as e: | |
caught_exception = e | |
if caught_exception: | |
raise error(caught_exception.msg, caught_exception.pattern, | |
caught_exception.pos) | |
# Should we print the parsed pattern? | |
if flags & DEBUG: | |
parsed.dump(indent=0, reverse=reverse) | |
# Optimise the parsed pattern. | |
parsed = parsed.optimise(info, reverse) | |
parsed = parsed.pack_characters(info) | |
# Get the required string. | |
req_offset, req_chars, req_flags = _get_required_string(parsed, info.flags) | |
# Build the named lists. | |
named_lists = {} | |
named_list_indexes = [None] * len(info.named_lists_used) | |
args_needed = set() | |
for key, index in info.named_lists_used.items(): | |
name, case_flags = key | |
values = frozenset(kwargs[name]) | |
if case_flags: | |
items = frozenset(_fold_case(info, v) for v in values) | |
else: | |
items = values | |
named_lists[name] = values | |
named_list_indexes[index] = items | |
args_needed.add((name, values)) | |
# Any unused keyword arguments, possibly resulting from a typo? | |
unused_kwargs = set(kwargs) - set(named_lists) | |
if unused_kwargs and not ignore_unused: | |
any_one = next(iter(unused_kwargs)) | |
> raise ValueError('unused keyword argument {!a}'.format(any_one)) | |
E ValueError: unused keyword argument 'name' | |
/usr/lib/python3.8/site-packages/regex/regex.py:585: ValueError | |
_______________________________________________________ test_rebulk_rules_2 ________________________________________________________ | |
def test_rebulk_rules_2(): | |
rebulk = Rebulk() | |
> rebulk.regex(r'\d{4}', name="year") | |
rebulk/test/test_rebulk.py:209: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
rebulk/builder.py:179: in regex | |
return self.pattern(self.build_re(*pattern, **kwargs)) | |
rebulk/builder.py:107: in build_re | |
return RePattern(*pattern, **kwargs) | |
rebulk/pattern.py:441: in __init__ | |
pattern = call(re.compile, pattern, **self._kwargs) | |
rebulk/loose.py:60: in call | |
return function(*call_args, **call_kwargs) | |
/usr/lib/python3.8/site-packages/regex/regex.py:348: in compile | |
return _compile(pattern, flags, ignore_unused, kwargs) | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
pattern = '\\d{4}', flags = 0, ignore_unused = False, kwargs = {'name': 'year'} | |
def _compile(pattern, flags, ignore_unused, kwargs): | |
"Compiles a regular expression to a PatternObject." | |
global DEFAULT_VERSION | |
try: | |
from regex import DEFAULT_VERSION | |
except ImportError: | |
pass | |
# We won't bother to cache the pattern if we're debugging. | |
debugging = (flags & DEBUG) != 0 | |
# What locale is this pattern using? | |
locale_key = (type(pattern), pattern) | |
if _locale_sensitive.get(locale_key, True) or (flags & LOCALE) != 0: | |
# This pattern is, or might be, locale-sensitive. | |
pattern_locale = _getpreferredencoding() | |
else: | |
# This pattern is definitely not locale-sensitive. | |
pattern_locale = None | |
if not debugging: | |
try: | |
# Do we know what keyword arguments are needed? | |
args_key = pattern, type(pattern), flags | |
args_needed = _named_args[args_key] | |
# Are we being provided with its required keyword arguments? | |
args_supplied = set() | |
if args_needed: | |
for k, v in args_needed: | |
try: | |
args_supplied.add((k, frozenset(kwargs[k]))) | |
except KeyError: | |
raise error("missing named list: {!r}".format(k)) | |
args_supplied = frozenset(args_supplied) | |
# Have we already seen this regular expression and named list? | |
pattern_key = (pattern, type(pattern), flags, args_supplied, | |
DEFAULT_VERSION, pattern_locale) | |
return _cache[pattern_key] | |
except KeyError: | |
# It's a new pattern, or new named list for a known pattern. | |
pass | |
# Guess the encoding from the class of the pattern string. | |
if isinstance(pattern, str): | |
guess_encoding = UNICODE | |
elif isinstance(pattern, bytes): | |
guess_encoding = ASCII | |
elif isinstance(pattern, Pattern): | |
if flags: | |
raise ValueError("cannot process flags argument with a compiled pattern") | |
return pattern | |
else: | |
raise TypeError("first argument must be a string or compiled pattern") | |
# Set the default version in the core code in case it has been changed. | |
_regex_core.DEFAULT_VERSION = DEFAULT_VERSION | |
global_flags = flags | |
while True: | |
caught_exception = None | |
try: | |
source = _Source(pattern) | |
info = _Info(global_flags, source.char_type, kwargs) | |
info.guess_encoding = guess_encoding | |
source.ignore_space = bool(info.flags & VERBOSE) | |
parsed = _parse_pattern(source, info) | |
break | |
except _UnscopedFlagSet: | |
# Remember the global flags for the next attempt. | |
global_flags = info.global_flags | |
except error as e: | |
caught_exception = e | |
if caught_exception: | |
raise error(caught_exception.msg, caught_exception.pattern, | |
caught_exception.pos) | |
if not source.at_end(): | |
raise error("unbalanced parenthesis", pattern, source.pos) | |
# Check the global flags for conflicts. | |
version = (info.flags & _ALL_VERSIONS) or DEFAULT_VERSION | |
if version not in (0, VERSION0, VERSION1): | |
raise ValueError("VERSION0 and VERSION1 flags are mutually incompatible") | |
if (info.flags & _ALL_ENCODINGS) not in (0, ASCII, LOCALE, UNICODE): | |
raise ValueError("ASCII, LOCALE and UNICODE flags are mutually incompatible") | |
if isinstance(pattern, bytes) and (info.flags & UNICODE): | |
raise ValueError("cannot use UNICODE flag with a bytes pattern") | |
if not (info.flags & _ALL_ENCODINGS): | |
if isinstance(pattern, str): | |
info.flags |= UNICODE | |
else: | |
info.flags |= ASCII | |
reverse = bool(info.flags & REVERSE) | |
fuzzy = isinstance(parsed, _Fuzzy) | |
# Remember whether this pattern as an inline locale flag. | |
_locale_sensitive[locale_key] = info.inline_locale | |
# Fix the group references. | |
caught_exception = None | |
try: | |
parsed.fix_groups(pattern, reverse, False) | |
except error as e: | |
caught_exception = e | |
if caught_exception: | |
raise error(caught_exception.msg, caught_exception.pattern, | |
caught_exception.pos) | |
# Should we print the parsed pattern? | |
if flags & DEBUG: | |
parsed.dump(indent=0, reverse=reverse) | |
# Optimise the parsed pattern. | |
parsed = parsed.optimise(info, reverse) | |
parsed = parsed.pack_characters(info) | |
# Get the required string. | |
req_offset, req_chars, req_flags = _get_required_string(parsed, info.flags) | |
# Build the named lists. | |
named_lists = {} | |
named_list_indexes = [None] * len(info.named_lists_used) | |
args_needed = set() | |
for key, index in info.named_lists_used.items(): | |
name, case_flags = key | |
values = frozenset(kwargs[name]) | |
if case_flags: | |
items = frozenset(_fold_case(info, v) for v in values) | |
else: | |
items = values | |
named_lists[name] = values | |
named_list_indexes[index] = items | |
args_needed.add((name, values)) | |
# Any unused keyword arguments, possibly resulting from a typo? | |
unused_kwargs = set(kwargs) - set(named_lists) | |
if unused_kwargs and not ignore_unused: | |
any_one = next(iter(unused_kwargs)) | |
> raise ValueError('unused keyword argument {!a}'.format(any_one)) | |
E ValueError: unused keyword argument 'name' | |
/usr/lib/python3.8/site-packages/regex/regex.py:585: ValueError | |
_______________________________________________________ test_rebulk_rules_3 ________________________________________________________ | |
def test_rebulk_rules_3(): | |
rebulk = Rebulk() | |
> rebulk.regex(r'\d{4}', name="year") | |
rebulk/test/test_rebulk.py:223: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
rebulk/builder.py:179: in regex | |
return self.pattern(self.build_re(*pattern, **kwargs)) | |
rebulk/builder.py:107: in build_re | |
return RePattern(*pattern, **kwargs) | |
rebulk/pattern.py:441: in __init__ | |
pattern = call(re.compile, pattern, **self._kwargs) | |
rebulk/loose.py:60: in call | |
return function(*call_args, **call_kwargs) | |
/usr/lib/python3.8/site-packages/regex/regex.py:348: in compile | |
return _compile(pattern, flags, ignore_unused, kwargs) | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
pattern = '\\d{4}', flags = 0, ignore_unused = False, kwargs = {'name': 'year'} | |
def _compile(pattern, flags, ignore_unused, kwargs): | |
"Compiles a regular expression to a PatternObject." | |
global DEFAULT_VERSION | |
try: | |
from regex import DEFAULT_VERSION | |
except ImportError: | |
pass | |
# We won't bother to cache the pattern if we're debugging. | |
debugging = (flags & DEBUG) != 0 | |
# What locale is this pattern using? | |
locale_key = (type(pattern), pattern) | |
if _locale_sensitive.get(locale_key, True) or (flags & LOCALE) != 0: | |
# This pattern is, or might be, locale-sensitive. | |
pattern_locale = _getpreferredencoding() | |
else: | |
# This pattern is definitely not locale-sensitive. | |
pattern_locale = None | |
if not debugging: | |
try: | |
# Do we know what keyword arguments are needed? | |
args_key = pattern, type(pattern), flags | |
args_needed = _named_args[args_key] | |
# Are we being provided with its required keyword arguments? | |
args_supplied = set() | |
if args_needed: | |
for k, v in args_needed: | |
try: | |
args_supplied.add((k, frozenset(kwargs[k]))) | |
except KeyError: | |
raise error("missing named list: {!r}".format(k)) | |
args_supplied = frozenset(args_supplied) | |
# Have we already seen this regular expression and named list? | |
pattern_key = (pattern, type(pattern), flags, args_supplied, | |
DEFAULT_VERSION, pattern_locale) | |
return _cache[pattern_key] | |
except KeyError: | |
# It's a new pattern, or new named list for a known pattern. | |
pass | |
# Guess the encoding from the class of the pattern string. | |
if isinstance(pattern, str): | |
guess_encoding = UNICODE | |
elif isinstance(pattern, bytes): | |
guess_encoding = ASCII | |
elif isinstance(pattern, Pattern): | |
if flags: | |
raise ValueError("cannot process flags argument with a compiled pattern") | |
return pattern | |
else: | |
raise TypeError("first argument must be a string or compiled pattern") | |
# Set the default version in the core code in case it has been changed. | |
_regex_core.DEFAULT_VERSION = DEFAULT_VERSION | |
global_flags = flags | |
while True: | |
caught_exception = None | |
try: | |
source = _Source(pattern) | |
info = _Info(global_flags, source.char_type, kwargs) | |
info.guess_encoding = guess_encoding | |
source.ignore_space = bool(info.flags & VERBOSE) | |
parsed = _parse_pattern(source, info) | |
break | |
except _UnscopedFlagSet: | |
# Remember the global flags for the next attempt. | |
global_flags = info.global_flags | |
except error as e: | |
caught_exception = e | |
if caught_exception: | |
raise error(caught_exception.msg, caught_exception.pattern, | |
caught_exception.pos) | |
if not source.at_end(): | |
raise error("unbalanced parenthesis", pattern, source.pos) | |
# Check the global flags for conflicts. | |
version = (info.flags & _ALL_VERSIONS) or DEFAULT_VERSION | |
if version not in (0, VERSION0, VERSION1): | |
raise ValueError("VERSION0 and VERSION1 flags are mutually incompatible") | |
if (info.flags & _ALL_ENCODINGS) not in (0, ASCII, LOCALE, UNICODE): | |
raise ValueError("ASCII, LOCALE and UNICODE flags are mutually incompatible") | |
if isinstance(pattern, bytes) and (info.flags & UNICODE): | |
raise ValueError("cannot use UNICODE flag with a bytes pattern") | |
if not (info.flags & _ALL_ENCODINGS): | |
if isinstance(pattern, str): | |
info.flags |= UNICODE | |
else: | |
info.flags |= ASCII | |
reverse = bool(info.flags & REVERSE) | |
fuzzy = isinstance(parsed, _Fuzzy) | |
# Remember whether this pattern as an inline locale flag. | |
_locale_sensitive[locale_key] = info.inline_locale | |
# Fix the group references. | |
caught_exception = None | |
try: | |
parsed.fix_groups(pattern, reverse, False) | |
except error as e: | |
caught_exception = e | |
if caught_exception: | |
raise error(caught_exception.msg, caught_exception.pattern, | |
caught_exception.pos) | |
# Should we print the parsed pattern? | |
if flags & DEBUG: | |
parsed.dump(indent=0, reverse=reverse) | |
# Optimise the parsed pattern. | |
parsed = parsed.optimise(info, reverse) | |
parsed = parsed.pack_characters(info) | |
# Get the required string. | |
req_offset, req_chars, req_flags = _get_required_string(parsed, info.flags) | |
# Build the named lists. | |
named_lists = {} | |
named_list_indexes = [None] * len(info.named_lists_used) | |
args_needed = set() | |
for key, index in info.named_lists_used.items(): | |
name, case_flags = key | |
values = frozenset(kwargs[name]) | |
if case_flags: | |
items = frozenset(_fold_case(info, v) for v in values) | |
else: | |
items = values | |
named_lists[name] = values | |
named_list_indexes[index] = items | |
args_needed.add((name, values)) | |
# Any unused keyword arguments, possibly resulting from a typo? | |
unused_kwargs = set(kwargs) - set(named_lists) | |
if unused_kwargs and not ignore_unused: | |
any_one = next(iter(unused_kwargs)) | |
> raise ValueError('unused keyword argument {!a}'.format(any_one)) | |
E ValueError: unused keyword argument 'name' | |
/usr/lib/python3.8/site-packages/regex/regex.py:585: ValueError | |
_______________________________________________________ test_rebulk_rules_4 ________________________________________________________ | |
def test_rebulk_rules_4(): | |
class FirstOnlyRule(Rule): | |
def when(self, matches, context): | |
grabbed = matches.named("grabbed", 0) | |
if grabbed and matches.previous(grabbed): | |
return grabbed | |
def then(self, matches, when_response, context): | |
matches.remove(when_response) | |
rebulk = Rebulk() | |
> rebulk.regex("This match (.*?)grabbed", name="grabbed") | |
rebulk/test/test_rebulk.py:246: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
rebulk/builder.py:179: in regex | |
return self.pattern(self.build_re(*pattern, **kwargs)) | |
rebulk/builder.py:107: in build_re | |
return RePattern(*pattern, **kwargs) | |
rebulk/pattern.py:441: in __init__ | |
pattern = call(re.compile, pattern, **self._kwargs) | |
rebulk/loose.py:60: in call | |
return function(*call_args, **call_kwargs) | |
/usr/lib/python3.8/site-packages/regex/regex.py:348: in compile | |
return _compile(pattern, flags, ignore_unused, kwargs) | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
pattern = 'This match (.*?)grabbed', flags = 0, ignore_unused = False, kwargs = {'name': 'grabbed'} | |
def _compile(pattern, flags, ignore_unused, kwargs): | |
"Compiles a regular expression to a PatternObject." | |
global DEFAULT_VERSION | |
try: | |
from regex import DEFAULT_VERSION | |
except ImportError: | |
pass | |
# We won't bother to cache the pattern if we're debugging. | |
debugging = (flags & DEBUG) != 0 | |
# What locale is this pattern using? | |
locale_key = (type(pattern), pattern) | |
if _locale_sensitive.get(locale_key, True) or (flags & LOCALE) != 0: | |
# This pattern is, or might be, locale-sensitive. | |
pattern_locale = _getpreferredencoding() | |
else: | |
# This pattern is definitely not locale-sensitive. | |
pattern_locale = None | |
if not debugging: | |
try: | |
# Do we know what keyword arguments are needed? | |
args_key = pattern, type(pattern), flags | |
args_needed = _named_args[args_key] | |
# Are we being provided with its required keyword arguments? | |
args_supplied = set() | |
if args_needed: | |
for k, v in args_needed: | |
try: | |
args_supplied.add((k, frozenset(kwargs[k]))) | |
except KeyError: | |
raise error("missing named list: {!r}".format(k)) | |
args_supplied = frozenset(args_supplied) | |
# Have we already seen this regular expression and named list? | |
pattern_key = (pattern, type(pattern), flags, args_supplied, | |
DEFAULT_VERSION, pattern_locale) | |
return _cache[pattern_key] | |
except KeyError: | |
# It's a new pattern, or new named list for a known pattern. | |
pass | |
# Guess the encoding from the class of the pattern string. | |
if isinstance(pattern, str): | |
guess_encoding = UNICODE | |
elif isinstance(pattern, bytes): | |
guess_encoding = ASCII | |
elif isinstance(pattern, Pattern): | |
if flags: | |
raise ValueError("cannot process flags argument with a compiled pattern") | |
return pattern | |
else: | |
raise TypeError("first argument must be a string or compiled pattern") | |
# Set the default version in the core code in case it has been changed. | |
_regex_core.DEFAULT_VERSION = DEFAULT_VERSION | |
global_flags = flags | |
while True: | |
caught_exception = None | |
try: | |
source = _Source(pattern) | |
info = _Info(global_flags, source.char_type, kwargs) | |
info.guess_encoding = guess_encoding | |
source.ignore_space = bool(info.flags & VERBOSE) | |
parsed = _parse_pattern(source, info) | |
break | |
except _UnscopedFlagSet: | |
# Remember the global flags for the next attempt. | |
global_flags = info.global_flags | |
except error as e: | |
caught_exception = e | |
if caught_exception: | |
raise error(caught_exception.msg, caught_exception.pattern, | |
caught_exception.pos) | |
if not source.at_end(): | |
raise error("unbalanced parenthesis", pattern, source.pos) | |
# Check the global flags for conflicts. | |
version = (info.flags & _ALL_VERSIONS) or DEFAULT_VERSION | |
if version not in (0, VERSION0, VERSION1): | |
raise ValueError("VERSION0 and VERSION1 flags are mutually incompatible") | |
if (info.flags & _ALL_ENCODINGS) not in (0, ASCII, LOCALE, UNICODE): | |
raise ValueError("ASCII, LOCALE and UNICODE flags are mutually incompatible") | |
if isinstance(pattern, bytes) and (info.flags & UNICODE): | |
raise ValueError("cannot use UNICODE flag with a bytes pattern") | |
if not (info.flags & _ALL_ENCODINGS): | |
if isinstance(pattern, str): | |
info.flags |= UNICODE | |
else: | |
info.flags |= ASCII | |
reverse = bool(info.flags & REVERSE) | |
fuzzy = isinstance(parsed, _Fuzzy) | |
# Remember whether this pattern as an inline locale flag. | |
_locale_sensitive[locale_key] = info.inline_locale | |
# Fix the group references. | |
caught_exception = None | |
try: | |
parsed.fix_groups(pattern, reverse, False) | |
except error as e: | |
caught_exception = e | |
if caught_exception: | |
raise error(caught_exception.msg, caught_exception.pattern, | |
caught_exception.pos) | |
# Should we print the parsed pattern? | |
if flags & DEBUG: | |
parsed.dump(indent=0, reverse=reverse) | |
# Optimise the parsed pattern. | |
parsed = parsed.optimise(info, reverse) | |
parsed = parsed.pack_characters(info) | |
# Get the required string. | |
req_offset, req_chars, req_flags = _get_required_string(parsed, info.flags) | |
# Build the named lists. | |
named_lists = {} | |
named_list_indexes = [None] * len(info.named_lists_used) | |
args_needed = set() | |
for key, index in info.named_lists_used.items(): | |
name, case_flags = key | |
values = frozenset(kwargs[name]) | |
if case_flags: | |
items = frozenset(_fold_case(info, v) for v in values) | |
else: | |
items = values | |
named_lists[name] = values | |
named_list_indexes[index] = items | |
args_needed.add((name, values)) | |
# Any unused keyword arguments, possibly resulting from a typo? | |
unused_kwargs = set(kwargs) - set(named_lists) | |
if unused_kwargs and not ignore_unused: | |
any_one = next(iter(unused_kwargs)) | |
> raise ValueError('unused keyword argument {!a}'.format(any_one)) | |
E ValueError: unused keyword argument 'name' | |
/usr/lib/python3.8/site-packages/regex/regex.py:585: ValueError | |
___________________________________________________ TestMarkers.test_one_marker ____________________________________________________ | |
self = <rebulk.test.test_rebulk.TestMarkers object at 0x7ff81a878520> | |
def test_one_marker(self): | |
class MarkerRule(Rule): | |
def when(self, matches, context): | |
word_match = matches.named("word", 0) | |
marker = matches.markers.at_match(word_match, lambda marker: marker.name == "mark1", 0) | |
if not marker: | |
return word_match | |
def then(self, matches, when_response, context): | |
matches.remove(when_response) | |
> rebulk = Rebulk().regex(r'\(.*?\)', marker=True, name="mark1") \ | |
.regex(r'\[.*?\]', marker=True, name="mark2") \ | |
.string("word", name="word") \ | |
.rules(MarkerRule) | |
rebulk/test/test_rebulk.py:271: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
rebulk/builder.py:179: in regex | |
return self.pattern(self.build_re(*pattern, **kwargs)) | |
rebulk/builder.py:107: in build_re | |
return RePattern(*pattern, **kwargs) | |
rebulk/pattern.py:441: in __init__ | |
pattern = call(re.compile, pattern, **self._kwargs) | |
rebulk/loose.py:60: in call | |
return function(*call_args, **call_kwargs) | |
/usr/lib/python3.8/site-packages/regex/regex.py:348: in compile | |
return _compile(pattern, flags, ignore_unused, kwargs) | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
pattern = '\\(.*?\\)', flags = 0, ignore_unused = False, kwargs = {'marker': True, 'name': 'mark1'} | |
def _compile(pattern, flags, ignore_unused, kwargs): | |
"Compiles a regular expression to a PatternObject." | |
global DEFAULT_VERSION | |
try: | |
from regex import DEFAULT_VERSION | |
except ImportError: | |
pass | |
# We won't bother to cache the pattern if we're debugging. | |
debugging = (flags & DEBUG) != 0 | |
# What locale is this pattern using? | |
locale_key = (type(pattern), pattern) | |
if _locale_sensitive.get(locale_key, True) or (flags & LOCALE) != 0: | |
# This pattern is, or might be, locale-sensitive. | |
pattern_locale = _getpreferredencoding() | |
else: | |
# This pattern is definitely not locale-sensitive. | |
pattern_locale = None | |
if not debugging: | |
try: | |
# Do we know what keyword arguments are needed? | |
args_key = pattern, type(pattern), flags | |
args_needed = _named_args[args_key] | |
# Are we being provided with its required keyword arguments? | |
args_supplied = set() | |
if args_needed: | |
for k, v in args_needed: | |
try: | |
args_supplied.add((k, frozenset(kwargs[k]))) | |
except KeyError: | |
raise error("missing named list: {!r}".format(k)) | |
args_supplied = frozenset(args_supplied) | |
# Have we already seen this regular expression and named list? | |
pattern_key = (pattern, type(pattern), flags, args_supplied, | |
DEFAULT_VERSION, pattern_locale) | |
return _cache[pattern_key] | |
except KeyError: | |
# It's a new pattern, or new named list for a known pattern. | |
pass | |
# Guess the encoding from the class of the pattern string. | |
if isinstance(pattern, str): | |
guess_encoding = UNICODE | |
elif isinstance(pattern, bytes): | |
guess_encoding = ASCII | |
elif isinstance(pattern, Pattern): | |
if flags: | |
raise ValueError("cannot process flags argument with a compiled pattern") | |
return pattern | |
else: | |
raise TypeError("first argument must be a string or compiled pattern") | |
# Set the default version in the core code in case it has been changed. | |
_regex_core.DEFAULT_VERSION = DEFAULT_VERSION | |
global_flags = flags | |
while True: | |
caught_exception = None | |
try: | |
source = _Source(pattern) | |
info = _Info(global_flags, source.char_type, kwargs) | |
info.guess_encoding = guess_encoding | |
source.ignore_space = bool(info.flags & VERBOSE) | |
parsed = _parse_pattern(source, info) | |
break | |
except _UnscopedFlagSet: | |
# Remember the global flags for the next attempt. | |
global_flags = info.global_flags | |
except error as e: | |
caught_exception = e | |
if caught_exception: | |
raise error(caught_exception.msg, caught_exception.pattern, | |
caught_exception.pos) | |
if not source.at_end(): | |
raise error("unbalanced parenthesis", pattern, source.pos) | |
# Check the global flags for conflicts. | |
version = (info.flags & _ALL_VERSIONS) or DEFAULT_VERSION | |
if version not in (0, VERSION0, VERSION1): | |
raise ValueError("VERSION0 and VERSION1 flags are mutually incompatible") | |
if (info.flags & _ALL_ENCODINGS) not in (0, ASCII, LOCALE, UNICODE): | |
raise ValueError("ASCII, LOCALE and UNICODE flags are mutually incompatible") | |
if isinstance(pattern, bytes) and (info.flags & UNICODE): | |
raise ValueError("cannot use UNICODE flag with a bytes pattern") | |
if not (info.flags & _ALL_ENCODINGS): | |
if isinstance(pattern, str): | |
info.flags |= UNICODE | |
else: | |
info.flags |= ASCII | |
reverse = bool(info.flags & REVERSE) | |
fuzzy = isinstance(parsed, _Fuzzy) | |
# Remember whether this pattern as an inline locale flag. | |
_locale_sensitive[locale_key] = info.inline_locale | |
# Fix the group references. | |
caught_exception = None | |
try: | |
parsed.fix_groups(pattern, reverse, False) | |
except error as e: | |
caught_exception = e | |
if caught_exception: | |
raise error(caught_exception.msg, caught_exception.pattern, | |
caught_exception.pos) | |
# Should we print the parsed pattern? | |
if flags & DEBUG: | |
parsed.dump(indent=0, reverse=reverse) | |
# Optimise the parsed pattern. | |
parsed = parsed.optimise(info, reverse) | |
parsed = parsed.pack_characters(info) | |
# Get the required string. | |
req_offset, req_chars, req_flags = _get_required_string(parsed, info.flags) | |
# Build the named lists. | |
named_lists = {} | |
named_list_indexes = [None] * len(info.named_lists_used) | |
args_needed = set() | |
for key, index in info.named_lists_used.items(): | |
name, case_flags = key | |
values = frozenset(kwargs[name]) | |
if case_flags: | |
items = frozenset(_fold_case(info, v) for v in values) | |
else: | |
items = values | |
named_lists[name] = values | |
named_list_indexes[index] = items | |
args_needed.add((name, values)) | |
# Any unused keyword arguments, possibly resulting from a typo? | |
unused_kwargs = set(kwargs) - set(named_lists) | |
if unused_kwargs and not ignore_unused: | |
any_one = next(iter(unused_kwargs)) | |
> raise ValueError('unused keyword argument {!a}'.format(any_one)) | |
E ValueError: unused keyword argument 'marker' | |
/usr/lib/python3.8/site-packages/regex/regex.py:585: ValueError | |
_________________________________________________ TestMarkers.test_multiple_marker _________________________________________________ | |
self = <rebulk.test.test_rebulk.TestMarkers object at 0x7ff81aaa9730> | |
def test_multiple_marker(self): | |
class MarkerRule(Rule): | |
def when(self, matches, context): | |
word_match = matches.named("word", 0) | |
marker = matches.markers.at_match(word_match, | |
lambda marker: marker.name == "mark1" or marker.name == "mark2") | |
if len(marker) < 2: | |
return word_match | |
def then(self, matches, when_response, context): | |
matches.remove(when_response) | |
> rebulk = Rebulk().regex(r'\(.*?\)', marker=True, name="mark1") \ | |
.regex(r'\[.*?\]', marker=True, name="mark2") \ | |
.regex("w.*?d", name="word") \ | |
.rules(MarkerRule) | |
rebulk/test/test_rebulk.py:299: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
rebulk/builder.py:179: in regex | |
return self.pattern(self.build_re(*pattern, **kwargs)) | |
rebulk/builder.py:107: in build_re | |
return RePattern(*pattern, **kwargs) | |
rebulk/pattern.py:441: in __init__ | |
pattern = call(re.compile, pattern, **self._kwargs) | |
rebulk/loose.py:60: in call | |
return function(*call_args, **call_kwargs) | |
/usr/lib/python3.8/site-packages/regex/regex.py:348: in compile | |
return _compile(pattern, flags, ignore_unused, kwargs) | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
pattern = '\\(.*?\\)', flags = 0, ignore_unused = False, kwargs = {'marker': True, 'name': 'mark1'} | |
def _compile(pattern, flags, ignore_unused, kwargs): | |
"Compiles a regular expression to a PatternObject." | |
global DEFAULT_VERSION | |
try: | |
from regex import DEFAULT_VERSION | |
except ImportError: | |
pass | |
# We won't bother to cache the pattern if we're debugging. | |
debugging = (flags & DEBUG) != 0 | |
# What locale is this pattern using? | |
locale_key = (type(pattern), pattern) | |
if _locale_sensitive.get(locale_key, True) or (flags & LOCALE) != 0: | |
# This pattern is, or might be, locale-sensitive. | |
pattern_locale = _getpreferredencoding() | |
else: | |
# This pattern is definitely not locale-sensitive. | |
pattern_locale = None | |
if not debugging: | |
try: | |
# Do we know what keyword arguments are needed? | |
args_key = pattern, type(pattern), flags | |
args_needed = _named_args[args_key] | |
# Are we being provided with its required keyword arguments? | |
args_supplied = set() | |
if args_needed: | |
for k, v in args_needed: | |
try: | |
args_supplied.add((k, frozenset(kwargs[k]))) | |
except KeyError: | |
raise error("missing named list: {!r}".format(k)) | |
args_supplied = frozenset(args_supplied) | |
# Have we already seen this regular expression and named list? | |
pattern_key = (pattern, type(pattern), flags, args_supplied, | |
DEFAULT_VERSION, pattern_locale) | |
return _cache[pattern_key] | |
except KeyError: | |
# It's a new pattern, or new named list for a known pattern. | |
pass | |
# Guess the encoding from the class of the pattern string. | |
if isinstance(pattern, str): | |
guess_encoding = UNICODE | |
elif isinstance(pattern, bytes): | |
guess_encoding = ASCII | |
elif isinstance(pattern, Pattern): | |
if flags: | |
raise ValueError("cannot process flags argument with a compiled pattern") | |
return pattern | |
else: | |
raise TypeError("first argument must be a string or compiled pattern") | |
# Set the default version in the core code in case it has been changed. | |
_regex_core.DEFAULT_VERSION = DEFAULT_VERSION | |
global_flags = flags | |
while True: | |
caught_exception = None | |
try: | |
source = _Source(pattern) | |
info = _Info(global_flags, source.char_type, kwargs) | |
info.guess_encoding = guess_encoding | |
source.ignore_space = bool(info.flags & VERBOSE) | |
parsed = _parse_pattern(source, info) | |
break | |
except _UnscopedFlagSet: | |
# Remember the global flags for the next attempt. | |
global_flags = info.global_flags | |
except error as e: | |
caught_exception = e | |
if caught_exception: | |
raise error(caught_exception.msg, caught_exception.pattern, | |
caught_exception.pos) | |
if not source.at_end(): | |
raise error("unbalanced parenthesis", pattern, source.pos) | |
# Check the global flags for conflicts. | |
version = (info.flags & _ALL_VERSIONS) or DEFAULT_VERSION | |
if version not in (0, VERSION0, VERSION1): | |
raise ValueError("VERSION0 and VERSION1 flags are mutually incompatible") | |
if (info.flags & _ALL_ENCODINGS) not in (0, ASCII, LOCALE, UNICODE): | |
raise ValueError("ASCII, LOCALE and UNICODE flags are mutually incompatible") | |
if isinstance(pattern, bytes) and (info.flags & UNICODE): | |
raise ValueError("cannot use UNICODE flag with a bytes pattern") | |
if not (info.flags & _ALL_ENCODINGS): | |
if isinstance(pattern, str): | |
info.flags |= UNICODE | |
else: | |
info.flags |= ASCII | |
reverse = bool(info.flags & REVERSE) | |
fuzzy = isinstance(parsed, _Fuzzy) | |
# Remember whether this pattern as an inline locale flag. | |
_locale_sensitive[locale_key] = info.inline_locale | |
# Fix the group references. | |
caught_exception = None | |
try: | |
parsed.fix_groups(pattern, reverse, False) | |
except error as e: | |
caught_exception = e | |
if caught_exception: | |
raise error(caught_exception.msg, caught_exception.pattern, | |
caught_exception.pos) | |
# Should we print the parsed pattern? | |
if flags & DEBUG: | |
parsed.dump(indent=0, reverse=reverse) | |
# Optimise the parsed pattern. | |
parsed = parsed.optimise(info, reverse) | |
parsed = parsed.pack_characters(info) | |
# Get the required string. | |
req_offset, req_chars, req_flags = _get_required_string(parsed, info.flags) | |
# Build the named lists. | |
named_lists = {} | |
named_list_indexes = [None] * len(info.named_lists_used) | |
args_needed = set() | |
for key, index in info.named_lists_used.items(): | |
name, case_flags = key | |
values = frozenset(kwargs[name]) | |
if case_flags: | |
items = frozenset(_fold_case(info, v) for v in values) | |
else: | |
items = values | |
named_lists[name] = values | |
named_list_indexes[index] = items | |
args_needed.add((name, values)) | |
# Any unused keyword arguments, possibly resulting from a typo? | |
unused_kwargs = set(kwargs) - set(named_lists) | |
if unused_kwargs and not ignore_unused: | |
any_one = next(iter(unused_kwargs)) | |
> raise ValueError('unused keyword argument {!a}'.format(any_one)) | |
E ValueError: unused keyword argument 'marker' | |
/usr/lib/python3.8/site-packages/regex/regex.py:585: ValueError | |
_________________________________________________ TestMarkers.test_at_index_marker _________________________________________________ | |
self = <rebulk.test.test_rebulk.TestMarkers object at 0x7ff81ab1cb50> | |
def test_at_index_marker(self): | |
class MarkerRule(Rule): | |
def when(self, matches, context): | |
word_match = matches.named("word", 0) | |
marker = matches.markers.at_index(word_match.start, | |
lambda marker: marker.name == "mark1", 0) | |
if not marker: | |
return word_match | |
def then(self, matches, when_response, context): | |
matches.remove(when_response) | |
> rebulk = Rebulk().regex(r'\(.*?\)', marker=True, name="mark1") \ | |
.regex("w.*?d", name="word") \ | |
.rules(MarkerRule) | |
rebulk/test/test_rebulk.py:328: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
rebulk/builder.py:179: in regex | |
return self.pattern(self.build_re(*pattern, **kwargs)) | |
rebulk/builder.py:107: in build_re | |
return RePattern(*pattern, **kwargs) | |
rebulk/pattern.py:441: in __init__ | |
pattern = call(re.compile, pattern, **self._kwargs) | |
rebulk/loose.py:60: in call | |
return function(*call_args, **call_kwargs) | |
/usr/lib/python3.8/site-packages/regex/regex.py:348: in compile | |
return _compile(pattern, flags, ignore_unused, kwargs) | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
pattern = '\\(.*?\\)', flags = 0, ignore_unused = False, kwargs = {'marker': True, 'name': 'mark1'} | |
def _compile(pattern, flags, ignore_unused, kwargs): | |
"Compiles a regular expression to a PatternObject." | |
global DEFAULT_VERSION | |
try: | |
from regex import DEFAULT_VERSION | |
except ImportError: | |
pass | |
# We won't bother to cache the pattern if we're debugging. | |
debugging = (flags & DEBUG) != 0 | |
# What locale is this pattern using? | |
locale_key = (type(pattern), pattern) | |
if _locale_sensitive.get(locale_key, True) or (flags & LOCALE) != 0: | |
# This pattern is, or might be, locale-sensitive. | |
pattern_locale = _getpreferredencoding() | |
else: | |
# This pattern is definitely not locale-sensitive. | |
pattern_locale = None | |
if not debugging: | |
try: | |
# Do we know what keyword arguments are needed? | |
args_key = pattern, type(pattern), flags | |
args_needed = _named_args[args_key] | |
# Are we being provided with its required keyword arguments? | |
args_supplied = set() | |
if args_needed: | |
for k, v in args_needed: | |
try: | |
args_supplied.add((k, frozenset(kwargs[k]))) | |
except KeyError: | |
raise error("missing named list: {!r}".format(k)) | |
args_supplied = frozenset(args_supplied) | |
# Have we already seen this regular expression and named list? | |
pattern_key = (pattern, type(pattern), flags, args_supplied, | |
DEFAULT_VERSION, pattern_locale) | |
return _cache[pattern_key] | |
except KeyError: | |
# It's a new pattern, or new named list for a known pattern. | |
pass | |
# Guess the encoding from the class of the pattern string. | |
if isinstance(pattern, str): | |
guess_encoding = UNICODE | |
elif isinstance(pattern, bytes): | |
guess_encoding = ASCII | |
elif isinstance(pattern, Pattern): | |
if flags: | |
raise ValueError("cannot process flags argument with a compiled pattern") | |
return pattern | |
else: | |
raise TypeError("first argument must be a string or compiled pattern") | |
# Set the default version in the core code in case it has been changed. | |
_regex_core.DEFAULT_VERSION = DEFAULT_VERSION | |
global_flags = flags | |
while True: | |
caught_exception = None | |
try: | |
source = _Source(pattern) | |
info = _Info(global_flags, source.char_type, kwargs) | |
info.guess_encoding = guess_encoding | |
source.ignore_space = bool(info.flags & VERBOSE) | |
parsed = _parse_pattern(source, info) | |
break | |
except _UnscopedFlagSet: | |
# Remember the global flags for the next attempt. | |
global_flags = info.global_flags | |
except error as e: | |
caught_exception = e | |
if caught_exception: | |
raise error(caught_exception.msg, caught_exception.pattern, | |
caught_exception.pos) | |
if not source.at_end(): | |
raise error("unbalanced parenthesis", pattern, source.pos) | |
# Check the global flags for conflicts. | |
version = (info.flags & _ALL_VERSIONS) or DEFAULT_VERSION | |
if version not in (0, VERSION0, VERSION1): | |
raise ValueError("VERSION0 and VERSION1 flags are mutually incompatible") | |
if (info.flags & _ALL_ENCODINGS) not in (0, ASCII, LOCALE, UNICODE): | |
raise ValueError("ASCII, LOCALE and UNICODE flags are mutually incompatible") | |
if isinstance(pattern, bytes) and (info.flags & UNICODE): | |
raise ValueError("cannot use UNICODE flag with a bytes pattern") | |
if not (info.flags & _ALL_ENCODINGS): | |
if isinstance(pattern, str): | |
info.flags |= UNICODE | |
else: | |
info.flags |= ASCII | |
reverse = bool(info.flags & REVERSE) | |
fuzzy = isinstance(parsed, _Fuzzy) | |
# Remember whether this pattern as an inline locale flag. | |
_locale_sensitive[locale_key] = info.inline_locale | |
# Fix the group references. | |
caught_exception = None | |
try: | |
parsed.fix_groups(pattern, reverse, False) | |
except error as e: | |
caught_exception = e | |
if caught_exception: | |
raise error(caught_exception.msg, caught_exception.pattern, | |
caught_exception.pos) | |
# Should we print the parsed pattern? | |
if flags & DEBUG: | |
parsed.dump(indent=0, reverse=reverse) | |
# Optimise the parsed pattern. | |
parsed = parsed.optimise(info, reverse) | |
parsed = parsed.pack_characters(info) | |
# Get the required string. | |
req_offset, req_chars, req_flags = _get_required_string(parsed, info.flags) | |
# Build the named lists. | |
named_lists = {} | |
named_list_indexes = [None] * len(info.named_lists_used) | |
args_needed = set() | |
for key, index in info.named_lists_used.items(): | |
name, case_flags = key | |
values = frozenset(kwargs[name]) | |
if case_flags: | |
items = frozenset(_fold_case(info, v) for v in values) | |
else: | |
items = values | |
named_lists[name] = values | |
named_list_indexes[index] = items | |
args_needed.add((name, values)) | |
# Any unused keyword arguments, possibly resulting from a typo? | |
unused_kwargs = set(kwargs) - set(named_lists) | |
if unused_kwargs and not ignore_unused: | |
any_one = next(iter(unused_kwargs)) | |
> raise ValueError('unused keyword argument {!a}'.format(any_one)) | |
E ValueError: unused keyword argument 'marker' | |
/usr/lib/python3.8/site-packages/regex/regex.py:585: ValueError | |
__________________________________________________ TestMarkers.test_remove_marker __________________________________________________ | |
self = <rebulk.test.test_rebulk.TestMarkers object at 0x7ff81ab1b0a0> | |
def test_remove_marker(self): | |
class MarkerRule(Rule): | |
def when(self, matches, context): | |
marker = matches.markers.named("mark1", 0) | |
if marker: | |
return marker | |
def then(self, matches, when_response, context): | |
matches.markers.remove(when_response) | |
> rebulk = Rebulk().regex(r'\(.*?\)', marker=True, name="mark1") \ | |
.regex("w.*?d", name="word") \ | |
.rules(MarkerRule) | |
rebulk/test/test_rebulk.py:351: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
rebulk/builder.py:179: in regex | |
return self.pattern(self.build_re(*pattern, **kwargs)) | |
rebulk/builder.py:107: in build_re | |
return RePattern(*pattern, **kwargs) | |
rebulk/pattern.py:441: in __init__ | |
pattern = call(re.compile, pattern, **self._kwargs) | |
rebulk/loose.py:60: in call | |
return function(*call_args, **call_kwargs) | |
/usr/lib/python3.8/site-packages/regex/regex.py:348: in compile | |
return _compile(pattern, flags, ignore_unused, kwargs) | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
pattern = '\\(.*?\\)', flags = 0, ignore_unused = False, kwargs = {'marker': True, 'name': 'mark1'} | |
def _compile(pattern, flags, ignore_unused, kwargs): | |
"Compiles a regular expression to a PatternObject." | |
global DEFAULT_VERSION | |
try: | |
from regex import DEFAULT_VERSION | |
except ImportError: | |
pass | |
# We won't bother to cache the pattern if we're debugging. | |
debugging = (flags & DEBUG) != 0 | |
# What locale is this pattern using? | |
locale_key = (type(pattern), pattern) | |
if _locale_sensitive.get(locale_key, True) or (flags & LOCALE) != 0: | |
# This pattern is, or might be, locale-sensitive. | |
pattern_locale = _getpreferredencoding() | |
else: | |
# This pattern is definitely not locale-sensitive. | |
pattern_locale = None | |
if not debugging: | |
try: | |
# Do we know what keyword arguments are needed? | |
args_key = pattern, type(pattern), flags | |
args_needed = _named_args[args_key] | |
# Are we being provided with its required keyword arguments? | |
args_supplied = set() | |
if args_needed: | |
for k, v in args_needed: | |
try: | |
args_supplied.add((k, frozenset(kwargs[k]))) | |
except KeyError: | |
raise error("missing named list: {!r}".format(k)) | |
args_supplied = frozenset(args_supplied) | |
# Have we already seen this regular expression and named list? | |
pattern_key = (pattern, type(pattern), flags, args_supplied, | |
DEFAULT_VERSION, pattern_locale) | |
return _cache[pattern_key] | |
except KeyError: | |
# It's a new pattern, or new named list for a known pattern. | |
pass | |
# Guess the encoding from the class of the pattern string. | |
if isinstance(pattern, str): | |
guess_encoding = UNICODE | |
elif isinstance(pattern, bytes): | |
guess_encoding = ASCII | |
elif isinstance(pattern, Pattern): | |
if flags: | |
raise ValueError("cannot process flags argument with a compiled pattern") | |
return pattern | |
else: | |
raise TypeError("first argument must be a string or compiled pattern") | |
# Set the default version in the core code in case it has been changed. | |
_regex_core.DEFAULT_VERSION = DEFAULT_VERSION | |
global_flags = flags | |
while True: | |
caught_exception = None | |
try: | |
source = _Source(pattern) | |
info = _Info(global_flags, source.char_type, kwargs) | |
info.guess_encoding = guess_encoding | |
source.ignore_space = bool(info.flags & VERBOSE) | |
parsed = _parse_pattern(source, info) | |
break | |
except _UnscopedFlagSet: | |
# Remember the global flags for the next attempt. | |
global_flags = info.global_flags | |
except error as e: | |
caught_exception = e | |
if caught_exception: | |
raise error(caught_exception.msg, caught_exception.pattern, | |
caught_exception.pos) | |
if not source.at_end(): | |
raise error("unbalanced parenthesis", pattern, source.pos) | |
# Check the global flags for conflicts. | |
version = (info.flags & _ALL_VERSIONS) or DEFAULT_VERSION | |
if version not in (0, VERSION0, VERSION1): | |
raise ValueError("VERSION0 and VERSION1 flags are mutually incompatible") | |
if (info.flags & _ALL_ENCODINGS) not in (0, ASCII, LOCALE, UNICODE): | |
raise ValueError("ASCII, LOCALE and UNICODE flags are mutually incompatible") | |
if isinstance(pattern, bytes) and (info.flags & UNICODE): | |
raise ValueError("cannot use UNICODE flag with a bytes pattern") | |
if not (info.flags & _ALL_ENCODINGS): | |
if isinstance(pattern, str): | |
info.flags |= UNICODE | |
else: | |
info.flags |= ASCII | |
reverse = bool(info.flags & REVERSE) | |
fuzzy = isinstance(parsed, _Fuzzy) | |
# Remember whether this pattern as an inline locale flag. | |
_locale_sensitive[locale_key] = info.inline_locale | |
# Fix the group references. | |
caught_exception = None | |
try: | |
parsed.fix_groups(pattern, reverse, False) | |
except error as e: | |
caught_exception = e | |
if caught_exception: | |
raise error(caught_exception.msg, caught_exception.pattern, | |
caught_exception.pos) | |
# Should we print the parsed pattern? | |
if flags & DEBUG: | |
parsed.dump(indent=0, reverse=reverse) | |
# Optimise the parsed pattern. | |
parsed = parsed.optimise(info, reverse) | |
parsed = parsed.pack_characters(info) | |
# Get the required string. | |
req_offset, req_chars, req_flags = _get_required_string(parsed, info.flags) | |
# Build the named lists. | |
named_lists = {} | |
named_list_indexes = [None] * len(info.named_lists_used) | |
args_needed = set() | |
for key, index in info.named_lists_used.items(): | |
name, case_flags = key | |
values = frozenset(kwargs[name]) | |
if case_flags: | |
items = frozenset(_fold_case(info, v) for v in values) | |
else: | |
items = values | |
named_lists[name] = values | |
named_list_indexes[index] = items | |
args_needed.add((name, values)) | |
# Any unused keyword arguments, possibly resulting from a typo? | |
unused_kwargs = set(kwargs) - set(named_lists) | |
if unused_kwargs and not ignore_unused: | |
any_one = next(iter(unused_kwargs)) | |
> raise ValueError('unused keyword argument {!a}'.format(any_one)) | |
E ValueError: unused keyword argument 'marker' | |
/usr/lib/python3.8/site-packages/regex/regex.py:585: ValueError | |
================================================== 39 failed, 126 passed in 3.60s ================================================== | |
==> ERROR: A failure occurred in check(). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment