summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyan Petrello <lists@ryanpetrello.com>2013-05-01 07:19:35 -0400
committerRyan Petrello <lists@ryanpetrello.com>2013-05-01 07:19:35 -0400
commit2e9b2e44745aef8efca0121880e558e9cf14e406 (patch)
tree488fc1fa68b9faf884111bb2e29f3d245d360185
parent8b748c17322a44c66a2d7baad847c19482acd001 (diff)
downloadpecan-2e9b2e44745aef8efca0121880e558e9cf14e406.tar.gz
Refactor remnants of pecan.compat with alternatives from the six package.
-rw-r--r--pecan/compat/__init__.py29
-rw-r--r--pecan/scaffolds/__init__.py22
2 files changed, 17 insertions, 34 deletions
diff --git a/pecan/compat/__init__.py b/pecan/compat/__init__.py
index 6efe111..02a0631 100644
--- a/pecan/compat/__init__.py
+++ b/pecan/compat/__init__.py
@@ -1,36 +1,7 @@
-import sys
import inspect
import six
-if six.PY3: # pragma: no cover
- text_type = str
-else:
- text_type = unicode
-
-
-if six.PY3: # pragma: no cover
- def native_(s, encoding='latin-1', errors='strict'):
- """ If ``s`` is an instance of ``text_type``, return
- ``s``, otherwise return ``str(s, encoding, errors)``"""
- if isinstance(s, text_type):
- return s
- return str(s, encoding, errors)
-else:
- def native_(s, encoding='latin-1', errors='strict'): # noqa
- """ If ``s`` is an instance of ``text_type``, return
- ``s.encode(encoding, errors)``, otherwise return ``str(s)``"""
- if isinstance(s, text_type):
- return s.encode(encoding, errors)
- return str(s)
-
-native_.__doc__ = """
-Python 3: If ``s`` is an instance of ``text_type``, return ``s``, otherwise
-return ``str(s, encoding, errors)``
-
-Python 2: If ``s`` is an instance of ``text_type``, return
-``s.encode(encoding, errors)``, otherwise return ``str(s)``
-"""
def is_bound_method(ob):
return inspect.ismethod(ob) and six.get_method_self(ob) is not None
diff --git a/pecan/scaffolds/__init__.py b/pecan/scaffolds/__init__.py
index bbcd677..ac22464 100644
--- a/pecan/scaffolds/__init__.py
+++ b/pecan/scaffolds/__init__.py
@@ -6,8 +6,6 @@ from string import Template
import six
-from pecan.compat import native_
-
DEFAULT_SCAFFOLD = 'base'
_bad_chars_re = re.compile('[^a-zA-Z0-9_]')
@@ -121,6 +119,20 @@ def render_template(content, variables):
input (content) and the variable names defined (vars).
"""
fsenc = sys.getfilesystemencoding()
- content = native_(content, fsenc)
- bytes_ = lambda s, enc: s.encode(enc) if six.PY3 else s
- return bytes_(Template(content).substitute(variables), fsenc)
+
+ def to_native(s, encoding='latin-1', errors='strict'):
+ if six.PY3:
+ if isinstance(s, six.text_type):
+ return s
+ return str(s, encoding, errors)
+ else:
+ if isinstance(s, six.text_type):
+ return s.encode(encoding, errors)
+ return str(s)
+
+ output = Template(
+ to_native(content, fsenc)
+ ).substitute(variables)
+ if isinstance(output, six.text_type):
+ output = output.encode(fsenc, 'strict')
+ return output