66import stix2
77from stix2 .datastore import DataSourceError
88from stix2 .datastore .relational_db .utils import (
9- canonicalize_table_name , schema_for , table_name_for ,
10- see_through_workbench ,
9+ canonicalize_table_name , see_through_workbench , table_name_for ,
1110)
1211import stix2 .properties
1312import stix2 .utils
@@ -50,13 +49,13 @@ def _tables_for(stix_class, metadata, db_backend):
5049 # Some fixed info about core tables
5150 if stix2 .utils .is_sco (stix_class ._type , stix2 .DEFAULT_VERSION ):
5251 canon_core_table_name = canonicalize_table_name (
53- "core_sco" , db_backend .schema_for_core ()
52+ "core_sco" , db_backend .schema_for_core (),
5453 )
5554
5655 else :
5756 # for SROs and SMOs too?
5857 canon_core_table_name = canonicalize_table_name (
59- "core_sdo" , db_backend .schema_for_core ()
58+ "core_sdo" , db_backend .schema_for_core (),
6059 )
6160
6261 core_table = metadata .tables [canon_core_table_name ]
@@ -160,13 +159,13 @@ def _read_external_references(stix_id, metadata, conn, db_backend):
160159 ext_refs_table = metadata .tables [
161160 canonicalize_table_name (
162161 "external_references" ,
163- db_backend .schema_for_core ()
162+ db_backend .schema_for_core (),
164163 )
165164 ]
166165 ext_refs_hashes_table = metadata .tables [
167166 canonicalize_table_name (
168167 "external_references_hashes" ,
169- db_backend .schema_for_core ()
168+ db_backend .schema_for_core (),
170169 )
171170 ]
172171 ext_refs = []
@@ -206,7 +205,7 @@ def _read_object_marking_refs(stix_id, common_table_kind, metadata, conn, db_bac
206205
207206 marking_table_name = canonicalize_table_name (
208207 "object_marking_refs_" + common_table_kind ,
209- db_backend .schema_for_core ()
208+ db_backend .schema_for_core (),
210209 )
211210
212211 # The SCO/SDO object_marking_refs tables are mostly identical; they just
@@ -237,7 +236,7 @@ def _read_granular_markings(stix_id, common_table_kind, metadata, conn, db_backe
237236
238237 marking_table_name = canonicalize_table_name (
239238 "granular_marking_" + common_table_kind ,
240- db_backend .schema_for_core ()
239+ db_backend .schema_for_core (),
241240 )
242241 marking_table = metadata .tables [marking_table_name ]
243242
@@ -310,7 +309,7 @@ def _read_dictionary_property(
310309 prop_instance ,
311310 metadata ,
312311 conn ,
313- db_backend
312+ db_backend ,
314313):
315314 """
316315 Read a dictionary from a table.
@@ -350,11 +349,11 @@ def _read_dictionary_property(
350349 list_table_name = f"{ dict_table_name } _values"
351350 list_table = metadata .tables [list_table_name ]
352351 stmt = sa .select (
353- dict_table .c .name , list_table .c .value
352+ dict_table .c .name , list_table .c .value ,
354353 ).select_from (dict_table ).join (
355- list_table , list_table .c .id == dict_table .c ["values" ]
354+ list_table , list_table .c .id == dict_table .c ["values" ],
356355 ).where (
357- dict_table .c .id == stix_id
356+ dict_table .c .id == stix_id ,
358357 )
359358
360359 results = conn .execute (stmt )
@@ -509,7 +508,7 @@ def _read_complex_property_value(
509508 obj_table ,
510509 metadata ,
511510 conn ,
512- db_backend
511+ db_backend ,
513512):
514513 """
515514 Read property values which require auxiliary tables to store. These are
@@ -605,7 +604,7 @@ def _read_complex_property_value(
605604 prop_instance ,
606605 metadata ,
607606 conn ,
608- db_backend
607+ db_backend ,
609608 )
610609
611610 elif isinstance (prop_instance , stix2 .properties .EmbeddedObjectProperty ):
@@ -663,7 +662,7 @@ def _read_complex_top_level_property_value(
663662 stix_id ,
664663 metadata ,
665664 conn ,
666- db_backend
665+ db_backend ,
667666 )
668667
669668 elif prop_name == "object_marking_refs" :
@@ -689,7 +688,7 @@ def _read_complex_top_level_property_value(
689688 label_table = metadata .tables [
690689 canonicalize_table_name (
691690 f"core_{ common_table_kind } _labels" ,
692- db_backend .schema_for_core ()
691+ db_backend .schema_for_core (),
693692 )
694693 ]
695694 prop_value = _read_simple_array (stix_id , "label" , label_table , conn )
@@ -703,7 +702,7 @@ def _read_complex_top_level_property_value(
703702 type_table ,
704703 metadata ,
705704 conn ,
706- db_backend
705+ db_backend ,
707706 )
708707
709708 return prop_value
@@ -761,7 +760,7 @@ def read_object(stix_id, metadata, conn, db_backend):
761760 stix_obj = stix2 .parse (
762761 obj_dict ,
763762 allow_custom = True ,
764- version = stix2 .DEFAULT_VERSION
763+ version = stix2 .DEFAULT_VERSION ,
765764 )
766765
767766 return stix_obj
0 commit comments