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 """Utilies for the processing of schema python structures. | 4 """Utilies for the processing of schema python structures. |
5 """ | 5 """ |
6 | 6 |
| 7 def GetNamespace(ref_type): |
| 8 if '.' in ref_type: |
| 9 return ref_type[:ref_type.rindex('.')] |
| 10 |
7 def StripSchemaNamespace(s): | 11 def StripSchemaNamespace(s): |
8 last_dot = s.rfind('.') | 12 last_dot = s.rfind('.') |
9 if not last_dot == -1: | 13 if not last_dot == -1: |
10 return s[last_dot + 1:] | 14 return s[last_dot + 1:] |
11 return s | 15 return s |
12 | 16 |
13 def PrefixSchemasWithNamespace(schemas): | 17 def PrefixSchemasWithNamespace(schemas): |
14 for s in schemas: | 18 for s in schemas: |
15 _PrefixWithNamespace(s.get("namespace"), s) | 19 _PrefixWithNamespace(s.get("namespace"), s) |
16 | 20 |
(...skipping 11 matching lines...) Expand all Loading... |
28 def _PrefixWithNamespace(namespace, schema): | 32 def _PrefixWithNamespace(namespace, schema): |
29 if type(schema) == dict: | 33 if type(schema) == dict: |
30 if "types" in schema: | 34 if "types" in schema: |
31 _PrefixTypesWithNamespace(namespace, schema.get("types")) | 35 _PrefixTypesWithNamespace(namespace, schema.get("types")) |
32 _MaybePrefixFieldWithNamespace(namespace, schema, "$ref") | 36 _MaybePrefixFieldWithNamespace(namespace, schema, "$ref") |
33 for s in schema: | 37 for s in schema: |
34 _PrefixWithNamespace(namespace, schema[s]) | 38 _PrefixWithNamespace(namespace, schema[s]) |
35 elif type(schema) == list: | 39 elif type(schema) == list: |
36 for s in schema: | 40 for s in schema: |
37 _PrefixWithNamespace(namespace, s) | 41 _PrefixWithNamespace(namespace, s) |
OLD | NEW |