Skip to content
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

To work for Python 3 #72

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
*.pyc
*.swp
*.swo
*.bak
.coverage
coverage.xml
nose.xml
Expand Down
2 changes: 1 addition & 1 deletion htmlmin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.

__version__ = '0.7.0'
__version__ = '0.7.1'
4 changes: 2 additions & 2 deletions htmlmin/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

def main():
parser = argparse.ArgumentParser(
description=u'Minify content of HTML files',
description='Minify content of HTML files',
)
parser.add_argument('filename', metavar='filename', type=str, nargs=1)
parser.add_argument('--keep-comments', action='store_true')
Expand All @@ -21,4 +21,4 @@ def main():
with open(os.path.join(my_dir, args.filename[0])) as html_file:
content = html_file.read()

print html_minify(content, ignore_comments=not args.keep_comments)
print(html_minify(content, ignore_comments=not args.keep_comments))
6 changes: 3 additions & 3 deletions htmlmin/minify.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ def html_minify(html_code, ignore_comments=True, parser="html5lib"):
mini_soup = space_minify(soup, ignore_comments)
if FOLD_DOCTYPE is True:
# monkey patching to remove new line after doctype
bs4.element.Doctype.SUFFIX = u'>'
return unicode(mini_soup)
bs4.element.Doctype.SUFFIX = '>'
return str(mini_soup)

def space_minify(soup, ignore_comments=True):
"""recursive function to reduce space characters in html code.
Expand Down Expand Up @@ -104,7 +104,7 @@ def space_minify(soup, ignore_comments=True):
# conditional comment and
elif ignore_comments == True and is_comment(soup):
# remove the element
soup.string.replace_with(u'')
soup.string.replace_with('')
return soup

def is_navstr(soup):
Expand Down
2 changes: 1 addition & 1 deletion htmlmin/tests/test_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from django.conf import settings
from htmlmin.middleware import HtmlMinifyMiddleware, MarkRequestMiddleware
from htmlmin.tests import TESTS_DIR
from mocks import RequestMock, RequestBareMock, ResponseMock, ResponseWithCommentMock
from .mocks import RequestMock, RequestBareMock, ResponseMock, ResponseWithCommentMock


class TestMiddleware(unittest.TestCase):
Expand Down
2 changes: 1 addition & 1 deletion htmlmin/tests/test_minify.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def test_html_should_be_minified(self):
def test_minify_function_should_return_a_unicode_object(self):
html = "<html> <body>some text here</body> </html>"
minified = html_minify(html)
self.assertEqual(unicode, type(minified))
self.assertEqual(str, type(minified))

def test_minify_should_respect_encoding(self):
html, minified = self._normal_and_minified('blogpost')
Expand Down
6 changes: 3 additions & 3 deletions htmlmin/tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ class TestUtil(unittest.TestCase):

def test_should_decode_a_utf8_string(self):
string = "Blá blá"
self.assertEqual(u"Blá blá", force_decode(string))
self.assertEqual("Blá blá", force_decode(string))

def test_shoulde_decode_a_latin_string(self):
unicode_object = "Blá blá".decode("utf-8").encode("latin-1")
string = str(unicode_object)
self.assertEqual(u"Blá blá", force_decode(string))
self.assertEqual("Blá blá", force_decode(string))

def test_should_be_able_to_chose_the_encoding(self):
ENCODING = 'IBM857'
unicode_object = "Blá blá".decode("utf-8").encode(ENCODING)
string = str(unicode_object)
self.assertEqual(u"Blá blá", force_decode(string, encoding=ENCODING))
self.assertEqual("Blá blá", force_decode(string, encoding=ENCODING))

def test_should_be_between_two_tags(self):
all_lines = [
Expand Down