Skip to content

Commit 44b0bbc

Browse files
committed
Merge pull request #223 from gsnedders/pep8_1.7_fixes
pep8 1.7 fixes
2 parents 46dae3d + 5e90af8 commit 44b0bbc

File tree

11 files changed

+89
-168
lines changed

11 files changed

+89
-168
lines changed

html5lib/html5parser.py

+73-74
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,8 @@ def mainLoop(self):
204204
elif type == DoctypeToken:
205205
new_token = phase.processDoctype(new_token)
206206

207-
if (type == StartTagToken and token["selfClosing"]
208-
and not token["selfClosingAcknowledged"]):
207+
if (type == StartTagToken and token["selfClosing"] and
208+
not token["selfClosingAcknowledged"]):
209209
self.parseError("non-void-element-with-trailing-solidus",
210210
{"name": token["name"]})
211211

@@ -517,77 +517,76 @@ def processDoctype(self, token):
517517
if publicId != "":
518518
publicId = publicId.translate(asciiUpper2Lower)
519519

520-
if (not correct or token["name"] != "html"
521-
or publicId.startswith(
522-
("+//silmaril//dtd html pro v0r11 19970101//",
523-
"-//advasoft ltd//dtd html 3.0 aswedit + extensions//",
524-
"-//as//dtd html 3.0 aswedit + extensions//",
525-
"-//ietf//dtd html 2.0 level 1//",
526-
"-//ietf//dtd html 2.0 level 2//",
527-
"-//ietf//dtd html 2.0 strict level 1//",
528-
"-//ietf//dtd html 2.0 strict level 2//",
529-
"-//ietf//dtd html 2.0 strict//",
530-
"-//ietf//dtd html 2.0//",
531-
"-//ietf//dtd html 2.1e//",
532-
"-//ietf//dtd html 3.0//",
533-
"-//ietf//dtd html 3.2 final//",
534-
"-//ietf//dtd html 3.2//",
535-
"-//ietf//dtd html 3//",
536-
"-//ietf//dtd html level 0//",
537-
"-//ietf//dtd html level 1//",
538-
"-//ietf//dtd html level 2//",
539-
"-//ietf//dtd html level 3//",
540-
"-//ietf//dtd html strict level 0//",
541-
"-//ietf//dtd html strict level 1//",
542-
"-//ietf//dtd html strict level 2//",
543-
"-//ietf//dtd html strict level 3//",
544-
"-//ietf//dtd html strict//",
545-
"-//ietf//dtd html//",
546-
"-//metrius//dtd metrius presentational//",
547-
"-//microsoft//dtd internet explorer 2.0 html strict//",
548-
"-//microsoft//dtd internet explorer 2.0 html//",
549-
"-//microsoft//dtd internet explorer 2.0 tables//",
550-
"-//microsoft//dtd internet explorer 3.0 html strict//",
551-
"-//microsoft//dtd internet explorer 3.0 html//",
552-
"-//microsoft//dtd internet explorer 3.0 tables//",
553-
"-//netscape comm. corp.//dtd html//",
554-
"-//netscape comm. corp.//dtd strict html//",
555-
"-//o'reilly and associates//dtd html 2.0//",
556-
"-//o'reilly and associates//dtd html extended 1.0//",
557-
"-//o'reilly and associates//dtd html extended relaxed 1.0//",
558-
"-//softquad software//dtd hotmetal pro 6.0::19990601::extensions to html 4.0//",
559-
"-//softquad//dtd hotmetal pro 4.0::19971010::extensions to html 4.0//",
560-
"-//spyglass//dtd html 2.0 extended//",
561-
"-//sq//dtd html 2.0 hotmetal + extensions//",
562-
"-//sun microsystems corp.//dtd hotjava html//",
563-
"-//sun microsystems corp.//dtd hotjava strict html//",
564-
"-//w3c//dtd html 3 1995-03-24//",
565-
"-//w3c//dtd html 3.2 draft//",
566-
"-//w3c//dtd html 3.2 final//",
567-
"-//w3c//dtd html 3.2//",
568-
"-//w3c//dtd html 3.2s draft//",
569-
"-//w3c//dtd html 4.0 frameset//",
570-
"-//w3c//dtd html 4.0 transitional//",
571-
"-//w3c//dtd html experimental 19960712//",
572-
"-//w3c//dtd html experimental 970421//",
573-
"-//w3c//dtd w3 html//",
574-
"-//w3o//dtd w3 html 3.0//",
575-
"-//webtechs//dtd mozilla html 2.0//",
576-
"-//webtechs//dtd mozilla html//"))
577-
or publicId in
578-
("-//w3o//dtd w3 html strict 3.0//en//",
579-
"-/w3c/dtd html 4.0 transitional/en",
580-
"html")
581-
or publicId.startswith(
582-
("-//w3c//dtd html 4.01 frameset//",
583-
"-//w3c//dtd html 4.01 transitional//")) and
584-
systemId is None
585-
or systemId and systemId.lower() == "http://www.ibm.com/data/dtd/v11/ibmxhtml1-transitional.dtd"):
520+
if (not correct or token["name"] != "html" or
521+
publicId.startswith(
522+
("+//silmaril//dtd html pro v0r11 19970101//",
523+
"-//advasoft ltd//dtd html 3.0 aswedit + extensions//",
524+
"-//as//dtd html 3.0 aswedit + extensions//",
525+
"-//ietf//dtd html 2.0 level 1//",
526+
"-//ietf//dtd html 2.0 level 2//",
527+
"-//ietf//dtd html 2.0 strict level 1//",
528+
"-//ietf//dtd html 2.0 strict level 2//",
529+
"-//ietf//dtd html 2.0 strict//",
530+
"-//ietf//dtd html 2.0//",
531+
"-//ietf//dtd html 2.1e//",
532+
"-//ietf//dtd html 3.0//",
533+
"-//ietf//dtd html 3.2 final//",
534+
"-//ietf//dtd html 3.2//",
535+
"-//ietf//dtd html 3//",
536+
"-//ietf//dtd html level 0//",
537+
"-//ietf//dtd html level 1//",
538+
"-//ietf//dtd html level 2//",
539+
"-//ietf//dtd html level 3//",
540+
"-//ietf//dtd html strict level 0//",
541+
"-//ietf//dtd html strict level 1//",
542+
"-//ietf//dtd html strict level 2//",
543+
"-//ietf//dtd html strict level 3//",
544+
"-//ietf//dtd html strict//",
545+
"-//ietf//dtd html//",
546+
"-//metrius//dtd metrius presentational//",
547+
"-//microsoft//dtd internet explorer 2.0 html strict//",
548+
"-//microsoft//dtd internet explorer 2.0 html//",
549+
"-//microsoft//dtd internet explorer 2.0 tables//",
550+
"-//microsoft//dtd internet explorer 3.0 html strict//",
551+
"-//microsoft//dtd internet explorer 3.0 html//",
552+
"-//microsoft//dtd internet explorer 3.0 tables//",
553+
"-//netscape comm. corp.//dtd html//",
554+
"-//netscape comm. corp.//dtd strict html//",
555+
"-//o'reilly and associates//dtd html 2.0//",
556+
"-//o'reilly and associates//dtd html extended 1.0//",
557+
"-//o'reilly and associates//dtd html extended relaxed 1.0//",
558+
"-//softquad software//dtd hotmetal pro 6.0::19990601::extensions to html 4.0//",
559+
"-//softquad//dtd hotmetal pro 4.0::19971010::extensions to html 4.0//",
560+
"-//spyglass//dtd html 2.0 extended//",
561+
"-//sq//dtd html 2.0 hotmetal + extensions//",
562+
"-//sun microsystems corp.//dtd hotjava html//",
563+
"-//sun microsystems corp.//dtd hotjava strict html//",
564+
"-//w3c//dtd html 3 1995-03-24//",
565+
"-//w3c//dtd html 3.2 draft//",
566+
"-//w3c//dtd html 3.2 final//",
567+
"-//w3c//dtd html 3.2//",
568+
"-//w3c//dtd html 3.2s draft//",
569+
"-//w3c//dtd html 4.0 frameset//",
570+
"-//w3c//dtd html 4.0 transitional//",
571+
"-//w3c//dtd html experimental 19960712//",
572+
"-//w3c//dtd html experimental 970421//",
573+
"-//w3c//dtd w3 html//",
574+
"-//w3o//dtd w3 html 3.0//",
575+
"-//webtechs//dtd mozilla html 2.0//",
576+
"-//webtechs//dtd mozilla html//")) or
577+
publicId in ("-//w3o//dtd w3 html strict 3.0//en//",
578+
"-/w3c/dtd html 4.0 transitional/en",
579+
"html") or
580+
publicId.startswith(
581+
("-//w3c//dtd html 4.01 frameset//",
582+
"-//w3c//dtd html 4.01 transitional//")) and
583+
systemId is None or
584+
systemId and systemId.lower() == "http://www.ibm.com/data/dtd/v11/ibmxhtml1-transitional.dtd"):
586585
self.parser.compatMode = "quirks"
587586
elif (publicId.startswith(
588587
("-//w3c//dtd xhtml 1.0 frameset//",
589-
"-//w3c//dtd xhtml 1.0 transitional//"))
590-
or publicId.startswith(
588+
"-//w3c//dtd xhtml 1.0 transitional//")) or
589+
publicId.startswith(
591590
("-//w3c//dtd html 4.01 frameset//",
592591
"-//w3c//dtd html 4.01 transitional//")) and
593592
systemId is not None):
@@ -988,8 +987,8 @@ def processSpaceCharactersDropNewline(self, token):
988987
data = token["data"]
989988
self.processSpaceCharacters = self.processSpaceCharactersNonPre
990989
if (data.startswith("\n") and
991-
self.tree.openElements[-1].name in ("pre", "listing", "textarea")
992-
and not self.tree.openElements[-1].hasContent()):
990+
self.tree.openElements[-1].name in ("pre", "listing", "textarea") and
991+
not self.tree.openElements[-1].hasContent()):
993992
data = data[1:]
994993
if data:
995994
self.tree.reconstructActiveFormattingElements()
@@ -1016,8 +1015,8 @@ def startTagProcessInHead(self, token):
10161015

