module documentation

Undocumented

Function slugify No summary
Variable format​_lazy Undocumented
Variable re​_camel​_case Undocumented
Variable re​_chars Undocumented
Variable re​_newlines Undocumented
Variable re​_tag Undocumented
Variable re​_words Undocumented
Variable smart​_split​_re Undocumented
Class ​Streaming​Buffer Undocumented
Class ​Truncator An object used to truncate text, either by characters or words.
Function ​_format​_lazy Apply str.format() on 'format_string' where format_string, args, and/or kwargs might be lazy.
Function ​_replace​_entity Undocumented
Function camel​_case​_to​_spaces Split CamelCase and convert to lowercase. Strip surrounding whitespace.
Function capfirst Capitalize the first letter of a string.
Function compress​_sequence Undocumented
Function compress​_string Undocumented
Function get​_text​_list No summary
Function get​_valid​_filename No summary
Function normalize​_newlines Normalize CRLF and CR newlines to just LF.
Function phone2numeric Convert a phone number with letters into its numeric equivalent.
Function smart​_split No summary
Function unescape​_string​_literal Convert quoted string literals to unquoted strings with escaped quotes and backslashes unquoted:
Function wrap A word-wrap function that preserves existing line breaks. Expects that existing line breaks are posix newlines.
Variable ​_entity​_re Undocumented
@keep_lazy_text
def slugify(value, allow_unicode=False):
Convert to ASCII if 'allow_unicode' is False. Convert spaces or repeated dashes to single dashes. Remove characters that aren't alphanumerics, underscores, or hyphens. Convert to lowercase. Also strip leading and trailing whitespace, dashes, and underscores.
format_lazy =

Undocumented

re_camel_case =

Undocumented

re_chars =

Undocumented

re_newlines =

Undocumented

re_tag =

Undocumented

re_words =

Undocumented

smart_split_re =

Undocumented

def _format_lazy(format_string, *args, **kwargs):
Apply str.format() on 'format_string' where format_string, args, and/or kwargs might be lazy.
def _replace_entity(match):

Undocumented

def camel_case_to_spaces(value):
Split CamelCase and convert to lowercase. Strip surrounding whitespace.
@keep_lazy_text
def capfirst(x):
Capitalize the first letter of a string.
def compress_sequence(sequence):

Undocumented

def compress_string(s):

Undocumented

@keep_lazy_text
def get_text_list(list_, last_word=gettext_lazy('or')):
>>> get_text_list(['a', 'b', 'c', 'd'])
'a, b, c or d'
>>> get_text_list(['a', 'b', 'c'], 'and')
'a, b and c'
>>> get_text_list(['a', 'b'], 'and')
'a and b'
>>> get_text_list(['a'])
'a'
>>> get_text_list([])
''
@keep_lazy_text
def get_valid_filename(name):
Return the given string converted to a string that can be used for a clean filename. Remove leading and trailing spaces; convert other spaces to underscores; and remove anything that is not an alphanumeric, dash, underscore, or dot. >>> get_valid_filename("john's portrait in 2004.jpg") 'johns_portrait_in_2004.jpg'
@keep_lazy_text
def normalize_newlines(text):
Normalize CRLF and CR newlines to just LF.
@keep_lazy_text
def phone2numeric(phone):
Convert a phone number with letters into its numeric equivalent.
def smart_split(text):

Generator that splits a string by spaces, leaving quoted phrases together. Supports both single and double quotes, and supports escaping quotes with backslashes. In the output, strings will keep their initial and trailing quote marks and escaped quotes will remain escaped (the results can then be further processed with unescape_string_literal()).

>>> list(smart_split(r'This is "a person\'s" test.'))
['This', 'is', '"a person\\\'s"', 'test.']
>>> list(smart_split(r"Another 'person\'s' test."))
['Another', "'person\\'s'", 'test.']
>>> list(smart_split(r'A "\"funky\" style" test.'))
['A', '"\\"funky\\" style"', 'test.']
@keep_lazy_text
def unescape_string_literal(s):

Convert quoted string literals to unquoted strings with escaped quotes and backslashes unquoted:

>>> unescape_string_literal('"abc"')
'abc'
>>> unescape_string_literal("'abc'")
'abc'
>>> unescape_string_literal('"a \"bc\""')
'a "bc"'
>>> unescape_string_literal("'\'ab\' c'")
"'ab' c"
@keep_lazy_text
def wrap(text, width):

A word-wrap function that preserves existing line breaks. Expects that existing line breaks are posix newlines.

Preserve all white space except added line breaks consume the space on which they break the line.

Don't wrap long words, thus the output text may have lines longer than width.

_entity_re =

Undocumented