@@ -36,31 +36,13 @@ def build_schema(config: Config, schema_nodes):
3636 decl .add_type_definition (build_element (Typ , config , node = type_def ))
3737
3838 for enum_type in schema_node .xpath ('edm:EnumType' , namespaces = config .namespaces ):
39- try :
40- etype = build_element (EnumType , config , type_node = enum_type , namespace = namespace )
41- except (PyODataParserError , AttributeError ) as ex :
42- config .err_policy (ParserError .ENUM_TYPE ).resolve (ex )
43- etype = NullType (enum_type .get ('Name' ))
44-
45- decl .add_enum_type (etype )
39+ decl .add_enum_type (build_element (EnumType , config , type_node = enum_type , namespace = namespace ))
4640
4741 for complex_type in schema_node .xpath ('edm:ComplexType' , namespaces = config .namespaces ):
48- try :
49- ctype = build_element (ComplexType , config , type_node = complex_type , schema = schema )
50- except (KeyError , AttributeError ) as ex :
51- config .err_policy (ParserError .COMPLEX_TYPE ).resolve (ex )
52- ctype = NullType (complex_type .get ('Name' ))
53-
54- decl .add_complex_type (ctype )
42+ decl .add_complex_type (build_element (ComplexType , config , type_node = complex_type , schema = schema ))
5543
5644 for entity_type in schema_node .xpath ('edm:EntityType' , namespaces = config .namespaces ):
57- try :
58- etype = build_element (EntityType , config , type_node = entity_type , schema = schema )
59- except (KeyError , AttributeError ) as ex :
60- config .err_policy (ParserError .ENTITY_TYPE ).resolve (ex )
61- etype = NullType (entity_type .get ('Name' ))
62-
63- decl .add_entity_type (etype )
45+ decl .add_entity_type (build_element (EntityType , config , type_node = entity_type , schema = schema ))
6446
6547 # resolve types of properties
6648 for stype in itertools .chain (schema .entity_types , schema .complex_types ):
@@ -186,49 +168,53 @@ def build_type_definition(config: Config, node):
186168
187169# pylint: disable=protected-access, too-many-locals
188170def build_enum_type (config : Config , type_node , namespace ):
189- ename = type_node .get ('Name' )
190- is_flags = type_node .get ('IsFlags' )
171+ try :
172+ ename = type_node .get ('Name' )
173+ is_flags = type_node .get ('IsFlags' )
191174
192- # namespace = kwargs['namespace']
175+ # namespace = kwargs['namespace']
193176
194- underlying_type = type_node .get ('UnderlyingType' )
177+ underlying_type = type_node .get ('UnderlyingType' )
195178
196- # https://docs.oasis-open.org/odata/odata-csdl-json/v4.01/csprd04/odata-csdl-json-v4.01-csprd04.html#sec_EnumerationType
197- if underlying_type is None :
198- underlying_type = 'Edm.Int32'
179+ # https://docs.oasis-open.org/odata/odata-csdl-json/v4.01/csprd04/odata-csdl-json-v4.01-csprd04.html#sec_EnumerationType
180+ if underlying_type is None :
181+ underlying_type = 'Edm.Int32'
199182
200- valid_types = {
201- 'Edm.Byte' : [0 , 2 ** 8 - 1 ],
202- 'Edm.Int16' : [- 2 ** 15 , 2 ** 15 - 1 ],
203- 'Edm.Int32' : [- 2 ** 31 , 2 ** 31 - 1 ],
204- 'Edm.Int64' : [- 2 ** 63 , 2 ** 63 - 1 ],
205- 'Edm.SByte' : [- 2 ** 7 , 2 ** 7 - 1 ]
206- }
183+ valid_types = {
184+ 'Edm.Byte' : [0 , 2 ** 8 - 1 ],
185+ 'Edm.Int16' : [- 2 ** 15 , 2 ** 15 - 1 ],
186+ 'Edm.Int32' : [- 2 ** 31 , 2 ** 31 - 1 ],
187+ 'Edm.Int64' : [- 2 ** 63 , 2 ** 63 - 1 ],
188+ 'Edm.SByte' : [- 2 ** 7 , 2 ** 7 - 1 ]
189+ }
207190
208- if underlying_type not in valid_types :
209- raise PyODataParserError (
210- f'Type { underlying_type } is not valid as underlying type for EnumType - must be one of { valid_types } ' )
191+ if underlying_type not in valid_types :
192+ raise PyODataParserError (
193+ f'Type { underlying_type } is not valid as underlying type for EnumType - must be one of { valid_types } ' )
211194
212- mtype = Types .from_name (underlying_type , config )
213- etype = EnumType (ename , is_flags , mtype , namespace )
195+ mtype = Types .from_name (underlying_type , config )
196+ etype = EnumType (ename , is_flags , mtype , namespace )
214197
215- members = type_node .xpath ('edm:Member' , namespaces = config .namespaces )
198+ members = type_node .xpath ('edm:Member' , namespaces = config .namespaces )
216199
217- next_value = 0
218- for member in members :
219- name = member .get ('Name' )
220- value = member .get ('Value' )
200+ next_value = 0
201+ for member in members :
202+ name = member .get ('Name' )
203+ value = member .get ('Value' )
221204
222- if value is not None :
223- next_value = int (value )
205+ if value is not None :
206+ next_value = int (value )
224207
225- vtype = valid_types [underlying_type ]
226- if not vtype [0 ] < next_value < vtype [1 ]:
227- raise PyODataParserError (f'Value { next_value } is out of range for type { underlying_type } ' )
208+ vtype = valid_types [underlying_type ]
209+ if not vtype [0 ] < next_value < vtype [1 ]:
210+ raise PyODataParserError (f'Value { next_value } is out of range for type { underlying_type } ' )
228211
229- emember = EnumMember (etype , name , next_value )
230- etype ._member .append (emember )
212+ emember = EnumMember (etype , name , next_value )
213+ etype ._member .append (emember )
231214
232- next_value += 1
215+ next_value += 1
233216
234- return etype
217+ return etype
218+ except (PyODataParserError , AttributeError ) as ex :
219+ config .err_policy (ParserError .ENUM_TYPE ).resolve (ex )
220+ return NullType (type_node .get ('Name' ))
0 commit comments