From 33798209d4e5bd1f4f8cca038592698b19db065c Mon Sep 17 00:00:00 2001 From: David King Date: Thu, 10 Sep 2015 10:26:11 +0100 Subject: [PATCH] Add backported UTF-8 encoding patch Fixes use of ducktype when the locale encoding is ascii, such as when building an RPM. --- mallard-ducktype-0.2-open-utf8.patch | 38 ++++++++++++++++++++++++++++ python3-mallard-ducktype.spec | 8 +++++- 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 mallard-ducktype-0.2-open-utf8.patch diff --git a/mallard-ducktype-0.2-open-utf8.patch b/mallard-ducktype-0.2-open-utf8.patch new file mode 100644 index 0000000..e56026e --- /dev/null +++ b/mallard-ducktype-0.2-open-utf8.patch @@ -0,0 +1,38 @@ +From ec2b427c8b9555b9fb4fa045c6cdd7a5878d9583 Mon Sep 17 00:00:00 2001 +From: David King +Date: Wed, 9 Sep 2015 11:32:08 +0100 +Subject: [PATCH] Open files as UTF-8 + +Do not rely on the platform-preferred encoding when opening files, and +instead force UTF-8 encoding. + +Fixes #11 +--- + mallard/ducktype/parser.py | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/mallard/ducktype/parser.py b/mallard/ducktype/parser.py +index 35ea594..da73f54 100644 +--- a/mallard/ducktype/parser.py ++++ b/mallard/ducktype/parser.py +@@ -169,7 +169,7 @@ class Node: + fd = sys.stdout + elif isinstance(outfile, str): + close = True +- fd = open(outfile, 'w') ++ fd = open(outfile, 'w', encoding='utf-8') + else: + fd = outfile + self._write_xml(fd) +@@ -651,7 +651,7 @@ class DuckParser: + self._defaultid = os.path.basename(filename) + if self._defaultid.endswith('.duck'): + self._defaultid = self._defaultid[:-5] +- fd = open(filename) ++ fd = open(filename, encoding='utf-8') + for line in fd: + self.parse_line(line) + fd.close() +-- +2.5.1 + diff --git a/python3-mallard-ducktype.spec b/python3-mallard-ducktype.spec index 63876e8..8de20d9 100644 --- a/python3-mallard-ducktype.spec +++ b/python3-mallard-ducktype.spec @@ -2,12 +2,14 @@ Name: python3-mallard-ducktype Version: 0.2 -Release: 1%{?dist} +Release: 2%{?dist} Summary: Parse Ducktype files and convert them to Mallard License: MIT URL: https://pypi.python.org/pypi/%{srcname} Source0: https://pypi.python.org/packages/source/m/%{srcname}/%{srcname}-%{version}.tar.gz +# https://github.com/projectmallard/mallard-ducktype/issues/11 +Patch0: %{srcname}-0.2-open-utf8.patch BuildArch: noarch BuildRequires: python3-devel @@ -19,6 +21,7 @@ Parse Ducktype files and convert them to Mallard. %prep %setup -q -n %{srcname}-%{version} rm -rf %{srcname}-%{version}/mallard_ducktype.egg-info/ +%patch0 -p1 %build @@ -42,6 +45,9 @@ rm -rf %{srcname}-%{version}/mallard_ducktype.egg-info/ %changelog +* Wed Sep 09 2015 David King - 0.2-2 +- Add backported UTF-8 encoding patch + * Tue Sep 08 2015 David King - 0.2-1 - Update to 0.2