Package genshi :: Module core :: Class Markup

Class Markup

object --+        
         |        
basestring --+    
             |    
       unicode --+
                 |
                Markup

Marks a string as being safe for inclusion in HTML/XML output without needing to be escaped.
Instance Methods
 
__add__(self, other)
x+y
 
__mod__(self, args)
x%y
 
__mul__(self, num)
n*x
 
__radd__(self, other)
 
__repr__(self)
repr(x)
 
__rmul__(self, num)
n*x
Markup
join(self, seq, escape_quotes=True)
Return a Markup object which is the concatenation of the strings in the given sequence, where this Markup object is the separator between the joined elements.
Markup
stripentities(self, keepxmlentities=False)
Return a copy of the text with any character or numeric entities replaced by the equivalent UTF-8 characters.
Markup
striptags(self)
Return a copy of the text with all XML/HTML tags removed.
unicode
unescape(self)
Reverse-escapes &, <, >, and " and returns a unicode object.

Inherited from unicode: __contains__, __eq__, __format__, __ge__, __getattribute__, __getitem__, __getnewargs__, __getslice__, __gt__, __hash__, __le__, __len__, __lt__, __ne__, __new__, __rmod__, __sizeof__, __str__, capitalize, center, count, decode, encode, endswith, expandtabs, find, format, index, isalnum, isalpha, isdecimal, isdigit, islower, isnumeric, isspace, istitle, isupper, ljust, lower, lstrip, partition, replace, rfind, rindex, rjust, rpartition, rsplit, rstrip, split, splitlines, startswith, strip, swapcase, title, translate, upper, zfill

Inherited from object: __delattr__, __init__, __reduce__, __reduce_ex__, __setattr__, __subclasshook__

Class Methods
Markup
escape(cls, text, quotes=True)
Create a Markup instance from a string and escape special characters it may contain (<, >, & and ").
Properties

Inherited from object: __class__

Method Details

__add__(self, other)
(Addition operator)

 
x+y
Overrides: unicode.__add__
(inherited documentation)

__mod__(self, args)

 
x%y
Overrides: unicode.__mod__
(inherited documentation)

__mul__(self, num)

 
n*x
Overrides: unicode.__mul__
(inherited documentation)

__repr__(self)
(Representation operator)

 
repr(x)
Overrides: object.__repr__
(inherited documentation)

__rmul__(self, num)

 
n*x
Overrides: unicode.__rmul__
(inherited documentation)

escape(cls, text, quotes=True)
Class Method

 

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

join(self, seq, escape_quotes=True)

 

Return a Markup object which is the concatenation of the strings in the given sequence, where this Markup object is the separator between the joined elements.

Any element in the sequence that is not a Markup instance is automatically escaped.

Parameters:
  • seq - the sequence of strings to join
  • escape_quotes - whether double quote characters in the elements should be escaped
Returns: Markup
the joined Markup object
Overrides: unicode.join

See Also: escape

stripentities(self, keepxmlentities=False)

 

Return a copy of the text with any character or numeric entities replaced by the equivalent UTF-8 characters.

If the keepxmlentities parameter is provided and evaluates to True, the core XML entities (&amp;, &apos;, &gt;, &lt; and &quot;) are not stripped.

Returns: Markup
a Markup instance with entities removed

striptags(self)

 
Return a copy of the text with all XML/HTML tags removed.
Returns: Markup
a Markup instance with all tags removed

unescape(self)

 

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

>>> Markup('1 &lt; 2').unescape()
u'1 < 2'
Returns: unicode
the unescaped string