Skip to content
This repository has been archived by the owner on Jun 25, 2020. It is now read-only.

Commit

Permalink
Merge pull request #4 from sk-/python35
Browse files Browse the repository at this point in the history
Added support for python 3.5
  • Loading branch information
sk- committed Dec 12, 2015
2 parents 4fc1fab + e2497c2 commit 0ee6510
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ python:
- "2.7"
- "3.3"
- "3.4"
- "3.5"
- "pypy"
- "pypy3"
# command to install dependencies
Expand Down
17 changes: 14 additions & 3 deletions html_linter.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Copyright 2014 Deezer (http://www.deezer.com)
# Copyright 2015 Sebastian Kreft
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -30,6 +31,11 @@
import HTMLParser
except ImportError:
import html.parser as HTMLParser

# Python 2 and Pypy HTMLParser modules do not have attrfind_tolerant
if not hasattr(HTMLParser, 'attrfind_tolerant'):
HTMLParser.attrfind_tolerant = HTMLParser.attrfind

import re
import sys

Expand Down Expand Up @@ -461,7 +467,7 @@ def get_attribute_line_column(tag_definition, line, column, attribute):
Return:
A (line, column) tuple representing the position of the attribute.
"""
for match in HTMLParser.attrfind.finditer(tag_definition):
for match in HTMLParser.attrfind_tolerant.finditer(tag_definition):
if match.group(1).lower() == attribute:
return get_line_column(tag_definition, line, column, match.start(1))

Expand All @@ -480,7 +486,7 @@ def get_value_line_column(tag_definition, line, column, attribute):
Return:
A (line, column) tuple representing the position of the value.
"""
for match in HTMLParser.attrfind.finditer(tag_definition):
for match in HTMLParser.attrfind_tolerant.finditer(tag_definition):
if match.group(1).lower() == attribute:
if not match.group(3):
pos = match.end(1)
Expand Down Expand Up @@ -526,6 +532,10 @@ def __init__(self, html):
if hasattr(self, 'strict'):
self.strict = False

# Python 3.5 sets convert_charrefs to True by default
if hasattr(self, 'convert_charrefs'):
self.convert_charrefs = False

self.feed(html)
self.close()

Expand Down Expand Up @@ -797,7 +807,8 @@ def _check_starttag_capitalization(self, tag):

def _check_attributes_case_quotation_entities(self, tag, unused_attrs):
original_def = self.get_starttag_text()
for match in HTMLParser.attrfind.finditer(original_def, len(tag) + 1):
for match in HTMLParser.attrfind_tolerant.finditer(original_def,
len(tag) + 1):
# We do not use islower() due to http://bugs.python.org/issue13822.
if match.group(1) != match.group(1).lower():
line, column = self.get_attribute_line_column(
Expand Down
3 changes: 2 additions & 1 deletion scripts/html_lint.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python
# Copyright 2014 Deezer (http://www.deezer.com)
# Copyright 2015 Sebastian Kreft
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -80,7 +81,7 @@
}


__VERSION__ = '0.1.8'
__VERSION__ = '0.2.0'


def main():
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

setup(
name='html-linter',
version='0.1.9',
version='0.2.0',
description='Lints an HTML5 file using Google\'s style guide',
long_description=open('README.rst').read(),
author='Sebastian Kreft',
Expand All @@ -39,6 +39,7 @@
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: Implementation :: PyPy',
'Topic :: Software Development',
],
Expand Down

0 comments on commit 0ee6510

Please sign in to comment.