linkcheck.strformat
Various string utility functions. Note that these functions are not necessarily optimised for large strings, so use with care.
Functions
|
Get ASCII string without raising encoding errors. |
|
Format warning that a module could not be imported and that it should be installed for a certain URL. |
|
A new paragraph is considered to start at a line which follows one or more blank lines (lines containing nothing or just spaces). |
|
Indent each line of text with the given indent string. |
|
If the length of the string exceeds the given limit, it will be cut off and three dots will be appended. |
|
Print text in pages of lines. |
|
Turn a time value in seconds into x hours, x minutes, etc. |
|
Remove console control characters from text. |
|
Remove any lines from string after the first line. |
|
Display string representation on one line. |
|
Return human representation of bytes b. |
|
Return ISO 8601 formatted time. |
Return timezone info, %z on some platforms, but not supported on all. |
|
|
Remove leading and ending single and double quotes. |
|
Adjust lines of text to be not longer than width. |
- linkcheck.strformat.ascii_safe(s)[source]
Get ASCII string without raising encoding errors. Unknown characters of the given encoding will be ignored.
- Parameters:
s (string or None) – the string to be encoded
- Returns:
version of s containing only ASCII characters, or None if s was None
- Return type:
string or None
- linkcheck.strformat.format_feature_warning(**kwargs)[source]
Format warning that a module could not be imported and that it should be installed for a certain URL.
- linkcheck.strformat.get_paragraphs(text)[source]
A new paragraph is considered to start at a line which follows one or more blank lines (lines containing nothing or just spaces). The first line of the text also starts a paragraph.
- linkcheck.strformat.indent(text, indent_string=' ')[source]
Indent each line of text with the given indent string.
- linkcheck.strformat.limit(s, length=72)[source]
If the length of the string exceeds the given limit, it will be cut off and three dots will be appended.
- Parameters:
s (string) – the string to limit
length (non-negative integer) – maximum length
- Returns:
limited string, at most length+3 characters long
- linkcheck.strformat.strduration_long(duration, do_translate=True)[source]
Turn a time value in seconds into x hours, x minutes, etc.
- linkcheck.strformat.stripurl(s)[source]
Remove any lines from string after the first line. Also remove whitespace at start and end from given string.
- linkcheck.strformat.strsize(b, grouping=True)[source]
Return human representation of bytes b. A negative number of bytes raises a value error.
- linkcheck.strformat.strtime(t, func=<built-in function localtime>)[source]
Return ISO 8601 formatted time.
- linkcheck.strformat.strtimezone()[source]
Return timezone info, %z on some platforms, but not supported on all.
- linkcheck.strformat.unquote(s, matching=False)[source]
Remove leading and ending single and double quotes. The quotes need to match if matching is True. Only one quote from each end will be stripped.
- Returns:
if s evaluates to False, return s as is, else return string with stripped quotes
- Return type:
unquoted string, or s unchanged if it is evaluating to False