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

Side by Side Diff: third_party/chrome/tools/json_parse.py

Issue 12261015: Import chrome idl into third_party (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 10 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « third_party/chrome/tools/idl_schema_test.py ('k') | third_party/chrome/tools/json_schema.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #
32 # TODO(cduvall/kalman): Refuse to start the docs server in this case, but
33 # let json-schema-compiler do its thing.
34 #logging.warning('Using simplejson to parse, this might be slow! Upgrade to '
35 # 'Python 2.7.')
36
37 _SYS_PATH = sys.path[:]
38 try:
39 _SIMPLE_JSON_PATH = os.path.join(_FILE_PATH,
40 os.pardir,
41 os.pardir,
42 'third_party')
43 sys.path.insert(0, _SIMPLE_JSON_PATH)
44 # Add this path in case this is being used in the docs server.
45 sys.path.insert(0, os.path.join(_FILE_PATH,
46 os.pardir,
47 os.pardir,
48 'third_party',
49 'json_schema_compiler'))
50 import simplejson
51 from simplejson import OrderedDict
52 finally:
53 sys.path = _SYS_PATH
54
55 def Parse(json_str):
56 return simplejson.loads(json_comment_eater.Nom(json_str),
57 object_pairs_hook=OrderedDict)
58
59 def IsDict(item):
60 return isinstance(item, (dict, OrderedDict))
OLDNEW
« no previous file with comments | « third_party/chrome/tools/idl_schema_test.py ('k') | third_party/chrome/tools/json_schema.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698