OLD | NEW |
| (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 """Utilies for the processing of schema python structures. | |
5 """ | |
6 | |
7 def StripSchemaNamespace(s): | |
8 last_dot = s.rfind('.') | |
9 if not last_dot == -1: | |
10 return s[last_dot + 1:] | |
11 return s | |
12 | |
13 def PrefixSchemasWithNamespace(schemas): | |
14 for s in schemas: | |
15 _PrefixWithNamespace(s.get("namespace"), s) | |
16 | |
17 def _MaybePrefixFieldWithNamespace(namespace, schema, key): | |
18 if type(schema) == dict and key in schema: | |
19 old_value = schema[key] | |
20 if not "." in old_value: | |
21 schema[key] = namespace + "." + old_value | |
22 | |
23 def _PrefixTypesWithNamespace(namespace, types): | |
24 for t in types: | |
25 _MaybePrefixFieldWithNamespace(namespace, t, "id") | |
26 _MaybePrefixFieldWithNamespace(namespace, t, "customBindings") | |
27 | |
28 def _PrefixWithNamespace(namespace, schema): | |
29 if type(schema) == dict: | |
30 if "types" in schema: | |
31 _PrefixTypesWithNamespace(namespace, schema.get("types")) | |
32 _MaybePrefixFieldWithNamespace(namespace, schema, "$ref") | |
33 for s in schema: | |
34 _PrefixWithNamespace(namespace, schema[s]) | |
35 elif type(schema) == list: | |
36 for s in schema: | |
37 _PrefixWithNamespace(namespace, s) | |
OLD | NEW |