# Path: genshi/util.py
# def plaintext(text, keeplinebreaks=True):
#     """Return the text with all entities and tags removed.
#     
#     >>> plaintext('<b>1 &lt; 2</b>')
#     u'1 < 2'
#     
#     The `keeplinebreaks` parameter can be set to ``False`` to replace any line
#     breaks by simple spaces:
#     
#     >>> plaintext('''<b>1
#     ... &lt;
#     ... 2</b>''', keeplinebreaks=False)
#     u'1 < 2'
#     
#     :param text: the text to convert to plain text
#     :param keeplinebreaks: whether line breaks in the text should be kept intact
#     :return: the text with tags and entities removed
#     """
#     text = stripentities(striptags(text))
#     if not keeplinebreaks:
#         text = text.replace('\n', ' ')
#     return text
# 
# def stripentities(text, keepxmlentities=False):
#     """Return a copy of the given text with any character or numeric entities
#     replaced by the equivalent UTF-8 characters.
#     
#     >>> stripentities('1 &lt; 2')
#     u'1 < 2'
#     >>> stripentities('more &hellip;')
#     u'more \u2026'
#     >>> stripentities('&#8230;')
#     u'\u2026'
#     >>> stripentities('&#x2026;')
#     u'\u2026'
#     
#     If the `keepxmlentities` parameter is provided and is a truth value, the
#     core XML entities (&amp;, &apos;, &gt;, &lt; and &quot;) are left intact.
#     
#     >>> stripentities('1 &lt; 2 &hellip;', keepxmlentities=True)
#     u'1 &lt; 2 \u2026'
#     """
#     def _replace_entity(match):
#         if match.group(1): # numeric entity
#             ref = match.group(1)
#             if ref.startswith('x'):
#                 ref = int(ref[1:], 16)
#             else:
#                 ref = int(ref, 10)
#             return unichr(ref)
#         else: # character entity
#             ref = match.group(2)
#             if keepxmlentities and ref in ('amp', 'apos', 'gt', 'lt', 'quot'):
#                 return '&%s;' % ref
#             try:
#                 return unichr(entities.name2codepoint[ref])
#             except KeyError:
#                 if keepxmlentities:
#                     return '&amp;%s;' % ref
#                 else:
#                     return ref
#     return _STRIPENTITIES_RE.sub(_replace_entity, text)
# 
# def striptags(text):
#     """Return a copy of the text with any XML/HTML tags removed.
#     
#     >>> striptags('<span>Foo</span> bar')
#     'Foo bar'
#     >>> striptags('<span class="bar">Foo</span>')
#     'Foo'
#     >>> striptags('Foo<br />')
#     'Foo'
#     
#     HTML/XML comments are stripped, too:
#     
#     >>> striptags('<!-- <blub>hehe</blah> -->test')
#     'test'
#     
#     :param text: the string to remove tags from
#     :return: the text with tags removed
#     """
#     return _STRIPTAGS_RE.sub('', text)
# 
# def stringrepr(string):
#     ascii = string.encode('ascii', 'backslashreplace')
#     quoted = "'" +  ascii.replace("'", "\\'") + "'"
#     if len(ascii) > len(string):
#         return 'u' + quoted
#     return quoted


    from functools import reduce
from itertools import chain
from genshi.util import plaintext, stripentities, striptags, stringrepr
        from genshi.output import encode
        from genshi.path import Path
        from genshi.output import get_serializer
    from genshi._speedups import Markup
