Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add python 3.2 support. fix reading from input file

  • Loading branch information...
commit 6a9c593a15b0954b10e814139bbe74389bd45225 1 parent 31986ff
@mankyd authored
View
1  .travis.yml
@@ -1,5 +1,6 @@
language: python
python:
- "2.7"
+ - "3.2"
install: "pip install -r requirements.txt --use-mirrors"
script: "python setup.py test"
View
2  htmlmin/__init__.py
@@ -1,3 +1,3 @@
-from main import minify, Minifier
+from .main import minify, Minifier
__version__ = '0.1'
View
4 htmlmin/command.py
@@ -118,13 +118,13 @@ def main():
else:
inp = sys.stdin
- for line in sys.stdin.readlines():
+ for line in inp.readlines():
minifier.input(line)
if args.output_file:
codecs.open(args.output_file, 'w', encoding=args.encoding).write(minifier.output)
else:
- print minifier.output
+ print(minifier.output)
if __name__ == '__main__':
main()
View
15 htmlmin/parser.py
@@ -1,4 +1,9 @@
-import cgi
+from __future__ import unicode_literals
+try:
+ from html import escape
+except ImportError:
+ from cgi import escape
+
import re
try:
from html.parser import HTMLParser
@@ -48,11 +53,11 @@ def _has_pre(self, attrs):
return False
def build_tag(self, tag, attrs, close_tag):
- result = u'<{}'.format(cgi.escape(tag))
+ result = '<{}'.format(escape(tag))
for k,v in attrs:
- result += ' ' + cgi.escape(k)
+ result += ' ' + escape(k)
if v is not None:
- result += u'="{}"'.format(cgi.escape(v))
+ result += '="{}"'.format(escape(v, quote=True).replace('&#x27;', "'"))
if close_tag:
return result + '/>'
return result + '>'
@@ -155,7 +160,7 @@ def handle_endtag(self, tag):
# closing tags along since they affect output. For instance, a '</p>'
# results in a '<p></p>' in Chrome.
pass
- self._data_buffer.append('</{}>'.format(cgi.escape(tag)))
+ self._data_buffer.append('</{}>'.format(escape(tag)))
def handle_startendtag(self, tag, attrs):
self._after_doctype = False
View
11 htmlmin/tests/tests.py
@@ -1,3 +1,4 @@
+from __future__ import unicode_literals
import unittest
import htmlmin
@@ -226,15 +227,17 @@ class TestMinifyFunction(HTMLMinTestCase):
def test_basic_minification_quality(self):
import codecs
- inp = codecs.open('htmlmin/tests/large_test.html', encoding='utf-8').read()
+ with codecs.open('htmlmin/tests/large_test.html', encoding='utf-8') as inpf:
+ inp = inpf.read()
out = self.minify(inp)
- self.assertEqual(len(inp) - len(out), 796)
+ self.assertEqual(len(inp) - len(out), 776)
def test_high_minification_quality(self):
import codecs
- inp = codecs.open('htmlmin/tests/large_test.html', encoding='utf-8').read()
+ with codecs.open('htmlmin/tests/large_test.html', encoding='utf-8') as inpf:
+ inp = inpf.read()
out = self.minify(inp, remove_all_empty_space=True, remove_comments=True)
- self.assertEqual(len(inp) - len(out), 4033)
+ self.assertEqual(len(inp) - len(out), 4013)
class TestMinifierObject(HTMLMinTestCase):
__reference_texts__ = MINIFY_FUNCTION_TEXTS
Please sign in to comment.
Something went wrong with that request. Please try again.