Index: tools/json_schema_compiler/idl_schema.py |
diff --git a/tools/json_schema_compiler/idl_schema.py b/tools/json_schema_compiler/idl_schema.py |
index 30dad11555428459b5b48ff0f9c1e8f92b27381e..f2b9f7d3ac29eac7b25e4e78f8d58c429ade6254 100644 |
--- a/tools/json_schema_compiler/idl_schema.py |
+++ b/tools/json_schema_compiler/idl_schema.py |
@@ -11,6 +11,14 @@ import sys |
import schema_util |
+try: |
+ from collections import OrderedDict |
+except ImportError: |
+ # Failed to import, so we're running Python < 2.7. Use OrderedDict from |
+ # simplejson. |
+ import simplejson |
+ from simplejson import OrderedDict |
not at google - send to devlin
2013/01/14 15:26:25
hm, we already have logic which does this in json_
Matt Giuca
2013/01/17 05:30:53
Done.
|
+ |
# This file is a peer to json_schema.py. Each of these files understands a |
# certain format describing APIs (either JSON or IDL), reads files written |
# in that format into memory, and emits them as a Python array of objects |
@@ -70,7 +78,7 @@ def ProcessComment(comment): |
parent_comment = (parent_comment.strip().replace('\n\n', '<br/><br/>') |
.replace('\n', '')) |
- params = {} |
+ params = OrderedDict() |
for (cur_param, next_param) in itertools.izip_longest(parameter_starts, |
parameter_starts[1:]): |
param_name = cur_param.group(1) |
@@ -124,7 +132,7 @@ class Dictionary(object): |
self.node = dictionary_node |
def process(self, callbacks): |
- properties = {} |
+ properties = OrderedDict() |
for node in self.node.children: |
if node.cls == 'Member': |
k, v = Member(node).process(callbacks) |
@@ -147,13 +155,13 @@ class Member(object): |
self.node = member_node |
def process(self, callbacks): |
- properties = {} |
+ properties = OrderedDict() |
name = self.node.GetName() |
for property_name in ('OPTIONAL', 'nodoc', 'nocompile'): |
if self.node.GetProperty(property_name): |
properties[property_name.lower()] = True |
is_function = False |
- parameter_comments = {} |
+ parameter_comments = OrderedDict() |
for node in self.node.children: |
if node.cls == 'Comment': |
(parent_comment, parameter_comments) = ProcessComment(node.GetName()) |
@@ -183,7 +191,7 @@ class Typeref(object): |
function parameter, converts into a Python dictionary that the JSON schema |
compiler expects to see. |
''' |
- def __init__(self, typeref, parent, additional_properties={}): |
+ def __init__(self, typeref, parent, additional_properties=OrderedDict()): |
self.typeref = typeref |
self.parent = parent |
self.additional_properties = additional_properties |
@@ -200,7 +208,7 @@ class Typeref(object): |
for sibling in self.parent.GetChildren(): |
if sibling.cls == 'Array' and sibling.GetName() == self.parent.GetName(): |
properties['type'] = 'array' |
- properties['items'] = {} |
+ properties['items'] = OrderedDict() |
properties = properties['items'] |
break |
@@ -217,7 +225,7 @@ class Typeref(object): |
elif self.typeref == 'object': |
properties['type'] = 'object' |
if 'additionalProperties' not in properties: |
- properties['additionalProperties'] = {} |
+ properties['additionalProperties'] = OrderedDict() |
properties['additionalProperties']['type'] = 'any' |
instance_of = self.parent.GetProperty('instanceOf') |
if instance_of: |
@@ -283,7 +291,7 @@ class Namespace(object): |
self.events = [] |
self.functions = [] |
self.types = [] |
- self.callbacks = {} |
+ self.callbacks = OrderedDict() |
self.permissions = permissions or [] |
def process(self): |