| OLD | NEW |
| 1 # Copyright (C) 2013 Google Inc. All rights reserved. | 1 # Copyright (C) 2013 Google Inc. All rights reserved. |
| 2 # | 2 # |
| 3 # Redistribution and use in source and binary forms, with or without | 3 # Redistribution and use in source and binary forms, with or without |
| 4 # modification, are permitted provided that the following conditions are | 4 # modification, are permitted provided that the following conditions are |
| 5 # met: | 5 # met: |
| 6 # | 6 # |
| 7 # * Redistributions of source code must retain the above copyright | 7 # * Redistributions of source code must retain the above copyright |
| 8 # notice, this list of conditions and the following disclaimer. | 8 # notice, this list of conditions and the following disclaimer. |
| 9 # * Redistributions in binary form must reproduce the above | 9 # * Redistributions in binary form must reproduce the above |
| 10 # copyright notice, this list of conditions and the following disclaimer | 10 # copyright notice, this list of conditions and the following disclaimer |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 'idlDocument::enumerations': self.enumerations.values(), | 118 'idlDocument::enumerations': self.enumerations.values(), |
| 119 'idlDocument::fileName': self.file_name, | 119 'idlDocument::fileName': self.file_name, |
| 120 # Perl treats exceptions as a kind of interface | 120 # Perl treats exceptions as a kind of interface |
| 121 'idlDocument::interfaces': sorted(self.exceptions.values() + sel
f.interfaces.values()), | 121 'idlDocument::interfaces': sorted(self.exceptions.values() + sel
f.interfaces.values()), |
| 122 } | 122 } |
| 123 | 123 |
| 124 def to_json(self, debug=False): | 124 def to_json(self, debug=False): |
| 125 """Returns a JSON string representing the Definitions. | 125 """Returns a JSON string representing the Definitions. |
| 126 | 126 |
| 127 The JSON output should be identical with the output of the Perl parser, | 127 The JSON output should be identical with the output of the Perl parser, |
| 128 specifically the function serializeJSON in deprecated_idl_serializer.pm, | 128 specifically the function serializeJSON in idl_serializer.pm, |
| 129 which takes a Perl object created by deprecated_idl_parser.pm. | 129 which takes a Perl object created by idl_parser.pm. |
| 130 """ | 130 """ |
| 131 # Sort so order consistent, allowing comparison of output | 131 # Sort so order consistent, allowing comparison of output |
| 132 if debug: | 132 if debug: |
| 133 # indent turns on pretty-printing for legibility | 133 # indent turns on pretty-printing for legibility |
| 134 return json.dumps(self, cls=IdlEncoder, sort_keys=True, indent=4) | 134 return json.dumps(self, cls=IdlEncoder, sort_keys=True, indent=4) |
| 135 # Use compact separators so output identical to Perl | 135 # Use compact separators so output identical to Perl |
| 136 return json.dumps(self, cls=IdlEncoder, sort_keys=True, separators=(',',
':')) | 136 return json.dumps(self, cls=IdlEncoder, sort_keys=True, separators=(',',
':')) |
| 137 | 137 |
| 138 | 138 |
| 139 class IdlCallbackFunction(BaseIdl, TypedObject): | 139 class IdlCallbackFunction(BaseIdl, TypedObject): |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 443 | 443 |
| 444 | 444 |
| 445 # JSON export | 445 # JSON export |
| 446 | 446 |
| 447 | 447 |
| 448 class IdlEncoder(json.JSONEncoder): | 448 class IdlEncoder(json.JSONEncoder): |
| 449 def default(self, obj): | 449 def default(self, obj): |
| 450 if isinstance(obj, BaseIdl): | 450 if isinstance(obj, BaseIdl): |
| 451 return obj.json_serializable() | 451 return obj.json_serializable() |
| 452 return json.JSONEncoder.default(self, obj) | 452 return json.JSONEncoder.default(self, obj) |
| OLD | NEW |