1010SCW_DIR = 'remediation_training'
1111THIRD_PARTY_MAPPING_DIR = 'third-party-mappings'
1212
13+
1314def get_json (filename ):
1415 with open (filename ) as f :
1516 return json .loads (f .read ())
1617
18+
1719def all_versions (filename ):
1820 """
19- Find, open and parse all tagged versions of a json file, including the current version
21+ Find, open and parse all tagged versions of a json file,
22+ including the current version
2023
2124 :param filename: The filename to find
2225 :return: a dictionary of all the versions, in the form
@@ -41,10 +44,12 @@ def id_valid(vrt, id_list):
4144 Check if a vrt id is valid
4245
4346 :param vrt: The vrt object
44- :param id_list: The vrt id, split into components, eg ['category', 'subcategory', 'variant']
47+ :param id_list: The vrt id, split into components,
48+ eg ['category', 'subcategory', 'variant']
4549 :return: True/False
4650 """
47- # this is not particularly efficient, but it's more readable than other options so until we need to care...
51+ # this is not particularly efficient, but it's more readable than other
52+ # options so until we need to care...
4853 return id_list in all_id_lists (vrt )
4954
5055
@@ -53,7 +58,8 @@ def has_mapping(mapping, id_list, key):
5358 Check if a vrt id has a mapping
5459
5560 :param mapping: The mapping object, keyed by id
56- :param id_list: The vrt id, split into components, eg ['category', 'subcategory', 'variant']
61+ :param id_list: The vrt id, split into components,
62+ eg ['category', 'subcategory', 'variant']
5763 :param key: The mapping key to look for, eg 'cvss_v3'
5864 :return: True/False
5965 """
@@ -72,9 +78,16 @@ def key_by_id(mapping):
7278 Converts arrays to hashes keyed by the id attribute for easier lookup. So
7379 [{'id': 'one', 'foo': 'bar'}, {'id': 'two', 'foo': 'baz'}]
7480 becomes
75- {'one': {'id': 'one', 'foo': 'bar'}, 'two': {'id': 'two', 'foo': 'baz'}}
81+ {
82+ 'one': {'id': 'one', 'foo': 'bar'},
83+ 'two': {'id': 'two', 'foo': 'baz'}
84+ }
7685 """
77- if isinstance (mapping , list ) and isinstance (mapping [0 ], dict ) and 'id' in mapping [0 ]:
86+ if isinstance (
87+ mapping , list
88+ ) and isinstance (
89+ mapping [0 ], dict
90+ ) and 'id' in mapping [0 ]:
7891 return {x ['id' ]: key_by_id (x ) for x in mapping }
7992 elif isinstance (mapping , dict ):
8093 return {k : key_by_id (v ) for k , v in mapping .items ()}
@@ -84,10 +97,12 @@ def key_by_id(mapping):
8497
8598def all_id_lists (vrt , include_internal = True ):
8699 """
87- Get all valid vrt ids for a given vrt object, including internal nodes by default
100+ Get all valid vrt ids for a given vrt object, including internal nodes
101+ by default
88102
89103 :param vrt: The vrt object
90- :param include_internal: Whether to include internal nodes or only leaf nodes
104+ :param include_internal: Whether to include internal nodes or only
105+ leaf nodes
91106 :return: ids in the form
92107 [
93108 ['category'],
@@ -98,7 +113,10 @@ def all_id_lists(vrt, include_internal=True):
98113 """
99114 def _all_id_lists (sub_vrt , prefix ):
100115 if isinstance (sub_vrt , list ):
101- return [vrt_id for entry in sub_vrt for vrt_id in _all_id_lists (entry , prefix )]
116+ return [
117+ vrt_id for entry in sub_vrt
118+ for vrt_id in _all_id_lists (entry , prefix )
119+ ]
102120 elif isinstance (sub_vrt , dict ):
103121 if 'children' in sub_vrt :
104122 new_prefix = prefix + [sub_vrt ['id' ]]
0 commit comments