fix(TextHandler): correcting case_sensitive argument logic
This is awkward, I can't believe how this slipped from me!
This commit is contained in:
@@ -134,7 +134,7 @@ class TextHandler(str):
|
|||||||
check_match: Literal[True],
|
check_match: Literal[True],
|
||||||
replace_entities: bool = True,
|
replace_entities: bool = True,
|
||||||
clean_match: bool = False,
|
clean_match: bool = False,
|
||||||
case_sensitive: bool = False,
|
case_sensitive: bool = True,
|
||||||
) -> bool:
|
) -> bool:
|
||||||
...
|
...
|
||||||
|
|
||||||
@@ -144,26 +144,26 @@ class TextHandler(str):
|
|||||||
regex: Union[str, Pattern[str]],
|
regex: Union[str, Pattern[str]],
|
||||||
replace_entities: bool = True,
|
replace_entities: bool = True,
|
||||||
clean_match: bool = False,
|
clean_match: bool = False,
|
||||||
case_sensitive: bool = False,
|
case_sensitive: bool = True,
|
||||||
check_match: Literal[False] = False,
|
check_match: Literal[False] = False,
|
||||||
) -> "TextHandlers[TextHandler]":
|
) -> "TextHandlers[TextHandler]":
|
||||||
...
|
...
|
||||||
|
|
||||||
def re(
|
def re(
|
||||||
self, regex: Union[str, Pattern[str]], replace_entities: bool = True, clean_match: bool = False,
|
self, regex: Union[str, Pattern[str]], replace_entities: bool = True, clean_match: bool = False,
|
||||||
case_sensitive: bool = False, check_match: bool = False
|
case_sensitive: bool = True, check_match: bool = False
|
||||||
) -> Union["TextHandlers[TextHandler]", bool]:
|
) -> Union["TextHandlers[TextHandler]", bool]:
|
||||||
"""Apply the given regex to the current text and return a list of strings with the matches.
|
"""Apply the given regex to the current text and return a list of strings with the matches.
|
||||||
|
|
||||||
:param regex: Can be either a compiled regular expression or a string.
|
:param regex: Can be either a compiled regular expression or a string.
|
||||||
:param replace_entities: if enabled character entity references are replaced by their corresponding character
|
:param replace_entities: if enabled character entity references are replaced by their corresponding character
|
||||||
:param clean_match: if enabled, this will ignore all whitespaces and consecutive spaces while matching
|
:param clean_match: if enabled, this will ignore all whitespaces and consecutive spaces while matching
|
||||||
:param case_sensitive: if enabled, function will set the regex to ignore letters case while compiling it
|
:param case_sensitive: if disabled, function will set the regex to ignore letters case while compiling it
|
||||||
:param check_match: used to quickly check if this regex matches or not without any operations on the results
|
:param check_match: used to quickly check if this regex matches or not without any operations on the results
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if isinstance(regex, str):
|
if isinstance(regex, str):
|
||||||
if not case_sensitive:
|
if case_sensitive:
|
||||||
regex = re.compile(regex, re.UNICODE)
|
regex = re.compile(regex, re.UNICODE)
|
||||||
else:
|
else:
|
||||||
regex = re.compile(regex, flags=re.UNICODE | re.IGNORECASE)
|
regex = re.compile(regex, flags=re.UNICODE | re.IGNORECASE)
|
||||||
@@ -182,14 +182,14 @@ class TextHandler(str):
|
|||||||
return TextHandlers(typing.cast(List[_TextHandlerType], [TextHandler(_replace_entities(s)) for s in results]))
|
return TextHandlers(typing.cast(List[_TextHandlerType], [TextHandler(_replace_entities(s)) for s in results]))
|
||||||
|
|
||||||
def re_first(self, regex: Union[str, Pattern[str]], default=None, replace_entities: bool = True,
|
def re_first(self, regex: Union[str, Pattern[str]], default=None, replace_entities: bool = True,
|
||||||
clean_match: bool = False, case_sensitive: bool = False) -> "TextHandler":
|
clean_match: bool = False, case_sensitive: bool = True) -> "TextHandler":
|
||||||
"""Apply the given regex to text and return the first match if found, otherwise return the default value.
|
"""Apply the given regex to text and return the first match if found, otherwise return the default value.
|
||||||
|
|
||||||
:param regex: Can be either a compiled regular expression or a string.
|
:param regex: Can be either a compiled regular expression or a string.
|
||||||
:param default: The default value to be returned if there is no match
|
:param default: The default value to be returned if there is no match
|
||||||
:param replace_entities: if enabled character entity references are replaced by their corresponding character
|
:param replace_entities: if enabled character entity references are replaced by their corresponding character
|
||||||
:param clean_match: if enabled, this will ignore all whitespaces and consecutive spaces while matching
|
:param clean_match: if enabled, this will ignore all whitespaces and consecutive spaces while matching
|
||||||
:param case_sensitive: if enabled, function will set the regex to ignore letters case while compiling it
|
:param case_sensitive: if disabled, function will set the regex to ignore letters case while compiling it
|
||||||
|
|
||||||
"""
|
"""
|
||||||
result = self.re(regex, replace_entities, clean_match=clean_match, case_sensitive=case_sensitive)
|
result = self.re(regex, replace_entities, clean_match=clean_match, case_sensitive=case_sensitive)
|
||||||
@@ -218,14 +218,14 @@ class TextHandlers(List[TextHandler]):
|
|||||||
return typing.cast(_TextHandlerType, TextHandler(lst))
|
return typing.cast(_TextHandlerType, TextHandler(lst))
|
||||||
|
|
||||||
def re(self, regex: Union[str, Pattern[str]], replace_entities: bool = True, clean_match: bool = False,
|
def re(self, regex: Union[str, Pattern[str]], replace_entities: bool = True, clean_match: bool = False,
|
||||||
case_sensitive: bool = False) -> 'TextHandlers[TextHandler]':
|
case_sensitive: bool = True) -> 'TextHandlers[TextHandler]':
|
||||||
"""Call the ``.re()`` method for each element in this list and return
|
"""Call the ``.re()`` method for each element in this list and return
|
||||||
their results flattened as TextHandlers.
|
their results flattened as TextHandlers.
|
||||||
|
|
||||||
:param regex: Can be either a compiled regular expression or a string.
|
:param regex: Can be either a compiled regular expression or a string.
|
||||||
:param replace_entities: if enabled character entity references are replaced by their corresponding character
|
:param replace_entities: if enabled character entity references are replaced by their corresponding character
|
||||||
:param clean_match: if enabled, this will ignore all whitespaces and consecutive spaces while matching
|
:param clean_match: if enabled, this will ignore all whitespaces and consecutive spaces while matching
|
||||||
:param case_sensitive: if enabled, function will set the regex to ignore letters case while compiling it
|
:param case_sensitive: if disabled, function will set the regex to ignore letters case while compiling it
|
||||||
"""
|
"""
|
||||||
results = [
|
results = [
|
||||||
n.re(regex, replace_entities, clean_match, case_sensitive) for n in self
|
n.re(regex, replace_entities, clean_match, case_sensitive) for n in self
|
||||||
@@ -233,7 +233,7 @@ class TextHandlers(List[TextHandler]):
|
|||||||
return TextHandlers(flatten(results))
|
return TextHandlers(flatten(results))
|
||||||
|
|
||||||
def re_first(self, regex: Union[str, Pattern[str]], default=None, replace_entities: bool = True,
|
def re_first(self, regex: Union[str, Pattern[str]], default=None, replace_entities: bool = True,
|
||||||
clean_match: bool = False, case_sensitive: bool = False) -> TextHandler:
|
clean_match: bool = False, case_sensitive: bool = True) -> TextHandler:
|
||||||
"""Call the ``.re_first()`` method for each element in this list and return
|
"""Call the ``.re_first()`` method for each element in this list and return
|
||||||
the first result or the default value otherwise.
|
the first result or the default value otherwise.
|
||||||
|
|
||||||
@@ -241,7 +241,7 @@ class TextHandlers(List[TextHandler]):
|
|||||||
:param default: The default value to be returned if there is no match
|
:param default: The default value to be returned if there is no match
|
||||||
:param replace_entities: if enabled character entity references are replaced by their corresponding character
|
:param replace_entities: if enabled character entity references are replaced by their corresponding character
|
||||||
:param clean_match: if enabled, this will ignore all whitespaces and consecutive spaces while matching
|
:param clean_match: if enabled, this will ignore all whitespaces and consecutive spaces while matching
|
||||||
:param case_sensitive: if enabled, function will set the regex to ignore letters case while compiling it
|
:param case_sensitive: if disabled, function will set the regex to ignore letters case while compiling it
|
||||||
"""
|
"""
|
||||||
for n in self:
|
for n in self:
|
||||||
for result in n.re(regex, replace_entities, clean_match, case_sensitive):
|
for result in n.re(regex, replace_entities, clean_match, case_sensitive):
|
||||||
|
|||||||
+8
-8
@@ -763,25 +763,25 @@ class Adaptor(SelectorsGeneration):
|
|||||||
return self.get_all_text(strip=True).json()
|
return self.get_all_text(strip=True).json()
|
||||||
|
|
||||||
def re(self, regex: Union[str, Pattern[str]], replace_entities: bool = True,
|
def re(self, regex: Union[str, Pattern[str]], replace_entities: bool = True,
|
||||||
clean_match: bool = False, case_sensitive: bool = False) -> TextHandlers:
|
clean_match: bool = False, case_sensitive: bool = True) -> TextHandlers:
|
||||||
"""Apply the given regex to the current text and return a list of strings with the matches.
|
"""Apply the given regex to the current text and return a list of strings with the matches.
|
||||||
|
|
||||||
:param regex: Can be either a compiled regular expression or a string.
|
:param regex: Can be either a compiled regular expression or a string.
|
||||||
:param replace_entities: if enabled character entity references are replaced by their corresponding character
|
:param replace_entities: if enabled character entity references are replaced by their corresponding character
|
||||||
:param clean_match: if enabled, this will ignore all whitespaces and consecutive spaces while matching
|
:param clean_match: if enabled, this will ignore all whitespaces and consecutive spaces while matching
|
||||||
:param case_sensitive: if enabled, function will set the regex to ignore letters case while compiling it
|
:param case_sensitive: if disabled, function will set the regex to ignore letters case while compiling it
|
||||||
"""
|
"""
|
||||||
return self.text.re(regex, replace_entities, clean_match, case_sensitive)
|
return self.text.re(regex, replace_entities, clean_match, case_sensitive)
|
||||||
|
|
||||||
def re_first(self, regex: Union[str, Pattern[str]], default=None, replace_entities: bool = True,
|
def re_first(self, regex: Union[str, Pattern[str]], default=None, replace_entities: bool = True,
|
||||||
clean_match: bool = False, case_sensitive: bool = False) -> TextHandler:
|
clean_match: bool = False, case_sensitive: bool = True) -> TextHandler:
|
||||||
"""Apply the given regex to text and return the first match if found, otherwise return the default value.
|
"""Apply the given regex to text and return the first match if found, otherwise return the default value.
|
||||||
|
|
||||||
:param regex: Can be either a compiled regular expression or a string.
|
:param regex: Can be either a compiled regular expression or a string.
|
||||||
:param default: The default value to be returned if there is no match
|
:param default: The default value to be returned if there is no match
|
||||||
:param replace_entities: if enabled character entity references are replaced by their corresponding character
|
:param replace_entities: if enabled character entity references are replaced by their corresponding character
|
||||||
:param clean_match: if enabled, this will ignore all whitespaces and consecutive spaces while matching
|
:param clean_match: if enabled, this will ignore all whitespaces and consecutive spaces while matching
|
||||||
:param case_sensitive: if enabled, function will set the regex to ignore letters case while compiling it
|
:param case_sensitive: if disabled, function will set the regex to ignore letters case while compiling it
|
||||||
"""
|
"""
|
||||||
return self.text.re_first(regex, default, replace_entities, clean_match, case_sensitive)
|
return self.text.re_first(regex, default, replace_entities, clean_match, case_sensitive)
|
||||||
|
|
||||||
@@ -1009,14 +1009,14 @@ class Adaptors(List[Adaptor]):
|
|||||||
return self.__class__(flatten(results))
|
return self.__class__(flatten(results))
|
||||||
|
|
||||||
def re(self, regex: Union[str, Pattern[str]], replace_entities: bool = True,
|
def re(self, regex: Union[str, Pattern[str]], replace_entities: bool = True,
|
||||||
clean_match: bool = False, case_sensitive: bool = False) -> TextHandlers[TextHandler]:
|
clean_match: bool = False, case_sensitive: bool = True) -> TextHandlers[TextHandler]:
|
||||||
"""Call the ``.re()`` method for each element in this list and return
|
"""Call the ``.re()`` method for each element in this list and return
|
||||||
their results flattened as List of TextHandler.
|
their results flattened as List of TextHandler.
|
||||||
|
|
||||||
:param regex: Can be either a compiled regular expression or a string.
|
:param regex: Can be either a compiled regular expression or a string.
|
||||||
:param replace_entities: if enabled character entity references are replaced by their corresponding character
|
:param replace_entities: if enabled character entity references are replaced by their corresponding character
|
||||||
:param clean_match: if enabled, this will ignore all whitespaces and consecutive spaces while matching
|
:param clean_match: if enabled, this will ignore all whitespaces and consecutive spaces while matching
|
||||||
:param case_sensitive: if enabled, function will set the regex to ignore letters case while compiling it
|
:param case_sensitive: if disabled, function will set the regex to ignore letters case while compiling it
|
||||||
"""
|
"""
|
||||||
results = [
|
results = [
|
||||||
n.text.re(regex, replace_entities, clean_match, case_sensitive) for n in self
|
n.text.re(regex, replace_entities, clean_match, case_sensitive) for n in self
|
||||||
@@ -1024,7 +1024,7 @@ class Adaptors(List[Adaptor]):
|
|||||||
return TextHandlers(flatten(results))
|
return TextHandlers(flatten(results))
|
||||||
|
|
||||||
def re_first(self, regex: Union[str, Pattern[str]], default=None, replace_entities: bool = True,
|
def re_first(self, regex: Union[str, Pattern[str]], default=None, replace_entities: bool = True,
|
||||||
clean_match: bool = False, case_sensitive: bool = False) -> TextHandler:
|
clean_match: bool = False, case_sensitive: bool = True) -> TextHandler:
|
||||||
"""Call the ``.re_first()`` method for each element in this list and return
|
"""Call the ``.re_first()`` method for each element in this list and return
|
||||||
the first result or the default value otherwise.
|
the first result or the default value otherwise.
|
||||||
|
|
||||||
@@ -1032,7 +1032,7 @@ class Adaptors(List[Adaptor]):
|
|||||||
:param default: The default value to be returned if there is no match
|
:param default: The default value to be returned if there is no match
|
||||||
:param replace_entities: if enabled character entity references are replaced by their corresponding character
|
:param replace_entities: if enabled character entity references are replaced by their corresponding character
|
||||||
:param clean_match: if enabled, this will ignore all whitespaces and consecutive spaces while matching
|
:param clean_match: if enabled, this will ignore all whitespaces and consecutive spaces while matching
|
||||||
:param case_sensitive: if enabled, function will set the regex to ignore letters case while compiling it
|
:param case_sensitive: if disabled, function will set the regex to ignore letters case while compiling it
|
||||||
"""
|
"""
|
||||||
for n in self:
|
for n in self:
|
||||||
for result in n.re(regex, replace_entities, clean_match, case_sensitive):
|
for result in n.re(regex, replace_entities, clean_match, case_sensitive):
|
||||||
|
|||||||
Reference in New Issue
Block a user