From 8412376285d9ae528e6df46c3cf82b296a27e788 Mon Sep 17 00:00:00 2001 From: sloria Date: Sun, 27 Jul 2014 19:36:19 -0400 Subject: [PATCH] Add compat.py and fix Python 3 error --- .../requirements/prod.txt | 1 - .../{{cookiecutter.app_name}}/compat.py | 20 +++++++++++++++++++ .../{{cookiecutter.app_name}}/database.py | 1 + 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 {{cookiecutter.app_name}}/{{cookiecutter.app_name}}/compat.py diff --git a/{{cookiecutter.app_name}}/requirements/prod.txt b/{{cookiecutter.app_name}}/requirements/prod.txt index c4719fa..2c27826 100644 --- a/{{cookiecutter.app_name}}/requirements/prod.txt +++ b/{{cookiecutter.app_name}}/requirements/prod.txt @@ -20,7 +20,6 @@ WTForms==2.0 # Deployment gunicorn>=17.5 -wsgiref>=0.1.2 # Assets Flask-Assets==0.10 diff --git a/{{cookiecutter.app_name}}/{{cookiecutter.app_name}}/compat.py b/{{cookiecutter.app_name}}/{{cookiecutter.app_name}}/compat.py new file mode 100644 index 0000000..863f2a0 --- /dev/null +++ b/{{cookiecutter.app_name}}/{{cookiecutter.app_name}}/compat.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +"""Python 2/3 compatibility module.""" + + +import sys + +PY2 = int(sys.version[0]) == 2 + +if PY2: + text_type = unicode + binary_type = str + string_types = (str, unicode) + unicode = unicode + basestring = basestring +else: + text_type = str + binary_type = bytes + string_types = (str,) + unicode = str + basestring = (str, bytes) diff --git a/{{cookiecutter.app_name}}/{{cookiecutter.app_name}}/database.py b/{{cookiecutter.app_name}}/{{cookiecutter.app_name}}/database.py index 6dbff38..3120766 100644 --- a/{{cookiecutter.app_name}}/{{cookiecutter.app_name}}/database.py +++ b/{{cookiecutter.app_name}}/{{cookiecutter.app_name}}/database.py @@ -5,6 +5,7 @@ utilities. from sqlalchemy.orm import relationship from .extensions import db +from .compat import basestring # Alias common SQLAlchemy names Column = db.Column