Skip to content

Get Flake8 looking clean #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 12 commits into from
15 changes: 15 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,18 @@ env:
- USE_OPTIONAL=true
- USE_OPTIONAL=false

matrix:
exclude:
- python: "2.7"
env: USE_OPTIONAL=false
- python: "3.3"
env: USE_OPTIONAL=false
include:
- python: "2.7"
env: USE_OPTIONAL=false FLAKE=true
- python: "3.3"
env: USE_OPTIONAL=false FLAKE=true

before_install:
- git submodule update --init --recursive

Expand All @@ -19,9 +31,12 @@ install:
- if [[ $TRAVIS_PYTHON_VERSION != 3.* && $USE_OPTIONAL == "true" ]]; then pip install -r requirements-optional-2.txt --use-mirrors; fi
- if [[ $TRAVIS_PYTHON_VERSION == 3.* && $USE_OPTIONAL == "true" ]]; then pip install -r requirements-optional-3.txt --use-mirrors; fi
- if [[ $TRAVIS_PYTHON_VERSION != "pypy" && $USE_OPTIONAL == "true" ]]; then pip install -r requirements-optional-cpython.txt --use-mirrors; fi
- if [[ $FLAKE == "true" ]]; then pip install --use-mirrors flake8; fi

script:
- nosetests
- if [[ $FLAKE == "true" ]]; then find html5lib/ -name '*.py' -and -not -name 'constants.py' -print0 | xargs -0 flake8 --ignore=E501; fi
- if [[ $FLAKE == "true" ]]; then flake8 --max-line-length=99 --ignore=E126 html5lib/constants.py; fi

after_script:
- python debug-info.py
2 changes: 2 additions & 0 deletions html5lib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@
from .treewalkers import getTreeWalker
from .serializer import serialize

__all__ = ["HTMLParser", "parse", "parseFragment", "getTreeBuilder",
"getTreeWalker", "serialize"]
__version__ = "1.0b1"
465 changes: 234 additions & 231 deletions html5lib/constants.py

Large diffs are not rendered by default.

31 changes: 16 additions & 15 deletions html5lib/filters/inject_meta_charset.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from . import _base


class Filter(_base.Filter):
def __init__(self, source, encoding):
_base.Filter.__init__(self, source)
Expand All @@ -20,21 +21,21 @@ def __iter__(self):

elif type == "EmptyTag":
if token["name"].lower() == "meta":
# replace charset with actual encoding
has_http_equiv_content_type = False
for (namespace,name),value in token["data"].items():
if namespace != None:
continue
elif name.lower() == 'charset':
token["data"][(namespace,name)] = self.encoding
meta_found = True
break
elif name == 'http-equiv' and value.lower() == 'content-type':
has_http_equiv_content_type = True
else:
if has_http_equiv_content_type and (None, "content") in token["data"]:
token["data"][(None, "content")] = 'text/html; charset=%s' % self.encoding
meta_found = True
# replace charset with actual encoding
has_http_equiv_content_type = False
for (namespace, name), value in token["data"].items():
if namespace is not None:
continue
elif name.lower() == 'charset':
token["data"][(namespace, name)] = self.encoding
meta_found = True
break
elif name == 'http-equiv' and value.lower() == 'content-type':
has_http_equiv_content_type = True
else:
if has_http_equiv_content_type and (None, "content") in token["data"]:
token["data"][(None, "content")] = 'text/html; charset=%s' % self.encoding
meta_found = True

elif token["name"].lower() == "head" and not meta_found:
# insert meta into empty head
Expand Down
5 changes: 4 additions & 1 deletion html5lib/filters/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
from html5lib.constants import spaceCharacters
spaceCharacters = "".join(spaceCharacters)

class LintError(Exception): pass

class LintError(Exception):
pass


class Filter(_base.Filter):
def __iter__(self):
Expand Down
5 changes: 3 additions & 2 deletions html5lib/filters/optionaltags.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from . import _base


class Filter(_base.Filter):
def slider(self):
previous1 = previous2 = None
Expand All @@ -17,7 +18,7 @@ def __iter__(self):
type = token["type"]
if type == "StartTag":
if (token["data"] or
not self.is_optional_start(token["name"], previous, next)):
not self.is_optional_start(token["name"], previous, next)):
yield token
elif type == "EndTag":
if not self.is_optional_end(token["name"], next):
Expand Down Expand Up @@ -75,7 +76,7 @@ def is_optional_start(self, tagname, previous, next):
# omit the thead and tfoot elements' end tag when they are
# immediately followed by a tbody element. See is_optional_end.
if previous and previous['type'] == 'EndTag' and \
previous['name'] in ('tbody','thead','tfoot'):
previous['name'] in ('tbody', 'thead', 'tfoot'):
return False
return next["name"] == 'tr'
else:
Expand Down
4 changes: 3 additions & 1 deletion html5lib/filters/sanitizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
from . import _base
from html5lib.sanitizer import HTMLSanitizerMixin


class Filter(_base.Filter, HTMLSanitizerMixin):
def __iter__(self):
for token in _base.Filter.__iter__(self):
token = self.sanitize_token(token)
if token: yield token
if token:
yield token
5 changes: 3 additions & 2 deletions html5lib/filters/whitespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

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


class Filter(_base.Filter):

spacePreserveElements = frozenset(["pre", "textarea"] + list(rcdataElements))
Expand All @@ -17,7 +18,7 @@ def __iter__(self):
for token in _base.Filter.__iter__(self):
type = token["type"]
if type == "StartTag" \
and (preserve or token["name"] in self.spacePreserveElements):
and (preserve or token["name"] in self.spacePreserveElements):
preserve += 1

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

yield token


def collapse_spaces(text):
return SPACES_REGEX.sub(' ', text)

Loading