From 26ee5ff3cdac5f0e27bdeca7ab6c89c1b2003905 Mon Sep 17 00:00:00 2001
From: Sascha Steinbiss <satta@debian.org>
Date: Sun, 26 Feb 2017 17:40:09 +0000
Subject: [PATCH] address encoding issues to fix #750895

---
 debian/changelog                       |  5 ++++
 debian/patches/0001-fix-encoding.patch | 46 ++++++++++++++++++++++++++++++++++
 debian/patches/series                  |  1 +
 debian/tests/control                   |  2 ++
 debian/tests/test-installed            |  8 ++++++
 debian/tests/test.tmpl                 |  2 ++
 6 files changed, 64 insertions(+)
 create mode 100644 debian/patches/0001-fix-encoding.patch
 create mode 100644 debian/patches/series
 create mode 100644 debian/tests/control
 create mode 100644 debian/tests/test-installed
 create mode 100644 debian/tests/test.tmpl

diff --git a/debian/changelog b/debian/changelog
index 08dcaac..c827bf1 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,7 +1,12 @@
 python-tempita (0.5.2-2) UNRELEASED; urgency=medium
 
+  [ Ondřej Nový ]
   * Fixed VCS URL (https)
 
+  [ Sascha Steinbiss ]
+  * Address encoding issue on Python 3.
+    Closes: #750895
+
  -- Ondřej Nový <novy@ondrej.org>  Tue, 29 Mar 2016 22:24:41 +0200
 
 python-tempita (0.5.2-1) unstable; urgency=medium
diff --git a/debian/patches/0001-fix-encoding.patch b/debian/patches/0001-fix-encoding.patch
new file mode 100644
index 0000000..e697841
--- /dev/null
+++ b/debian/patches/0001-fix-encoding.patch
@@ -0,0 +1,46 @@
+From: Sascha Steinbiss <satta@debian.org>
+Date: Sun, 26 Feb 2017 16:55:35 +0000
+Subject: fix encoding
+
+Addresses #750895 by backporting upstream's fix.
+---
+ tempita/__init__.py | 4 +++-
+ tempita/compat3.py  | 4 +++-
+ 2 files changed, 6 insertions(+), 2 deletions(-)
+
+diff --git a/tempita/__init__.py b/tempita/__init__.py
+index 91407b3..c36e2b9 100644
+--- a/tempita/__init__.py
++++ b/tempita/__init__.py
+@@ -37,7 +37,7 @@ import os
+ import tokenize
+ from cStringIO import StringIO
+ from tempita._looper import looper
+-from tempita.compat3 import bytes, basestring_, next, is_unicode, coerce_text
++from tempita.compat3 import PY3, bytes, basestring_, next, is_unicode, coerce_text
+ 
+ __all__ = ['TemplateError', 'Template', 'sub', 'HTMLTemplate',
+            'sub_html', 'html', 'bunch']
+@@ -143,6 +143,8 @@ class Template(object):
+         f.close()
+         if encoding:
+             c = c.decode(encoding)
++        if PY3:
++            c = c.decode('latin-1')
+         return cls(content=c, name=filename, namespace=namespace,
+                    default_inherit=default_inherit, get_template=get_template)
+ 
+diff --git a/tempita/compat3.py b/tempita/compat3.py
+index 5e18fa0..63098e4 100644
+--- a/tempita/compat3.py
++++ b/tempita/compat3.py
+@@ -1,6 +1,8 @@
+ import sys
+ 
+-__all__ = ['b', 'basestring_', 'bytes', 'next', 'is_unicode']
++__all__ = ['PY3', 'b', 'basestring_', 'bytes', 'next', 'is_unicode']
++
++PY3 = True if sys.version_info[0] == 3 else False
+ 
+ if sys.version < "3":
+     b = bytes = str
diff --git a/debian/patches/series b/debian/patches/series
new file mode 100644
index 0000000..acdaa7d
--- /dev/null
+++ b/debian/patches/series
@@ -0,0 +1 @@
+0001-fix-encoding.patch
diff --git a/debian/tests/control b/debian/tests/control
new file mode 100644
index 0000000..636b906
--- /dev/null
+++ b/debian/tests/control
@@ -0,0 +1,2 @@
+Tests: test-installed
+Depends: @
diff --git a/debian/tests/test-installed b/debian/tests/test-installed
new file mode 100644
index 0000000..f1bba83
--- /dev/null
+++ b/debian/tests/test-installed
@@ -0,0 +1,8 @@
+#!/usr/bin/env python3
+
+import os
+from tempita import Template as t
+
+tmpldir = os.path.dirname(os.path.realpath(__file__))
+w = t.from_filename(os.path.join(tmpldir, "test.tmpl"))
+print(str(w.substitute()))
diff --git a/debian/tests/test.tmpl b/debian/tests/test.tmpl
new file mode 100644
index 0000000..1c6d66b
--- /dev/null
+++ b/debian/tests/test.tmpl
@@ -0,0 +1,2 @@
+{{py:x="Hello"}}
+{{x}} Test
-- 
2.11.0