import operator

    def unescape(self):
        """Reverse-escapes &, <, >, and \" and returns a `unicode` object.
        
        >>> Markup('1 &lt; 2').unescape()
        u'1 < 2'
        
        :return: the unescaped string
        :rtype: `unicode`
        :see: `genshi.core.unescape`
        """
        if not self:
            return ''
        return unicode(self).replace('&#34;', '"') \
                            .replace('&gt;', '>') \
                            .replace('&lt;', '<') \
                            .replace('&amp;', '&')

    def 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.
        
        :return: a `Markup` instance with entities removed
        :rtype: `Markup`
        :see: `genshi.util.stripentities`
        """

# Path: genshi/util.py
# def plaintext(text, keeplinebreaks=True):
#     """Return the text with all entities and tags removed.
#     
#     >>> plaintext('<b>1 &lt; 2</b>')
#     u'1 < 2'
#     
#     The `keeplinebreaks` parameter can be set to ``False`` to replace any line
#     breaks by simple spaces:
#     
#     >>> plaintext('''<b>1
#     ... &lt;
#     ... 2</b>''', keeplinebreaks=False)
#     u'1 < 2'
#     
#     :param text: the text to convert to plain text
#     :param keeplinebreaks: whether line breaks in the text should be kept intact
#     :return: the text with tags and entities removed
#     """
#     text = stripentities(striptags(text))
#     if not keeplinebreaks:
#         text = text.replace('\n', ' ')
#     return text
# 
# def stripentities(text, keepxmlentities=False):
#     """Return a copy of the given text with any character or numeric entities
#     replaced by the equivalent UTF-8 characters.
#     
#     >>> stripentities('1 &lt; 2')
#     u'1 < 2'
#     >>> stripentities('more &hellip;')
#     u'more \u2026'
#     >>> stripentities('&#8230;')
#     u'\u2026'
#     >>> stripentities('&#x2026;')
#     u'\u2026'
#     
#     If the `keepxmlentities` parameter is provided and is a truth value, the
#     core XML entities (&amp;, &apos;, &gt;, &lt; and &quot;) are left intact.
#     
#     >>> stripentities('1 &lt; 2 &hellip;', keepxmlentities=True)
#     u'1 &lt; 2 \u2026'
#     """
#     def _replace_entity(match):
#         if match.group(1): # numeric entity
#             ref = match.group(1)
#             if ref.startswith('x'):
#                 ref = int(ref[1:], 16)
#             else:
#                 ref = int(ref, 10)
#             return unichr(ref)
#         else: # character entity
#             ref = match.group(2)
#             if keepxmlentities and ref in ('amp', 'apos', 'gt', 'lt', 'quot'):
#                 return '&%s;' % ref
#             try:
#                 return unichr(entities.name2codepoint[ref])
#             except KeyError:
#                 if keepxmlentities:
#                     return '&amp;%s;' % ref
#                 else:
#                     return ref
#     return _STRIPENTITIES_RE.sub(_replace_entity, text)
# 
# def striptags(text):
#     """Return a copy of the text with any XML/HTML tags removed.
#     
#     >>> striptags('<span>Foo</span> bar')
#     'Foo bar'
#     >>> striptags('<span class="bar">Foo</span>')
#     'Foo'
#     >>> striptags('Foo<br />')
#     'Foo'
#     
#     HTML/XML comments are stripped, too:
#     
#     >>> striptags('<!-- <blub>hehe</blah> -->test')
#     'test'
#     
#     :param text: the string to remove tags from
#     :return: the text with tags removed
#     """
#     return _STRIPTAGS_RE.sub('', text)
# 
# def stringrepr(string):
#     ascii = string.encode('ascii', 'backslashreplace')
#     quoted = "'" +  ascii.replace("'", "\\'") + "'"
#     if len(ascii) > len(string):
#         return 'u' + quoted
#     return quoted


# Path: genshi/core.py
    from functools import reduce
from itertools import chain
from genshi.util import plaintext, stripentities, striptags, stringrepr
        from genshi.output import encode
        from genshi.path import Path
        from genshi.output import get_serializer
    from genshi._speedups import Markup
import operator


    def unescape(self):
        """Reverse-escapes &, <, >, and \" and returns a `unicode` object.
        
        >>> Markup('1 &lt; 2').unescape()
        u'1 < 2'
        
        :return: the unescaped string
        :rtype: `unicode`
        :see: `genshi.core.unescape`
        """
        if not self:
            return ''
        return unicode(self).replace('&#34;', '"') \
                            .replace('&gt;', '>') \
                            .replace('&lt;', '<') \
                            .replace('&amp;', '&')

    def 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.
        
        :return: a `Markup` instance with entities removed
        :rtype: `Markup`
        :see: `genshi.util.stripentities`
        """

        return Markup(stripentities(self, keepxmlentities=keepxmlentities))