Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(383)

Unified Diff: tools/json_schema_compiler/json_parse.py

Issue 11079010: Extensions Docs Server: Preserve JSON declaration order in extensions documentation (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: more efficient ordered_dict Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: tools/json_schema_compiler/json_parse.py
diff --git a/tools/json_schema_compiler/json_parse.py b/tools/json_schema_compiler/json_parse.py
new file mode 100644
index 0000000000000000000000000000000000000000..563faef5f9d1c539448755e0e076468a90e442a8
--- /dev/null
+++ b/tools/json_schema_compiler/json_parse.py
@@ -0,0 +1,35 @@
+# Copyright (c) 2012 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import json
+import os
+import sys
+
+try:
+ from collections import OrderedDict
+except ImportError:
+ from ordered_dict import OrderedDict
+
not at google - send to devlin 2012/11/16 18:45:56 Can we incorporate this file into ordered_dict.py?
cduvall 2012/11/17 01:55:12 Done.
+SYS_PATH = sys.path[:]
+try:
+ _FILE_PATH = os.path.dirname(os.path.realpath(__file__))
+ _SIMPLE_JSON_PATH = os.path.join(_FILE_PATH,
+ os.pardir,
+ os.pardir,
+ 'simplejson')
+ sys.path.insert(0, _SIMPLE_JSON_PATH)
+ import simplejson
+ _COMMENT_EATER_PATH = os.path.join(_FILE_PATH, os.pardir)
+ sys.path.insert(0, _COMMENT_EATER_PATH)
+ import json_comment_eater
+finally:
+ sys.path = SYS_PATH
+
+
+def Parse(json_str):
+ json_str = json_comment_eater.Nom(json_str)
+ try:
+ return json.loads(json_str, object_pairs_hook=OrderedDict)
+ except TypeError:
+ return simplejson.loads(json_str, object_pairs_hook=OrderedDict)

Powered by Google App Engine
This is Rietveld 408576698