Package trac :: Package util :: Module html

Module html

source code

Classes
  TracHTMLSanitizer
Sanitize HTML constructions which are potentially vector of phishing or XSS attacks, in user-supplied HTML.
  Deuglifier
Help base class used for cleaning up HTML riddled with <FONT COLOR=...> tags and replace them with appropriate <span class="...">.
  FormTokenInjector
Identify and protect forms from CSRF attacks.
Functions
unicode
unescape(text)
Reverse-escapes &, <, >, and " and returns a unicode object.
Markup
escape(text, quotes=True)
Create a Markup instance from a string and escape special characters it may contain (<, >, & and ").
source code
 
plaintext(text, keeplinebreaks=True)
Extract the text elements from (X)HTML content
source code
 
find_element(frag, attr=None, cls=None, tag=None)
Return the first element in the fragment having the given attribute, class or tag, using a preorder depth-first search.
source code
 
is_safe_origin(safe_origins, uri, req=None)
Whether the given uri is a safe cross-origin.
source code
 
to_fragment(input)
Convert input to a Fragment object.
source code
Variables
  tag = <genshi.builder.ElementFactory object at 0x7f4932e45810>
  html = <trac.util.html.TransposingElementFactory object at 0x7...
Function Details

unescape(text)

 

Reverse-escapes &, <, >, and " and returns a unicode object.

>>> unescape(Markup('1 &lt; 2'))
'1 < 2'

If the provided text object is not a Markup instance, it is returned unchanged.

>>> unescape('1 &lt; 2')
'1 &lt; 2'
Parameters:
  • text - the text to unescape
Returns: unicode
the unescsaped string

escape(text, quotes=True)

source code 

Create a Markup instance from a string and escape special characters it may contain (<, >, & and ").

>>> escape('"1 < 2"')
<Markup u'&#34;1 &lt; 2&#34;'>

If the quotes parameter is set to False, the " character is left as is. Escaping quotes is generally only required for strings that are to be used in attribute values.

>>> escape('"1 < 2"', quotes=False)
<Markup u'"1 &lt; 2"'>
Parameters:
  • text - the text to escape
  • quotes - if True, double quote characters are escaped in addition to the other special characters
Returns: Markup
the escaped Markup string

plaintext(text, keeplinebreaks=True)

source code 
Extract the text elements from (X)HTML content
Parameters:
  • text - unicode or genshi.builder.Fragment
  • keeplinebreaks - optionally keep linebreaks

Variables Details

html

Value:
<trac.util.html.TransposingElementFactory object at 0x7f4932d84250>