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

Side by Side 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: updated with the new simplejson Created 8 years, 1 month 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4
5 import json
6 import logging
7 import os
8 import sys
9
10 _FILE_PATH = os.path.dirname(os.path.realpath(__file__))
11 _SYS_PATH = sys.path[:]
12 try:
13 _COMMENT_EATER_PATH = os.path.join(_FILE_PATH, os.pardir)
14 sys.path.insert(0, _COMMENT_EATER_PATH)
15 import json_comment_eater
16 finally:
17 sys.path = _SYS_PATH
18
19 try:
20 from collections import OrderedDict
21
22 # Successfully imported, so we're running Python >= 2.7, and json.loads
23 # supports object_pairs_hook.
24 def Parse(json_str):
25 return json.loads(json_comment_eater.Nom(json_str),
26 object_pairs_hook=OrderedDict)
27
28 except ImportError:
29 # Failed to import, so we're running Python < 2.7, and json.loads doesn't
30 # support object_pairs_hook. simplejson however does, but it's slow.
31 logging.warning('Using simplejson to parse, this might be slow! Upgrade to '
32 'Python 2.7.')
33
34 _SYS_PATH = sys.path[:]
35 try:
36 _SIMPLE_JSON_PATH = os.path.join(_FILE_PATH,
37 os.pardir,
38 os.pardir,
39 'third_party')
40 sys.path.insert(0, _SIMPLE_JSON_PATH)
41 # Add this path in case this is being used in the docs server.
42 sys.path.insert(0, os.path.join(_FILE_PATH,
43 os.pardir,
44 os.pardir,
45 'third_party',
46 'json_schema_compiler'))
47 import simplejson
48 from simplejson import OrderedDict
49 finally:
50 sys.path = _SYS_PATH
51
52 def Parse(json_str):
53 return simplejson.loads(json_comment_eater.Nom(json_str),
54 object_pairs_hook=OrderedDict)
55
56 def IsDict(item):
57 return isinstance(item, (dict, OrderedDict))
OLDNEW
« no previous file with comments | « chrome/common/extensions/docs/server2/build_server.py ('k') | tools/json_schema_compiler/json_schema.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698