linkcheck.strformat

Various string utility functions. Note that these functions are not necessarily optimised for large strings, so use with care.

Functions

ascii_safe(s)

Get ASCII string without raising encoding errors.

format_feature_warning(**kwargs)

Format warning that a module could not be imported and that it should be installed for a certain URL.

get_paragraphs(text)

A new paragraph is considered to start at a line which follows one or more blank lines (lines containing nothing or just spaces).

indent(text[, indent_string])

Indent each line of text with the given indent string.

limit(s[, length])

If the length of the string exceeds the given limit, it will be cut off and three dots will be appended.

paginate(text)

Print text in pages of lines.

strduration_long(duration[, do_translate])

Turn a time value in seconds into x hours, x minutes, etc.

strip_control_chars(text)

Remove console control characters from text.

stripurl(s)

Remove any lines from string after the first line.

strline(s)

Display string representation on one line.

strsize(b[, grouping])

Return human representation of bytes b.

strtime(t[, func])

Return ISO 8601 formatted time.

strtimezone()

Return timezone info, %z on some platforms, but not supported on all.

unquote(s[, matching])

Remove leading and ending single and double quotes.

wrap(text, width, **kwargs)

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.paginate(text)[source]

Print text in pages of lines.

linkcheck.strformat.strduration_long(duration, do_translate=True)[source]

Turn a time value in seconds into x hours, x minutes, etc.

linkcheck.strformat.strip_control_chars(text)[source]

Remove console control characters from text.

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.strline(s)[source]

Display string representation on one line.

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

linkcheck.strformat.wrap(text, width, **kwargs)[source]

Adjust lines of text to be not longer than width. The text will be returned unmodified if width <= 0. See textwrap.wrap() for a list of supported kwargs. Returns text with lines no longer than given width.