OLD | NEW |
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 import json | 5 import json |
6 import logging | 6 import logging |
7 import os | 7 import os |
8 import sys | 8 import sys |
9 | 9 |
10 _FILE_PATH = os.path.dirname(os.path.realpath(__file__)) | 10 _FILE_PATH = os.path.dirname(os.path.realpath(__file__)) |
(...skipping 10 matching lines...) Expand all Loading... |
21 | 21 |
22 # Successfully imported, so we're running Python >= 2.7, and json.loads | 22 # Successfully imported, so we're running Python >= 2.7, and json.loads |
23 # supports object_pairs_hook. | 23 # supports object_pairs_hook. |
24 def Parse(json_str): | 24 def Parse(json_str): |
25 return json.loads(json_comment_eater.Nom(json_str), | 25 return json.loads(json_comment_eater.Nom(json_str), |
26 object_pairs_hook=OrderedDict) | 26 object_pairs_hook=OrderedDict) |
27 | 27 |
28 except ImportError: | 28 except ImportError: |
29 # Failed to import, so we're running Python < 2.7, and json.loads doesn't | 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. | 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 ' | 31 # |
32 'Python 2.7.') | 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.') |
33 | 36 |
34 _SYS_PATH = sys.path[:] | 37 _SYS_PATH = sys.path[:] |
35 try: | 38 try: |
36 _SIMPLE_JSON_PATH = os.path.join(_FILE_PATH, | 39 _SIMPLE_JSON_PATH = os.path.join(_FILE_PATH, |
37 os.pardir, | 40 os.pardir, |
38 os.pardir, | 41 os.pardir, |
39 'third_party') | 42 'third_party') |
40 sys.path.insert(0, _SIMPLE_JSON_PATH) | 43 sys.path.insert(0, _SIMPLE_JSON_PATH) |
41 # Add this path in case this is being used in the docs server. | 44 # Add this path in case this is being used in the docs server. |
42 sys.path.insert(0, os.path.join(_FILE_PATH, | 45 sys.path.insert(0, os.path.join(_FILE_PATH, |
43 os.pardir, | 46 os.pardir, |
44 os.pardir, | 47 os.pardir, |
45 'third_party', | 48 'third_party', |
46 'json_schema_compiler')) | 49 'json_schema_compiler')) |
47 import simplejson | 50 import simplejson |
48 from simplejson import OrderedDict | 51 from simplejson import OrderedDict |
49 finally: | 52 finally: |
50 sys.path = _SYS_PATH | 53 sys.path = _SYS_PATH |
51 | 54 |
52 def Parse(json_str): | 55 def Parse(json_str): |
53 return simplejson.loads(json_comment_eater.Nom(json_str), | 56 return simplejson.loads(json_comment_eater.Nom(json_str), |
54 object_pairs_hook=OrderedDict) | 57 object_pairs_hook=OrderedDict) |
55 | 58 |
56 def IsDict(item): | 59 def IsDict(item): |
57 return isinstance(item, (dict, OrderedDict)) | 60 return isinstance(item, (dict, OrderedDict)) |
OLD | NEW |