From 813718517433ff0fb516f52d7d2665a71cb984e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Hrn=C4=8Diar?= Date: Mon, 25 Oct 2021 11:37:46 +0200 Subject: [PATCH] Split Specifier regex into operator and version parts Tokenizer uses _version_regex_str to detect 'VERSION' token. --- packaging/_parser.py | 2 +- packaging/specifiers.py | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/packaging/_parser.py b/packaging/_parser.py index 8f614711b..8a41fe32f 100644 --- a/packaging/_parser.py +++ b/packaging/_parser.py @@ -20,7 +20,7 @@ def __init__(self, value: str) -> None: self.value = value def __str__(self) -> str: - return str(self.value) + return self.value def __repr__(self) -> str: return f"<{self.__class__.__name__}('{self}')>" diff --git a/packaging/specifiers.py b/packaging/specifiers.py index dab49eef9..2aa6dd488 100644 --- a/packaging/specifiers.py +++ b/packaging/specifiers.py @@ -80,8 +80,10 @@ def filter( class Specifier(BaseSpecifier): - _regex_str = r""" + _operator_regex_str = r""" (?P(~=|==|!=|<=|>=|<|>|===)) + """ + _version_regex_str = r""" (?P (?: # The identity operators allow for an escape hatch that will @@ -173,7 +175,10 @@ class Specifier(BaseSpecifier): ) """ - _regex = re.compile(r"^\s*" + _regex_str + r"\s*$", re.VERBOSE | re.IGNORECASE) + _regex = re.compile( + r"^\s*" + _operator_regex_str + _version_regex_str + r"\s*$", + re.VERBOSE | re.IGNORECASE, + ) _operators = { "~=": "compatible",