Skip to content

Improve python3 support #204

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions pystache/common.py
Original file line number Diff line number Diff line change
@@ -14,6 +14,8 @@ def _get_string_types():
# and "basestring" to Python 3's "str".
if version_info < (3, ):
return basestring
else:
unicode = str
# The latter evaluates to "bytes" in Python 3 -- even after conversion by 2to3.
return (unicode, type(u"a".encode('utf-8')))

9 changes: 7 additions & 2 deletions pystache/parser.py
Original file line number Diff line number Diff line change
@@ -6,13 +6,17 @@
"""

import re
import sys

if sys.version_info.major >= 3:
unicode = str

from pystache import defaults
from pystache.parsed import ParsedTemplate


END_OF_LINE_CHARACTERS = [u'\r', u'\n']
NON_BLANK_RE = re.compile(ur'^(.)', re.M)
NON_BLANK_RE = re.compile(u'^(.)', re.M)


# TODO: add some unit tests for this.
@@ -146,8 +150,9 @@ def __repr__(self):

def render(self, engine, context):
template = engine.resolve_partial(self.key)

# Indent before rendering.
template = re.sub(NON_BLANK_RE, self.indent + ur'\1', template)
template = re.sub(NON_BLANK_RE, self.indent + u'\\1', template)

return engine.render(template, context)