Add backported UTF-8 encoding patch

Fixes use of ducktype when the locale encoding is ascii, such as when
building an RPM.
This commit is contained in:
David King 2015-09-10 10:26:11 +01:00
parent 453cc974db
commit 33798209d4
2 changed files with 45 additions and 1 deletions

View File

@ -0,0 +1,38 @@
From ec2b427c8b9555b9fb4fa045c6cdd7a5878d9583 Mon Sep 17 00:00:00 2001
From: David King <dking@redhat.com>
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

View File

@ -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 <amigadave@amigadave.com> - 0.2-2
- Add backported UTF-8 encoding patch
* Tue Sep 08 2015 David King <amigadave@amigadave.com> - 0.2-1
- Update to 0.2