Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@xml._keepstate
def get_tag_attributes(source, tag_name):
'''Iteratively parse XML stream in ``source`` until encountering ``tag_name``
at which point parsing terminates and return the attributes of the matched
tag.
Parameters
----------
source: file-like
A file-like object over an XML document
tag_name: str
The name of the XML tag to parse until
Returns
-------
dict
'''
@xml._keepstate
def _find_section(source, section):
value = next(source.iterfind(section))
return value
@xml._keepstate
def iterparse_until(source, target_name, quit_name):
'''Iteratively parse XML stream in ``source``, yielding XML elements
matching ``target_name``. If at any point a tag matching ``quit_name``
is encountered, stop parsing.
Parameters
----------
source: file-like
A file-like object over an XML document
tag_name: str
The name of the XML tag to parse until
quit_name: str
The name to stop parsing at.
Yields
------