~ubuntu-branches/ubuntu/saucy/lxml/saucy-updates

« back to all changes in this revision

Viewing changes to src/lxml/html/diff.py

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2013-02-19 21:47:31 UTC
  • mfrom: (2.1.35 experimental)
  • Revision ID: package-import@ubuntu.com-20130219214731-jbkip7ycyvzlth3m
Tags: 3.1.0-1
New upstream version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
import difflib
2
2
from lxml import etree
3
3
from lxml.html import fragment_fromstring
4
 
import cgi
5
4
import re
6
5
 
7
6
__all__ = ['html_annotate', 'htmldiff']
8
7
 
9
8
try:
 
9
    from html import escape as html_escape
 
10
except ImportError:
 
11
    from cgi import escape as html_escape
 
12
try:
10
13
    _unicode = unicode
11
14
except NameError:
12
15
    # Python 3
23
26
 
24
27
def default_markup(text, version):
25
28
    return '<span title="%s">%s</span>' % (
26
 
        cgi.escape(_unicode(version), 1), text)
 
29
        html_escape(_unicode(version), 1), text)
27
30
 
28
31
def html_annotate(doclist, markup=default_markup):
29
32
    """
686
689
        return
687
690
    start_words = split_words(el.text)
688
691
    for word in start_words:
689
 
        yield cgi.escape(word)
 
692
        yield html_escape(word)
690
693
    for child in el:
691
694
        for item in flatten_el(child, include_hrefs=include_hrefs):
692
695
            yield item
696
699
        yield end_tag(el)
697
700
        end_words = split_words(el.tail)
698
701
        for word in end_words:
699
 
            yield cgi.escape(word)
 
702
            yield html_escape(word)
700
703
 
701
704
def split_words(text):
702
705
    """ Splits some text into words. Includes trailing whitespace (one
715
718
    The text representation of the start tag for a tag.
716
719
    """
717
720
    return '<%s%s>' % (
718
 
        el.tag, ''.join([' %s="%s"' % (name, cgi.escape(value, True))
 
721
        el.tag, ''.join([' %s="%s"' % (name, html_escape(value, True))
719
722
                         for name, value in el.attrib.items()]))
720
723
 
721
724
def end_tag(el):