Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4834f64

Browse files
committed
Remove the "XHTML" Serializer.
This never did what it claimed, and never actually guaranteed itsoutput was well-formed XML, and hence provided little of use.(The only thing it was good at was producing stylized HTML, and thiscan be done by manually setting the relevant options without havinga misleadingly named module.)If you want XHTML, use one of the tree-builders that supports itnatively. These are DOM (with most DOM implementations, inc. thestandard library minidom with its Node.toxml function) andElementTree (ElementTree.tostring gives XML). Neither simpletree northe deprecated BeautifulSoup tree-builders support this.If you want polyglot, there is no solution. I (personally) would behappy to add a polyglot serializer to html5lib if one is written.
1 parent3e50aad commit4834f64

File tree

3 files changed

+8
-41
lines changed

3 files changed

+8
-41
lines changed

‎html5lib/serializer/__init__.py‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
from __future__importabsolute_import,division,unicode_literals
22

3-
43
fromhtml5libimporttreewalkers
54

65
from .htmlserializerimportHTMLSerializer
7-
from .xhtmlserializerimportXHTMLSerializer
6+
87

98
defserialize(input,tree="simpletree",format="html",encoding=None,
109
**serializer_opts):
1110
# XXX: Should we cache this?
1211
walker=treewalkers.getTreeWalker(tree)
1312
ifformat=="html":
1413
s=HTMLSerializer(**serializer_opts)
15-
elifformat=="xhtml":
16-
s=XHTMLSerializer(**serializer_opts)
1714
else:
18-
raiseValueError("type must beeitherhtml or xhtml")
15+
raiseValueError("type must be html")
1916
returns.render(walker(input),encoding)

‎html5lib/serializer/xhtmlserializer.py‎

Lines changed: 0 additions & 11 deletions
This file was deleted.

‎html5lib/tests/test_serializer.py‎

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -86,35 +86,19 @@ def serialize_html(input, options):
8686
options=dict([(str(k),v)fork,vinoptions.items()])
8787
returnserializer.HTMLSerializer(**options).render(JsonWalker(input),options.get("encoding",None))
8888

89-
defserialize_xhtml(input,options):
90-
options=dict([(str(k),v)fork,vinoptions.items()])
91-
returnserializer.XHTMLSerializer(**options).render(JsonWalker(input),options.get("encoding",None))
92-
93-
defrunSerializerTest(input,expected,xhtml,options):
89+
defrunSerializerTest(input,expected,options):
9490
encoding=options.get("encoding",None)
9591

9692
ifencoding:
9793
encode=lambdax:x.encode(encoding)
9894
expected=list(map(encode,expected))
99-
ifxhtml:
100-
xhtml=list(map(encode,xhtml))
101-
10295

10396
result=serialize_html(input,options)
10497
iflen(expected)==1:
105-
assertexpected[0]==result,"Expected:\n%s\nActual:\n%s\nOptions\nxhtml:False\n%s"%(expected[0],result,str(options))
98+
assertexpected[0]==result,"Expected:\n%s\nActual:\n%s\nOptions:\n%s"%(expected[0],result,str(options))
10699
elifresultnotinexpected:
107100
assertFalse,"Expected: %s, Received: %s"% (expected,result)
108101

109-
ifnotxhtml:
110-
return
111-
112-
result=serialize_xhtml(input,options)
113-
iflen(xhtml)==1:
114-
assertxhtml[0]==result,"Expected:\n%s\nActual:\n%s\nOptions\nxhtml:True\n%s"%(xhtml[0],result,str(options))
115-
elifresultnotinxhtml:
116-
assertFalse,"Expected: %s, Received: %s"% (xhtml,result)
117-
118102

119103
classEncodingTestCase(unittest.TestCase):
120104
defthrowsWithLatin1(self,input):
@@ -131,11 +115,11 @@ def testDoctypeSystemId(self):
131115

132116
deftestCdataCharacters(self):
133117
runSerializerTest([["StartTag","http://www.w3.org/1999/xhtml","style", {}], ["Characters","\u0101"]],
134-
["<style>&amacr;"],None,{"encoding":"iso-8859-1"})
118+
["<style>&amacr;"], {"encoding":"iso-8859-1"})
135119

136120
deftestCharacters(self):
137121
runSerializerTest([["Characters","\u0101"]],
138-
["&amacr;"],None,{"encoding":"iso-8859-1"})
122+
["&amacr;"], {"encoding":"iso-8859-1"})
139123

140124
deftestStartTagName(self):
141125
self.throwsWithLatin1([["StartTag","http://www.w3.org/1999/xhtml","\u0101", []]])
@@ -149,7 +133,7 @@ def testAttributeName(self):
149133
deftestAttributeValue(self):
150134
runSerializerTest([["StartTag","http://www.w3.org/1999/xhtml","span",
151135
[{"namespace":None,"name":"potato","value":"\u0101"}]]],
152-
["<span potato=&amacr;>"],None,{"encoding":"iso-8859-1"})
136+
["<span potato=&amacr;>"], {"encoding":"iso-8859-1"})
153137

154138
deftestEndTagName(self):
155139
self.throwsWithLatin1([["EndTag","http://www.w3.org/1999/xhtml","\u0101"]])
@@ -190,7 +174,4 @@ def test_serializer():
190174
tests=json.load(fp)
191175
test_name=os.path.basename(filename).replace('.test','')
192176
forindex,testinenumerate(tests['tests']):
193-
xhtml=test.get("xhtml",test["expected"])
194-
iftest_name=='optionaltags':
195-
xhtml=None
196-
yieldrunSerializerTest,test["input"],test["expected"],xhtml,test.get("options", {})
177+
yieldrunSerializerTest,test["input"],test["expected"],test.get("options", {})

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp