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
 
__radd__(self, other)
 
__mod__(self, args)
x%y
 
__mul__(self, num)
x*n
 
__rmul__(self, num)
n*x
 
__repr__(self)
repr(x)
 
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.
 
unescape(self)
Reverse-escapes &, <, >, and " and returns a unicode object.
 
stripentities(self, keepxmlentities=False)
Return a copy of the text with any character or numeric entities replaced by the equivalent UTF-8 characters.
 
striptags(self)
Return a copy of the text with all XML/HTML tags removed.

Inherited from unicode: __cmp__, __contains__, __getattribute__, __getitem__, __getnewargs__, __getslice__, __hash__, __len__, __rmod__, __str__, capitalize, center, count, decode, encode, endswith, expandtabs, find, index, isalnum, isalpha, isdecimal, isdigit, islower, isnumeric, isspace, istitle, isupper, ljust, lower, lstrip, replace, rfind, rindex, rjust, rsplit, rstrip, split, splitlines, startswith, strip, swapcase, title, translate, upper, zfill

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

Class Methods
 
escape(cls, text, quotes=True)
Create a Markup instance from a string and escape special characters it may contain (<, >, & and ").
Static Methods
 
__new__(cls, text='', *args)
Returns: a new object with type S, a subtype of T
Properties

Inherited from object: __class__

Method Details

__new__(cls, text='', *args)
Static Method

 
Returns:
a new object with type S, a subtype of T

Overrides: unicode.__new__
(inherited documentation)

__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)

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

__rmul__(self, num)

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

__repr__(self)
(Representation operator)

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

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:
the joined Markup object
Overrides: unicode.join

See Also: escape

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:
the escaped Markup string

See Also: genshi.core.escape

unescape(self)

 

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

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

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.

striptags(self)

 
Return a copy of the text with all XML/HTML tags removed.