[Pkg-isocodes-devel] [iso-codes] 01/03: Ensure UTF-8 encoding for handling JSON data

Tobias Quathamer toddy at moszumanska.debian.org
Mon May 2 18:41:21 UTC 2016


This is an automated email from the git hooks/post-receive script.

toddy pushed a commit to branch master
in repository iso-codes.

commit baa7d2bb579f52eb7cfb786321b814cd67d232c6
Author: Dr. Tobias Quathamer <toddy at debian.org>
Date:   Mon May 2 09:00:02 2016 +0200

    Ensure UTF-8 encoding for handling JSON data
---
 bin/pot_from_json.py      | 4 ++--
 bin/validate_json_data.py | 8 ++++----
 bin/xml_from_json.py      | 4 ++--
 3 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/bin/pot_from_json.py b/bin/pot_from_json.py
index d616d0a..0fd21a6 100755
--- a/bin/pot_from_json.py
+++ b/bin/pot_from_json.py
@@ -53,7 +53,7 @@ if domain == "iso_3166-2":
     comment = "code"
 
 # Read in the JSON file
-with open(datapath + "/" + domain + ".json") as json_file:
+with open(datapath + "/" + domain + ".json", encoding="utf-8") as json_file:
     iso = json.load(json_file)
 
 # Helper function for keeping track of msgids and comments
@@ -83,7 +83,7 @@ for item in iso[iso_number]:
         add_msgid(item["inverted_name"], "Inverted name for " + item[comment])
 
 # Write the POT file
-with open(domain + ".pot", "w") as pot_file:
+with open(domain + ".pot", "w", encoding="utf-8") as pot_file:
     # Write the header
     pot_file.write("# Translation of ISO " + iso_number + " to LANGUAGE\n")
     pot_file.write("# " + description[domain] + "\n")
diff --git a/bin/validate_json_data.py b/bin/validate_json_data.py
index 12c3505..9f7daad 100755
--- a/bin/validate_json_data.py
+++ b/bin/validate_json_data.py
@@ -34,15 +34,15 @@ standards = [
 
 # Validate against schema
 for standard in standards:
-    with open("data/schema-" + standard + ".json") as schema_file:
+    with open("data/schema-" + standard + ".json", encoding="utf-8") as schema_file:
         schema = json.load(schema_file)
-        with open("data/iso_" + standard + ".json") as json_file:
+        with open("data/iso_" + standard + ".json", encoding="utf-8") as json_file:
             validate(json.load(json_file), schema)
 
 # Ensure correct sorting order
 for standard in standards:
     # Read in the JSON file
-    with open("data/iso_" + standard + ".json") as json_file:
+    with open("data/iso_" + standard + ".json", encoding="utf-8") as json_file:
         iso = json.load(json_file)
     sort_key = "alpha_3"
     if standard in ["3166-3", "15924"]:
@@ -51,7 +51,7 @@ for standard in standards:
         sort_key = "code"
     iso[standard].sort(key=lambda item: item[sort_key])
     # Write the sorted JSON file
-    with open("data/iso_" + standard + ".json", "w") as json_file:
+    with open("data/iso_" + standard + ".json", "w", encoding="utf-8") as json_file:
         json.dump(iso, json_file, ensure_ascii=False, indent=2, sort_keys=True)
         # Add a final newline
         json_file.write("\n")
diff --git a/bin/xml_from_json.py b/bin/xml_from_json.py
index 85dad24..d28b626 100755
--- a/bin/xml_from_json.py
+++ b/bin/xml_from_json.py
@@ -392,12 +392,12 @@ Source: <http://www.bsi-global.com/en/Standards-and-Publications/Industry-Sector
 def get_iso_entries(standard):
     """ Return all entries from the given standard
     """
-    with open(datapath + "/iso_" + standard + ".json") as input_file:
+    with open(datapath + "/iso_" + standard + ".json", encoding="utf-8") as input_file:
         iso = json.load(input_file)
         return iso[standard]
 
 # Create the output file
-with open(xml_file, "w") as outfile:
+with open(xml_file, "w", encoding="utf-8") as outfile:
     #
     # Handle ISO 639-2
     #

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-isocodes/iso-codes.git



More information about the Pkg-isocodes-devel mailing list