10171016
def startTagBody(self, token):
10181017
self.parser.parseError("unexpected-start-tag", {"name": "body"})
1019-
if (len(self.tree.openElements) == 1
1020-
or self.tree.openElements[1].name != "body"):
1018+
if (len(self.tree.openElements) == 1 or
1019+
self.tree.openElements[1].name != "body"):
10211020
assert self.parser.innerHTML
10221021
else:
10231022
self.parser.framesetOK = False

html5lib/serializer/htmlserializer.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,8 @@ def serialize(self, treewalker, encoding=None):
237237

238238
yield self.encodeStrict(k)
239239
if not self.minimize_boolean_attributes or \
240-
(k not in booleanAttributes.get(name, tuple())
241-
and k not in booleanAttributes.get("", tuple())):
240+
(k not in booleanAttributes.get(name, tuple()) and
241+
k not in booleanAttributes.get("", tuple())):
242242
yield self.encodeStrict("=")
243243
if self.quote_attr_values or not v:
244244
quote_attr = True

html5lib/tests/mockParser.py

-41
This file was deleted.

html5lib/tests/performance/concatenation.py

-36
This file was deleted.

html5lib/tests/test_serializer.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,7 @@ def runSerializerTest(input, expected, options):
9191
encoding = options.get("encoding", None)
9292

