string¶
String utilities.
- deltona.string.add_unidecode_custom_replacement(find: str, replace: str) None¶
Add a custom replacement to the Unidecode cache.
-
deltona.string.cssq(selector: str, file: TextIO | str, limit: int =
0, *, debug_selector: bool =False, strip: bool =True, text: False =False) Iterator[Tag]¶ -
deltona.string.cssq(selector: str, file: TextIO | str, limit: int =
0, *, debug_selector: bool =False, strip: bool =True, text: True =True) Iterator[str] -
deltona.string.cssq(selector: str, file: TextIO | str, limit: int =
0, *, debug_selector: bool =False, strip: bool =True, text: bool =False) Iterator[str] | Iterator[Tag] Filter HTML with CSS.
If passing
limit=1, consider usingcssq_one()instead.- Parameters:¶
- selector : str¶
CSS selector.
- file : TextIO | str¶
File-like object or string containing HTML.
- limit : int¶
Limit number of results.
0means no limit.- debug_selector : bool¶
Enable SoupSieve debug logging.
- strip : bool¶
Strip whitespace from text content.
- text : bool¶
Output content within the HTML tags only.
- Yields:¶
Iterator[Tag] | Iterator[str] – The filtered items.
-
deltona.string.cssq_one(selector: str, file: TextIO | str, *, debug_selector: bool =
False, strip: bool =True, text: False =False) Tag | None¶ -
deltona.string.cssq_one(selector: str, file: TextIO | str, *, debug_selector: bool =
False, strip: bool =True, text: True =True) str | None -
deltona.string.cssq_one(selector: str, file: TextIO | str, *, debug_selector: bool =
False, strip: bool =True, text: bool =False) str | Tag | None Select a single item from HTML with CSS.
- deltona.string.fix_apostrophes(word: str) str¶
Title-case a word while preserving apostrophe contractions.
- deltona.string.fullwidth_to_narrow(s: str) str¶
Convert fullwidth characters in
sto narrow or halfwidth.Unlike Unidecode this will convert
'¥'to its halfwidth form'¥'.
- deltona.string.hexstr2bytes(s: str) bytes¶
Convert a hex string such as
"01020a"to its bytes form (0x1 0x2 0x10)).
- deltona.string.hexstr2bytes_generator(s: str) Iterator[int]¶
Convert a hex string such as
"01020a"to integers.
- deltona.string.is_ascii(s: collections.abc.Sequence[str]) bool¶
Check if a string consists of only ASCII characters.
- deltona.string.is_url(filename: str | PathLike[str]) bool¶
Detect if
filenameis a URL.This is the same method mpv uses to decide this.
- deltona.string.rev_sentences(sentences: collections.abc.Sequence[str]) Iterator[str]¶
Reverse the word order of each sentence.
-
deltona.string.sanitize(s: str, *, restricted: bool =
True) str¶ Transform a string to a ‘sanitised’ form.
- deltona.string.strip_ansi(o: str) str¶
Remove ANSI escape sequences from
o.As defined by ECMA-048 in http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-048.
Taken from https://github.com/ewen-lbh/python-strip-ansi/ due to installation issues with Poetry.
- deltona.string.strip_ansi_if_no_colors(s: str) str¶
Strip ANSI colour-codes if the
NO_COLORenvironment variable is set.