Check for usage of undefined variables
1 | # Copyright 2019 Extreme Networks, Inc. |
||
2 | # |
||
3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
||
4 | # you may not use this file except in compliance with the License. |
||
5 | # You may obtain a copy of the License at |
||
6 | # |
||
7 | # http://www.apache.org/licenses/LICENSE-2.0 |
||
8 | # |
||
9 | # Unless required by applicable law or agreed to in writing, software |
||
10 | # distributed under the License is distributed on an "AS IS" BASIS, |
||
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||
12 | # See the License for the specific language governing permissions and |
||
13 | # limitations under the License. |
||
14 | # |
||
15 | import sys |
||
16 | |||
17 | |||
18 | TYPE_TABLE = { |
||
19 | dict: 'object', |
||
20 | list: 'array', |
||
21 | int: 'integer', |
||
22 | str: 'string', |
||
23 | float: 'number', |
||
24 | bool: 'boolean', |
||
25 | type(None): 'null', |
||
26 | } |
||
27 | |||
28 | if sys.version_info[0] < 3: |
||
29 | TYPE_TABLE[unicode] = 'string' |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
Loading history...
|
|||
30 | |||
31 | |||
32 | def _dict_to_schema(item): |
||
33 | schema = {} |
||
34 | for key, value in item.iteritems(): |
||
35 | if isinstance(value, dict): |
||
36 | schema[key] = { |
||
37 | 'type': 'object', |
||
38 | 'parameters': _dict_to_schema(value) |
||
39 | } |
||
40 | else: |
||
41 | schema[key] = { |
||
42 | 'type': TYPE_TABLE[type(value)] |
||
43 | } |
||
44 | |||
45 | return schema |
||
46 | |||
47 | |||
48 | def render_output_schema_from_output(output): |
||
49 | """Given an action output produce a reasonable schema to match. |
||
50 | """ |
||
51 | return _dict_to_schema(output) |
||
52 |