Commit f681002 1 parent c3c519a commit f681002 Copy full SHA for f681002
File tree 2 files changed +13
-6
lines changed
2 files changed +13
-6
lines changed Original file line number Diff line number Diff line change @@ -62,7 +62,7 @@ def test_github_flavoured_markdown(self):
62
62
print("Hello, World")
63
63
</code></pre>""" )
64
64
65
- @unittest .skipIf (html .html5lib_version == "0.95" , "backport" )
65
+ @unittest .skipIf (html .HTML5LIB_VERSION <= html . HTML5LIB_SIMPLETREE , "backport" )
66
66
def test_sanitizer (self ):
67
67
sanitizer = html .Sanitizer (elements = [], attributes = [])
68
68
examples = [
@@ -75,7 +75,7 @@ def test_sanitizer(self):
75
75
for (input , expected ) in examples :
76
76
self .assertEqual (html .sanitize (sanitizer , input ), expected )
77
77
78
- @unittest .skipIf (html .html5lib_version == "0.95" , "backport" )
78
+ @unittest .skipIf (html .HTML5LIB_VERSION <= html . HTML5LIB_SIMPLETREE , "backport" )
79
79
def test_sanitizer_extensions (self ):
80
80
sanitizer = html .Sanitizer (elements = ["img" ], attributes = ["src" ])
81
81
examples = [
Original file line number Diff line number Diff line change 2
2
3
3
from __future__ import unicode_literals
4
4
5
- import pkg_resources
6
5
import operator
6
+ import pkg_resources
7
+
8
+ from distutils .version import LooseVersion as Version
9
+
10
+ HTML5LIB_VERSION = Version (pkg_resources .get_distribution ("html5lib" ).version )
11
+ HTML5LIB_SIMPLETREE = Version ("0.9.5" )
7
12
8
13
from isso .compat import reduce
9
14
10
15
import html5lib
11
- html5lib_version = pkg_resources .get_distribution ("html5lib" ).version
12
-
13
16
from html5lib .sanitizer import HTMLSanitizer
14
17
from html5lib .serializer import HTMLSerializer
15
18
@@ -45,7 +48,11 @@ def sanitize(tokenizer, document):
45
48
parser = html5lib .HTMLParser (tokenizer = tokenizer )
46
49
domtree = parser .parseFragment (document )
47
50
48
- builder = "simpletree" if html5lib_version == "0.95" else "etree"
51
+ if HTML5LIB_VERSION > HTML5LIB_SIMPLETREE :
52
+ builder = "etree"
53
+ else :
54
+ builder = "simpletree"
55
+
49
56
stream = html5lib .treewalkers .getTreeWalker (builder )(domtree )
50
57
serializer = HTMLSerializer (quote_attr_values = True , omit_optional_tags = False )
51
58
You can’t perform that action at this time.
0 commit comments