Package tdi :: Package tools :: Module escape
[frames] | no frames]

Module escape

source code

This module is deprecated.

This module is deprecated and going to be removed. All code has been moved elsewhere.


Copyright: Copyright 2006 - 2013 André Malo or his licensors, as applicable

License:

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Author: André Malo

Functions
unicode
decode_html(value, encoding='latin-1', errors='strict', entities=None)
Decode HTML encoded text
source code
str
escape_js(toescape, inlined=True, encoding=None)
Escape a string for JS output (to be inserted into a JS string)
source code
str
multiline_to_html(content, encoding='ascii', tabwidth=8, xhtml=True)
Encode multiline content to HTML, assignable to node.raw.content
source code
Variables
  __package__ = None
hash(x)
Function Details

decode_html(value, encoding='latin-1', errors='strict', entities=None)

source code 
Decode HTML encoded text
Parameters:
  • value (basestring) - HTML content to decode
  • encoding (str) - Unicode encoding to be applied before value is being processed further. If value is already a unicode instance, the encoding is ignored. If omitted, 'latin-1' is applied (because it can't fail and maps bytes 1:1 to unicode codepoints).
  • errors (str) - Error handling, passed to .decode() and evaluated for entities. If the entity name or character codepoint could not be found or not be parsed then the error handler has the following semantics:

    strict (or anything different from the other tokens below)
    A ValueError is raised.
    ignore
    The original entity is passed through
    replace
    The character is replaced by the replacement character (U+FFFD)
  • entities (dict) - Entity name mapping (unicode(name) -> unicode(value)). If omitted or None, the HTML5 entity list is applied.

Returns: unicode
The decoded content

escape_js(toescape, inlined=True, encoding=None)

source code 

Escape a string for JS output (to be inserted into a JS string)

This function is one of the building blocks of the tdi.tools.javascript.replace function. You probably shouldn't use it directly in your rendering code.

Parameters:
  • toescape (basestring) - The string to escape
  • inlined (bool) - Do additional escapings (possibly needed for inlining the script within a HTML page)?
  • encoding (str) - Encoding in case that toescape is a str. If omitted or None, no encoding is applied and toescape is expected to be ASCII compatible.
Returns: str
The escaped string (ascii)

multiline_to_html(content, encoding='ascii', tabwidth=8, xhtml=True)

source code 
Encode multiline content to HTML, assignable to node.raw.content
Parameters:
  • content (unicode) - Content to encode
  • encoding (str) - Target encoding
  • tabwidth (int) - Tab width? Used to expand tabs. If None, tabs are not expanded.
  • xhtml (bool) - XHTML? Only used to determine if <br> or <br /> is emitted.
Returns: str
The multilined content

Variables Details

__package__

hash(x)

Value:
None