Package genshi :: Module core

Module core

Core classes for markup processing.
Classes
  Stream
Represents a stream of markup events.
  Attrs
Immutable sequence type that stores the attributes of an element.
  Markup
Marks a string as being safe for inclusion in HTML/XML output without needing to be escaped.
  Namespace
Utility class creating and testing elements with a namespace.
  QName
A qualified element or attribute name.
Functions
Markup
escape(text, quotes=True)
Create a Markup instance from a string and escape special characters it may contain (<, >, & and ").
unicode
unescape(text)
Reverse-escapes &, <, >, and " and returns a unicode object.
Function Details

escape(text, quotes=True)

 

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

unescape(text)

 

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

>>> unescape(Markup('1 &lt; 2'))
u'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