Skip to content

Commit a8b40b2

Browse files
committed
(Almost) comply with PEP 8.
The two violations: - We don't in general comply with the 79 character per line limit. - constants.py violates (at least according to pep8) the hanging indent rule. On the whole, I disagree with the tool and have filed <PyCQA/pycodestyle#189> with regards to this.
1 parent 7a06a5a commit a8b40b2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1530
-1317
lines changed

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ install:
3131

3232
script:
3333
- nosetests
34-
- if [[ $FLAKE == "true" ]]; then flake8 --exclude=E,W html5lib; fi
34+
- if [[ $FLAKE == "true" ]]; then find html5lib/ -name '*.py' -and -not -name 'constants.py' -print0 | xargs -0 flake8 --ignore=E501; fi
35+
- if [[ $FLAKE == "true" ]]; then flake8 --max-line-length=99 --ignore=E126 html5lib/constants.py; fi
3536

3637
after_script:
3738
- python debug-info.py

html5lib/constants.py

Lines changed: 234 additions & 231 deletions
Large diffs are not rendered by default.

html5lib/filters/inject_meta_charset.py

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from . import _base
44

5+
56
class Filter(_base.Filter):
67
def __init__(self, source, encoding):
78
_base.Filter.__init__(self, source)
@@ -20,21 +21,21 @@ def __iter__(self):
2021

2122
elif type == "EmptyTag":
2223
if token["name"].lower() == "meta":
23-
# replace charset with actual encoding
24-
has_http_equiv_content_type = False
25-
for (namespace,name),value in token["data"].items():
26-
if namespace != None:
27-
continue
28-
elif name.lower() == 'charset':
29-
token["data"][(namespace,name)] = self.encoding
30-
meta_found = True
31-
break
32-
elif name == 'http-equiv' and value.lower() == 'content-type':
33-
has_http_equiv_content_type = True
34-
else:
35-
if has_http_equiv_content_type and (None, "content") in token["data"]:
36-
token["data"][(None, "content")] = 'text/html; charset=%s' % self.encoding
37-
meta_found = True
24+
# replace charset with actual encoding
25+
has_http_equiv_content_type = False
26+
for (namespace, name), value in token["data"].items():
27+
if namespace is not None:
28+
continue
29+
elif name.lower() == 'charset':
30+
token["data"][(namespace, name)] = self.encoding
31+
meta_found = True
32+
break
33+
elif name == 'http-equiv' and value.lower() == 'content-type':
34+
has_http_equiv_content_type = True
35+
else:
36+
if has_http_equiv_content_type and (None, "content") in token["data"]:
37+
token["data"][(None, "content")] = 'text/html; charset=%s' % self.encoding
38+
meta_found = True
3839

3940
elif token["name"].lower() == "head" and not meta_found:
4041
# insert meta into empty head

html5lib/filters/lint.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@
99
from html5lib.constants import spaceCharacters
1010
spaceCharacters = "".join(spaceCharacters)
1111

12-
class LintError(Exception): pass
12+
13+
class LintError(Exception):
14+
pass
15+
1316

1417
class Filter(_base.Filter):
1518
def __iter__(self):

html5lib/filters/optionaltags.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from . import _base
44

5+
56
class Filter(_base.Filter):
67
def slider(self):
78
previous1 = previous2 = None
@@ -17,7 +18,7 @@ def __iter__(self):
1718
type = token["type"]
1819
if type == "StartTag":
1920
if (token["data"] or
20-
not self.is_optional_start(token["name"], previous, next)):
21+
not self.is_optional_start(token["name"], previous, next)):
2122
yield token
2223
elif type == "EndTag":
2324
if not self.is_optional_end(token["name"], next):
@@ -75,7 +76,7 @@ def is_optional_start(self, tagname, previous, next):
7576
# omit the thead and tfoot elements' end tag when they are
7677
# immediately followed by a tbody element. See is_optional_end.
7778
if previous and previous['type'] == 'EndTag' and \
78-
previous['name'] in ('tbody','thead','tfoot'):
79+
previous['name'] in ('tbody', 'thead', 'tfoot'):
7980
return False
8081
return next["name"] == 'tr'
8182
else:

html5lib/filters/sanitizer.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
from . import _base
44
from html5lib.sanitizer import HTMLSanitizerMixin
55

6+
67
class Filter(_base.Filter, HTMLSanitizerMixin):
78
def __iter__(self):
89
for token in _base.Filter.__iter__(self):
910
token = self.sanitize_token(token)
10-
if token: yield token
11+
if token:
12+
yield token

html5lib/filters/whitespace.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
SPACES_REGEX = re.compile("[%s]+" % spaceCharacters)
1010

11+
1112
class Filter(_base.Filter):
1213

1314
spacePreserveElements = frozenset(["pre", "textarea"] + list(rcdataElements))
@@ -17,7 +18,7 @@ def __iter__(self):
1718
for token in _base.Filter.__iter__(self):
1819
type = token["type"]
1920
if type == "StartTag" \
20-
and (preserve or token["name"] in self.spacePreserveElements):
21+
and (preserve or token["name"] in self.spacePreserveElements):
2122
preserve += 1
2223

2324
elif type == "EndTag" and preserve:
@@ -32,6 +33,6 @@ def __iter__(self):
3233

3334
yield token
3435

36+
3537
def collapse_spaces(text):
3638
return SPACES_REGEX.sub(' ', text)
37-

0 commit comments

Comments
 (0)