1010from abc import ABCMeta , abstractmethod
1111from collections .abc import Iterator
1212from functools import lru_cache
13- from typing import cast , Any , Optional , Union
13+ from typing import Any , Optional , Union
1414
1515from elementpath .exceptions import ElementPathTypeError
1616from elementpath .protocols import XsdTypeProtocol , XsdAttributeProtocol , \
17- XsdElementProtocol , XsdSchemaProtocol , XsdAttributeGroupProtocol
18- from elementpath .namespaces import XSD_ANY_ATOMIC_TYPE
17+ XsdElementProtocol , XsdSchemaProtocol
1918from elementpath .datatypes import AtomicType
2019from elementpath .etree import is_etree_element
2120from elementpath .xpath_context import XPathSchemaContext
@@ -143,47 +142,21 @@ def get_type(self, qname: str) -> Optional[XsdTypeProtocol]:
143142 """
144143 return self ._schema .maps .types .get (qname )
145144
146- def get_attribute (self , qname : str , parent_type : Optional [XsdTypeProtocol ] = None ) \
147- -> Optional [XsdAttributeProtocol ]:
145+ def get_attribute (self , qname : str ) -> Optional [XsdAttributeProtocol ]:
148146 """
149147 Get the XSD global attribute from the schema's scope.
150148
151149 :param qname: the fully qualified name of the attribute to retrieve.
152- :param parent_type: an optional XSD type that represents the scope where matching \
153- the attribute name. If not provided, the scope is assumed to be the global scope.
154- :returns: an object that represents an XSD type or `None`.
155150 """
156- if parent_type is None :
157- return self ._schema .maps .attributes .get (qname )
158- elif hasattr (parent_type , 'attributes' ):
159- attributes = cast (XsdAttributeGroupProtocol , parent_type .attributes )
160- if qname in attributes :
161- return attributes [qname ]
162- elif None in attributes and attributes [None ].is_matching (qname ):
163- return self ._schema .maps .attributes [qname ]
164- return None
165-
166- def get_element (self , qname : str , parent_type : Optional [XsdTypeProtocol ] = None ) \
167- -> Optional [XsdElementProtocol ]:
151+ return self ._schema .maps .attributes .get (qname )
152+
153+ def get_element (self , qname : str ,) -> Optional [XsdElementProtocol ]:
168154 """
169155 Get the XSD global element from the schema's scope.
170156
171157 :param qname: the fully qualified name of the attribute to retrieve.
172- :param parent_type: an optional XSD type that represents the scope where matching \
173- the child element name. If `None` or not provided the scope is the schema.
174- :returns: an object that represents an XSD type or `None`.
175158 """
176- if parent_type is None :
177- return self ._schema .maps .elements .get (qname )
178- elif (content := parent_type .model_group ) is not None :
179- for xsd_element in content .iter_elements ():
180- if xsd_element .is_matching (qname ):
181- if xsd_element .name == qname :
182- return xsd_element
183- else :
184- # a wildcard or a substitute
185- return self ._schema .maps .elements .get (qname )
186- return None
159+ return self ._schema .maps .elements .get (qname )
187160
188161 def get_substitution_group (self , qname : str ) -> Optional [set [XsdElementProtocol ]]:
189162 """
@@ -195,63 +168,6 @@ def get_substitution_group(self, qname: str) -> Optional[set[XsdElementProtocol]
195168 """
196169 return self ._schema .maps .substitution_groups .get (qname )
197170
198- def get_attribute_type (self , name : str , parent_type : Optional [XsdTypeProtocol ] = None ) \
199- -> Optional [XsdTypeProtocol ]:
200- """
201- Get the XSD attribute type if the provided name is matching in the scope,
202- otherwise return None.
203-
204- :param name: the name of the attribute to retrieve.
205- :param parent_type: an optional XSD type that represents the scope where matching \
206- the attribute name. If not provided, the scope is assumed to be the global scope.
207- """
208- if parent_type is None :
209- try :
210- return self ._schema .maps .attributes [name ].type
211- except KeyError :
212- return None
213- elif hasattr (parent_type , 'attributes' ):
214- attributes = cast (XsdAttributeGroupProtocol , parent_type .attributes )
215- if name in attributes :
216- return attributes [name ].type
217- elif None in attributes and attributes [None ].is_matching (name ):
218- try :
219- return self ._schema .maps .attributes [name ].type
220- except KeyError :
221- return None
222- elif name .startswith ('{http://www.w3.org/2001/XMLSchema-instance}' ):
223- return self ._schema .maps .types .get (XSD_ANY_ATOMIC_TYPE )
224-
225- return None
226-
227- def get_child_type (self , name : str , parent_type : Optional [XsdTypeProtocol ] = None ) \
228- -> Optional [XsdTypeProtocol ]:
229- """
230- Get the child XSD type if the provided name is matching in the scope,
231- otherwise return None.
232-
233- :param name: the name of the child element to match.
234- :param parent_type: an optional XSD type that represents the scope where matching \
235- the child element name. If `None` or not provided the scope is the schema.
236- """
237- if parent_type is None :
238- try :
239- return self ._schema .maps .elements [name ].type
240- except KeyError :
241- return None
242- elif (content := parent_type .model_group ) is not None :
243- for xsd_element in content .iter_elements ():
244- if xsd_element .is_matching (name ):
245- if xsd_element .name == name :
246- return xsd_element .type
247- else :
248- # a wildcard or a substitute
249- try :
250- return self ._schema .maps .elements [name ].type
251- except KeyError :
252- return None
253- return None
254-
255171 @abstractmethod
256172 def is_instance (self , obj : Any , type_qname : str ) -> bool :
257173 """
0 commit comments