22import logging
33from .attribute_mapper import Attribute_Mapper
44
5+
56class Attribute_Inserter ():
67
78 def __init__ (self , schema_skeleton : dict , key_list : list , map : object ) -> None :
@@ -35,9 +36,9 @@ def fill_json_object(self, json_object: dict, key_list: list, attributes_object:
3536 for key in key_list :
3637 if (isinstance (json_object [key ], str )) or (isinstance (json_object [key ], tuple )):
3738 if key in attributes_object .keys ():
38- new_dict [key ] = self .get_json_type (json_object [key ], attributes_object [key ])
39+ new_dict [key ] = self .get_json_type (json_object [key ], attributes_object [key ], key )
3940 else :
40- new_dict [key ] = self .get_json_type (json_object [key ], json_object [key ])
41+ new_dict [key ] = self .get_json_type (json_object [key ], json_object [key ], key )
4142 elif isinstance (json_object [key ], dict ):
4243 if key in attributes_object :
4344 if isinstance (attributes_object [key ], Attribute_Mapper ):
@@ -75,7 +76,7 @@ def fill_json_array(self, json_object: dict, json_object_property: str, json_arr
7576 Returns:
7677 list: The list that represents the filled json array.
7778 """
78- if isinstance (attributes , list ) == False :
79+ if not isinstance (attributes , list ):
7980 if json_object_property in attributes .__dict__ .keys ():
8081 attributes = attributes .__dict__ [json_object_property ]
8182 try :
@@ -89,7 +90,7 @@ def fill_json_array(self, json_object: dict, json_object_property: str, json_arr
8990 for list_item , list_index in zip (json_array , range (0 , len (json_array ))):
9091 if (isinstance (list_item , str )) or (isinstance (list_item , tuple )):
9192 try :
92- new_list .append (self .get_json_type (list_item , attributes [list_index ]))
93+ new_list .append (self .get_json_type (list_item , attributes [list_index ], None ))
9394 except TypeError as e :
9495 logging .warning (e )
9596 pass
@@ -106,7 +107,7 @@ def fill_json_array(self, json_object: dict, json_object_property: str, json_arr
106107 pass
107108 return new_list
108109
109- def get_json_type (self , data_type : str , attribute : str ) -> Any :
110+ def get_json_type (self , data_type : str , attribute : str , key ) -> Any :
110111 """Takes an attribute and its data type. Confirms the primitive data types of the mapped attribute values and assigns these values to the schema attribute. The correct hirarchial
111112 position has been reached through the methods above.
112113
@@ -118,19 +119,19 @@ def get_json_type(self, data_type: str, attribute: str) -> Any:
118119 Any: The value of the mapped attribute as the correct data type.
119120 """
120121 try :
121- if (isinstance (data_type , tuple ) and (isinstance (attribute , tuple )== False )):
122+ if (isinstance (data_type , tuple ) and not (isinstance (attribute , tuple ))):
122123 if (isinstance (attribute , list )) and ("<class 'list'>" in data_type ):
123124 return attribute
124125 else :
125126 for element in data_type :
126127 if element in ["<class 'int'>" , "<class 'bool'>" , "<class 'None'>" , "<class 'float'>" , "<class 'list'>" ]:
127- return (self .get_json_type (element , attribute ))
128+ return (self .get_json_type (element , attribute , None ))
128129 else :
129130 pass
130- logging .warning (f'incorrect type provided for { attribute } , expected { data_type } but received { type (attribute )} , returning original value.' )
131+ logging .warning (f'incorrect type provided for property \" { key } \" , expected { data_type } but received { type (attribute )} , returning original value.' )
131132 return attribute
132133 elif isinstance (attribute , tuple ):
133- logging .warning (f'No value provided for { attribute } , returning original value.' )
134+ logging .warning (f'No value provided for property \" { key } \" , returning original value.' )
134135 return attribute
135136 elif data_type == "<class 'int'>" :
136137 return int (attribute )
@@ -143,11 +144,11 @@ def get_json_type(self, data_type: str, attribute: str) -> Any:
143144 elif data_type == "<class 'str'>" :
144145 return str (attribute )
145146 else :
146- logging .warning (f'incorrect type provided for { attribute } , expected { data_type } but received { type (attribute )} , returning original value.' )
147+ logging .warning (f'incorrect type provided for property \" { key } \" , expected { data_type } but received { type (attribute )} , returning original value.' )
147148 return attribute
148- except TypeError as e :
149- logging .warning (f'incorrect type provided for { attribute } , expected { data_type } but received { type (attribute )} , returning original value.' )
149+ except TypeError :
150+ logging .warning (f'incorrect type provided for property \" { key } \" , expected { data_type } but received { type (attribute )} , returning original value.' )
150151 return attribute
151- except ValueError as e :
152- logging .warning (f'incorrect value provided for { attribute } , expected { data_type } but received { type (attribute )} , returning original value.' )
152+ except ValueError :
153+ logging .warning (f'incorrect value provided for property \" { key } \" , expected { data_type } but received { type (attribute )} , returning original value.' )
153154 return attribute
0 commit comments