Blob Blame History Raw
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