community-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r1867596 - /comdev/projects.apache.org/trunk/scripts/cronjobs/jsonutils.py
Date Thu, 26 Sep 2019 17:35:39 GMT
Author: sebb
Date: Thu Sep 26 17:35:39 2019
New Revision: 1867596

URL: http://svn.apache.org/viewvc?rev=1867596&view=rev
Log:
JSON utils

Added:
    comdev/projects.apache.org/trunk/scripts/cronjobs/jsonutils.py   (with props)

Added: comdev/projects.apache.org/trunk/scripts/cronjobs/jsonutils.py
URL: http://svn.apache.org/viewvc/comdev/projects.apache.org/trunk/scripts/cronjobs/jsonutils.py?rev=1867596&view=auto
==============================================================================
--- comdev/projects.apache.org/trunk/scripts/cronjobs/jsonutils.py (added)
+++ comdev/projects.apache.org/trunk/scripts/cronjobs/jsonutils.py Thu Sep 26 17:35:39 2019
@@ -0,0 +1,27 @@
+#!/usr/bin/env python3
+
+"""
+   Some utilities for working with JSON
+   Python3 only
+"""
+
+import sys
+if sys.hexversion < 0x03000000:
+    raise ImportError("This script requires Python 3")
+import json
+
+def write_utf8(output, path, indent=1, sort_keys=True, ensure_ascii=False):
+    """
+    Write output to the given file path using UTF_8
+    Defaults to sorted keys, ident=1
+    Preserves UTF-8 characters by default.
+    """
+    with open(path, "w", encoding='utf-8') as f:
+        json.dump(output, f, indent=indent, sort_keys=sort_keys, ensure_ascii=ensure_ascii)
+        
+def read_utf8(path):
+    """
+    Read and parse JSON from the given file path assuming UTF-8 encoding
+    """
+    with open(path, "rb") as f:
+        input = json.loads(f.read().decode('UTF-8', errors='replace'))

Propchange: comdev/projects.apache.org/trunk/scripts/cronjobs/jsonutils.py
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message