translate.misc.quote

Package translate :: Package misc :: Module quote |
[hide private]
[frames] | no frames]

# Module quote

source code

String processing utilities for extracting strings with various kinds of delimiters

Functions | [hide private]
find_all(searchin, substr) Returns a list of locations where substr occurs in searchin locations are not allowed to overlap | source code
extract(source, startdelim, enddelim, escape=None, startinstring=False, allowreentry=True) Extracts a doublequote-delimited string from a string, allowing for backslash-escaping returns tuple of (quoted string with quotes, still in string at end). | source code
extractwithoutquotes(source, startdelim, enddelim, escape=None, startinstring=False, includeescapes=True, allowreentry=True) Extracts a doublequote-delimited string from a string, allowing for backslash-escaping includeescapes can also be a function that takes the whole escaped string and returns the replaced version. | source code
escapequotes(source, escapeescapes=0) Returns the same string, with double quotes escaped with backslash | source code
escapesinglequotes(source) Returns the same string, with single quotes doubled | source code
htmlentityencode(source) encodes source using HTML entities e.g. | source code
htmlentitydecode(source) decodes source using HTML entities e.g. | source code
javapropertiesencode(source) Encodes source in the escaped-unicode encoding used by Java .properties files | source code
mozillapropertiesencode(source) Encodes source in the escaped-unicode encoding used by Mozilla .properties files. | source code
escapecontrols(source) escape control characters in the given string | source code
propertiesdecode(source) Decodes source from the escaped-unicode encoding used by .properties files. | source code
quotestr(source, escapeescapes=0) Returns a doublequote-delimited quoted string, escaping double quotes with backslash. | source code
singlequotestr(source) Returns a doublequote-delimited quoted string, escaping single quotes with themselves. | source code
findend(string, substring) | source code
rstripeol(string) | source code
stripcomment(comment, startstring=`'``<!--``'`, endstring=`'``-->``'`) | source code
unstripcomment(comment, startstring=`'``<!--` `'`, endstring=`'``-->\n``'`) | source code

Variables | [hide private]
| propertyescapes = ``{``'``"``'``:` `'``"``'``,` `'``\'``'``:` `'``\'``'``,` `'``\\``'``:` `'``\\``'``,` `'``f``'``:` `'``\x0``...``
| controlchars = ``{``'``\t``'``:` `'``\\t``'``,` `'``\n``'``:` `'``\\n``'``,` `'``\x0c``'``:` `'``\\f``'``,` `'``\r``'``:``...``

Imports: logging, htmlentitydefs, accepts, returns

Function Details | [hide private]

### htmlentityencode(source) | source code
encodes source using HTML entities e.g. © -> &copy; Decorators: `@accepts(unicode)` `@returns(unicode)`

### htmlentitydecode(source) | source code
decodes source using HTML entities e.g. &copy; -> © Decorators: `@accepts(unicode)` `@returns(unicode)`

### javapropertiesencode(source) | source code
Encodes source in the escaped-unicode encoding used by Java .properties files Decorators: `@accepts(unicode)` `@returns(unicode)`

### mozillapropertiesencode(source) | source code
Encodes source in the escaped-unicode encoding used by Mozilla .properties files. Decorators: `@accepts(unicode)` `@returns(unicode)`

### propertiesdecode(source) | source code
Decodes source from the escaped-unicode encoding used by .properties files. Java uses Latin1 by default, and Mozilla uses UTF-8 by default. Since the .decode("unicode-escape") routine decodes everything, and we don't want to we reimplemented the algorithm from Python Objects/unicode.c in Python and modify it to retain escaped control characters. Decorators: `@accepts(unicode)` `@returns(unicode)`

Variables Details | [hide private]

  ### propertyescapes Value:
      {'"': '"',
       '\'': '\'',
       '\\': '\\',
       'f': '\x0c',
       'n': '''
      ''',
       'r': '\r',
       't': '\t'}

  ### controlchars Value:
      {'\t': '\\t', '\n': '\\n', '\x0c': '\\f', '\r': '\\r', '\\': '\\\\'}