9393
if encoding:
94-
encode = lambda x: x.encode(encoding)
95-
expected = list(map(encode, expected))
94+
expected = list(map(lambda x: x.encode(encoding), expected))
9695

9796
result = serialize_html(input, options)
9897
if len(expected) == 1:

html5lib/tests/test_tokenizer.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ def tokensMatch(expectedTokens, receivedTokens, ignoreErrorOrder,
9898
"""
9999
checkSelfClosing = False
100100
for token in expectedTokens:
101-
if (token[0] == "StartTag" and len(token) == 4
102-
or token[0] == "EndTag" and len(token) == 3):
101+
if (token[0] == "StartTag" and len(token) == 4 or
102+
token[0] == "EndTag" and len(token) == 3):
103103
checkSelfClosing = True
104104
break
105105

html5lib/treebuilders/_base.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -353,8 +353,8 @@ def getTableMisnestedNodePosition(self):
353353
def generateImpliedEndTags(self, exclude=None):
354354
name = self.openElements[-1].name
355355
# XXX td, th and tr are not actually needed
356-
if (name in frozenset(("dd", "dt", "li", "option", "optgroup", "p", "rp", "rt"))
357-
and name != exclude):
356+
if (name in frozenset(("dd", "dt", "li", "option", "optgroup", "p", "rp", "rt")) and
357+
name != exclude):
358358
self.openElements.pop()
359359
# XXX This is not entirely what the specification says. We should
360360
# investigate it more closely.

html5lib/treebuilders/dom.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ def __init__(self, element):
4747
_base.Node.__init__(self, element.nodeName)
4848
self.element = element
4949

50-
namespace = property(lambda self: hasattr(self.element, "namespaceURI")
51-
and self.element.namespaceURI or None)
50+
namespace = property(lambda self: hasattr(self.element, "namespaceURI") and
51+
self.element.namespaceURI or None)
5252

5353
def appendChild(self, node):
5454
node.parent = self

html5lib/treewalkers/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010

1111
from __future__ import absolute_import, division, unicode_literals
1212

13-
__all__ = ["getTreeWalker", "pprint", "dom", "etree", "genshistream", "lxmletree"]
14-
1513
from .. import constants
1614
from ..utils import default_etree
1715

16+
__all__ = ["getTreeWalker", "pprint", "dom", "etree", "genshistream", "lxmletree"]
17+
1818
treeWalkerCache = {}
1919

2020

html5lib/treewalkers/_base.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
from __future__ import absolute_import, division, unicode_literals
22
from six import text_type, string_types
33

4+
from xml.dom import Node
5+
from ..constants import voidElements, spaceCharacters
6+
47
__all__ = ["DOCUMENT", "DOCTYPE", "TEXT", "ELEMENT", "COMMENT", "ENTITY", "UNKNOWN",
58
"TreeWalker", "NonRecursiveTreeWalker"]
69

7-
from xml.dom import Node
8-
910
DOCUMENT = Node.DOCUMENT_NODE
1011
DOCTYPE = Node.DOCUMENT_TYPE_NODE
1112
TEXT = Node.TEXT_NODE
@@ -14,7 +15,6 @@
1415
ENTITY = Node.ENTITY_NODE
1516
UNKNOWN = "<#UNKNOWN#>"
1617

17-
from ..constants import voidElements, spaceCharacters
1818
spaceCharacters = "".join(spaceCharacters)
1919

2020

html5lib/treewalkers/genshistream.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ def tokens(self, event, next):
3939

4040
if namespace == namespaces["html"] and name in voidElements:
4141
for token in self.emptyTag(namespace, name, converted_attribs,
42-
not next or next[0] != END
43-
or next[1] != tag):
42+
not next or next[0] != END or
43+
next[1] != tag):
4444
yield token
4545
else:
4646
yield self.startTag(namespace, name, converted_attribs)

0 commit comments

Comments
 (0)