Skip to content

Commit

Permalink
Python 3.6 support
Browse files Browse the repository at this point in the history
  • Loading branch information
ale-rt committed Oct 24, 2017
1 parent 5f1615d commit a940201
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
@@ -1,6 +1,8 @@
language: python
python:
- 2.7
- 3.5
- 3.6
install:
- make
script:
Expand Down
1 change: 0 additions & 1 deletion README.rst
Expand Up @@ -114,7 +114,6 @@ TODO

.. _todo_section:

- [ ] Python 3 support ... ;)
- [ ] Valueless attributes are not allowed in XML
- [ ] Attributes are aligned in a strange way if previous sibling has no spaces
- [ ] TBD: Style attributes should be multiline
3 changes: 2 additions & 1 deletion setup.py
Expand Up @@ -32,7 +32,7 @@ def read(*rnames):
'Intended Audience :: Developers',
'Programming Language :: Python',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 2 :: Only',
'Programming Language :: Python :: 3.6',
],
author='Alessandro Pisa',
author_email='alessandro.pisa@gmail.com',
Expand All @@ -41,6 +41,7 @@ def read(*rnames):
packages=find_packages(),
install_requires=[
'setuptools',
'six',
'beautifulsoup4',
'lxml',
],
Expand Down
4 changes: 3 additions & 1 deletion zpretty/elements.py
Expand Up @@ -12,6 +12,8 @@
from zpretty.text import rstrip_last_line
from zpretty.text import startswith_whitespace

import six


class OpenTagException(Exception):
''' We want this element to be closed
Expand Down Expand Up @@ -212,7 +214,7 @@ def text(self):
if not isinstance(self.context, NavigableString):
return u''
if self.is_comment():
return unicode(self.context)
return six.text_type(self.context)
return self.escaper.substitute_html(self.context.string)

@property
Expand Down
5 changes: 3 additions & 2 deletions zpretty/prettifier.py
Expand Up @@ -5,6 +5,7 @@
from zpretty.elements import PrettyElement

import fileinput
import six


logger = getLogger(__name__)
Expand All @@ -18,7 +19,7 @@ class ZPrettifier(object):
parser = 'html.parser'
builder = None
_end_with_newline = True
_newlines_marker = unicode(uuid4())
_newlines_marker = six.text_type(uuid4())

def __init__(
self,
Expand All @@ -33,7 +34,7 @@ def __init__(
self.filename = filename
if self.filename:
text = ''.join(fileinput.input([filename]))
if not isinstance(text, unicode):
if not isinstance(text, six.text_type):
text = text.decode(self.encoding)
self.text = "\n".join(
line if line.strip() else self._newlines_marker
Expand Down
5 changes: 3 additions & 2 deletions zpretty/text.py
@@ -1,12 +1,13 @@
# coding=utf-8
import six


def startswith_whitespace(text):
''' Check if text starts with a whitespace
If text is not a string return False
'''
if not isinstance(text, basestring):
if not isinstance(text, six.string_types):
return False
return text[:1].isspace()

Expand All @@ -16,7 +17,7 @@ def endswith_whitespace(text):
If text is not a string return False
'''
if not isinstance(text, basestring):
if not isinstance(text, six.string_types):
return False
return text[-1:].isspace()

Expand Down

0 comments on commit a940201

Please sign in to comment.