Package pology :: Module escape

Module escape

Escaping texts in various contexts.


Author: Chusslove Illich (Часлав Илић) <caslav.ilic@gmx.net>

License: GPLv3

Functions
string
unescape_c(s)
Unescape text for C-style quoted strings.
string
escape_c(s)
Escape text for C-style quoted strings.
string
escape_sh(s)
Escape text for Unix sh-like shell.
list of strings
split_escaped(text, sep)
Like split(), but double-separator is treated as an escape of itself.
Variables
  __package__ = 'pology'
  x = '\\'
  y = '\\'
Function Details

unescape_c(s)

 

Unescape text for C-style quoted strings.

Octal and hex sequences (\0OO, \xHH) are converted into the corresponding ASCII characters if less than 128, or else thrown out (with a warning).

Invalid escape sequences raise exception.

Parameters:
  • s (string) - text to unescape (without wrapping quotes)
Returns: string
unescaped text

See Also: escape_c

escape_c(s)

 

Escape text for C-style quoted strings.

Parameters:
  • s (string) - text to escape
Returns: string
escaped text (without wrapping quotes)

See Also: unescape_c

escape_sh(s)

 

Escape text for Unix sh-like shell.

Escaped text may be used as a fixed argument in command line, i.e. the shell will not interpret any part of it in a special way. It is undefined which of the possible ways to escape are used (single quotes, double quotes, backslashes).

Parameters:
  • s (string) - text to escape
Returns: string
escaped text

split_escaped(text, sep)

 

Like split(), but double-separator is treated as an escape of itself.

Parameters:
  • text (string) - the text to split
  • sep (string) - the separator
Returns: list of strings
parsed elements