neulab/docprompting-conala huggingface dataset:
write(file, encoding="us-ascii", xml_declaration=None, default_namespace=None, method="xml", *, short_empty_elements=True)  
Writes the element tree to a file, as XML. file is a file name, or a file object opened for writing. encoding 1 is the output encoding (default is US-ASCII). xml_declaration controls if an XML declaration should be added to the file. Use False for never, True for always, None for only if not US-ASCII or UTF-8 or Unicode (default is None). default_namespace sets the default XML namespace (for “xmlns”). method is either "xml", "html" or "text" (default is "xml"). The keyword-only short_empty_elements parameter controls the formatting of elements that contain no content. If True (the default), they are emitted as a single self-closed tag, otherwise they are emitted as a pair of start/end tags. The output is either a string (str) or binary (bytes). This is controlled by the encoding argument. If encoding is "unicode", the output is a string; otherwise, it’s binary. Note that this may conflict with the type of file if it’s an open file object; make sure you do not try to write a string to a binary stream and vice versa.  New in version 3.4: The short_empty_elements parameter.   Changed in version 3.8: The write() method now preserves the attribute order specified by the user.
_setroot(element)  
Replaces the root element for this tree. This discards the current contents of the tree, and replaces it with the given element. Use with care. element is an element instance.
xml.etree.ElementTree.fromstring(text, parser=None)  
Parses an XML section from a string constant. Same as XML(). text is a string containing XML data. parser is an optional parser instance. If not given, the standard XMLParser parser is used. Returns an Element instance.
xml.etree.ElementTree.fromstringlist(sequence, parser=None)  
Parses an XML document from a sequence of string fragments. sequence is a list or other sequence containing XML data fragments. parser is an optional parser instance. If not given, the standard XMLParser parser is used. Returns an Element instance.  New in version 3.2.
xml.etree.ElementTree.indent(tree, space=" ", level=0)  
Appends whitespace to the subtree to indent the tree visually. This can be used to generate pretty-printed XML output. tree can be an Element or ElementTree. space is the whitespace string that will be inserted for each indentation level, two space characters by default. For indenting partial subtrees inside of an already indented tree, pass the initial indentation level as level.  New in version 3.9.
xml.etree.ElementTree.iselement(element)  
Check if an object appears to be a valid element object. element is an element instance. Return True if this is an element object.
xml.etree.ElementTree.iterparse(source, events=None, parser=None)  
Parses an XML section into an element tree incrementally, and reports what’s going on to the user. source is a filename or file object containing XML data. events is a sequence of events to report back. The supported events are the strings "start", "end", "comment", "pi", "start-ns" and "end-ns" (the “ns” events are used to get detailed namespace information). If events is omitted, only "end" events are reported. parser is an optional parser instance. If not given, the standard XMLParser parser is used. parser must be a subclass of XMLParser and can only use the default TreeBuilder as a target. Returns an iterator providing (event, elem) pairs. Note that while iterparse() builds the tree incrementally, it issues blocking reads on source (or the file it names). As such, it’s unsuitable for applications where blocking reads can’t be made. For fully non-blocking parsing, see XMLPullParser.  Note iterparse() only guarantees that it has seen the “>” character of a starting tag when it emits a “start” event, so the attributes are defined, but the contents of the text and tail attributes are undefined at that point. The same applies to the element children; they may or may not be present. If you need a fully populated element, look for “end” events instead.   Deprecated since version 3.4: The parser argument.   Changed in version 3.8: The comment and pi events were added.
xml.etree.ElementTree.parse(source, parser=None)  
Parses an XML section into an element tree. source is a filename or file object containing XML data. parser is an optional parser instance. If not given, the standard XMLParser parser is used. Returns an ElementTree instance.
class xml.etree.ElementTree.ParseError  
XML parse error, raised by the various parsing methods in this module when parsing fails. The string representation of an instance of this exception will contain a user-friendly error message. In addition, it will have the following attributes available:  
code  
A numeric error code from the expat parser. See the documentation of xml.parsers.expat for the list of error codes and their meanings. 
  
position  
A tuple of line, column numbers, specifying where the error occurred.
code  
A numeric error code from the expat parser. See the documentation of xml.parsers.expat for the list of error codes and their meanings.
xml.etree.ElementTree.ProcessingInstruction(target, text=None)  
PI element factory. This factory function creates a special element that will be serialized as an XML processing instruction. target is a string containing the PI target. text is a string containing the PI contents, if given. Returns an element instance, representing a processing instruction. Note that XMLParser skips over processing instructions in the input instead of creating comment objects for them. An ElementTree will only contain processing instruction nodes if they have been inserted into to the tree using one of the Element methods.
class xml.etree.ElementTree.QName(text_or_uri, tag=None)  
QName wrapper. This can be used to wrap a QName attribute value, in order to get proper namespace handling on output. text_or_uri is a string containing the QName value, in the form {uri}local, or, if the tag argument is given, the URI part of a QName. If tag is given, the first argument is interpreted as a URI, and this argument is interpreted as a local name. QName instances are opaque.
xml.etree.ElementTree.register_namespace(prefix, uri)  
Registers a namespace prefix. The registry is global, and any existing mapping for either the given prefix or the namespace URI will be removed. prefix is a namespace prefix. uri is a namespace uri. Tags and attributes in this namespace will be serialized with the given prefix, if at all possible.  New in version 3.2.
xml.etree.ElementTree.SubElement(parent, tag, attrib={}, **extra)  
Subelement factory. This function creates an element instance, and appends it to an existing element. The element name, attribute names, and attribute values can be either bytestrings or Unicode strings. parent is the parent element. tag is the subelement name. attrib is an optional dictionary, containing element attributes. extra contains additional attributes, given as keyword arguments. Returns an element instance.
xml.etree.ElementTree.tostring(element, encoding="us-ascii", method="xml", *, xml_declaration=None, default_namespace=None, short_empty_elements=True)  
Generates a string representation of an XML element, including all subelements. element is an Element instance. encoding 1 is the output encoding (default is US-ASCII). Use encoding="unicode" to generate a Unicode string (otherwise, a bytestring is generated). method is either "xml", "html" or "text" (default is "xml"). xml_declaration, default_namespace and short_empty_elements has the same meaning as in ElementTree.write(). Returns an (optionally) encoded string containing the XML data.  New in version 3.4: The short_empty_elements parameter.   New in version 3.8: The xml_declaration and default_namespace parameters.   Changed in version 3.8: The tostring() function now preserves the attribute order specified by the user.
xml.etree.ElementTree.tostringlist(element, encoding="us-ascii", method="xml", *, xml_declaration=None, default_namespace=None, short_empty_elements=True)  
Generates a string representation of an XML element, including all subelements. element is an Element instance. encoding 1 is the output encoding (default is US-ASCII). Use encoding="unicode" to generate a Unicode string (otherwise, a bytestring is generated). method is either "xml", "html" or "text" (default is "xml"). xml_declaration, default_namespace and short_empty_elements has the same meaning as in ElementTree.write(). Returns a list of (optionally) encoded strings containing the XML data. It does not guarantee any specific sequence, except that b"".join(tostringlist(element)) == tostring(element).  New in version 3.2.   New in version 3.4: The short_empty_elements parameter.   New in version 3.8: The xml_declaration and default_namespace parameters.   Changed in version 3.8: The tostringlist() function now preserves the attribute order specified by the user.
class xml.etree.ElementTree.TreeBuilder(element_factory=None, *, comment_factory=None, pi_factory=None, insert_comments=False, insert_pis=False)  
Generic element structure builder. This builder converts a sequence of start, data, end, comment and pi method calls to a well-formed element structure. You can use this class to build an element structure using a custom XML parser, or a parser for some other XML-like format. element_factory, when given, must be a callable accepting two positional arguments: a tag and a dict of attributes. It is expected to return a new element instance. The comment_factory and pi_factory functions, when given, should behave like the Comment() and ProcessingInstruction() functions to create comments and processing instructions. When not given, the default factories will be used. When insert_comments and/or insert_pis is true, comments/pis will be inserted into the tree if they appear within the root element (but not outside of it).  
close()  
Flushes the builder buffers, and returns the toplevel document element. Returns an Element instance. 
  
data(data)  
Adds text to the current element. data is a string. This should be either a bytestring, or a Unicode string. 
  
end(tag)  
Closes the current element. tag is the element name. Returns the closed element. 
  
start(tag, attrs)  
Opens a new element. tag is the element name. attrs is a dictionary containing element attributes. Returns the opened element. 
  
comment(text)  
Creates a comment with the given text. If insert_comments is true, this will also add it to the tree.  New in version 3.8.  
  
pi(target, text)  
Creates a comment with the given target name and text. If insert_pis is true, this will also add it to the tree.  New in version 3.8.  
 In addition, a custom TreeBuilder object can provide the following methods:  
doctype(name, pubid, system)  
Handles a doctype declaration. name is the doctype name. pubid is the public identifier. system is the system identifier. This method does not exist on the default TreeBuilder class.  New in version 3.2.  
  
start_ns(prefix, uri)  
Is called whenever the parser encounters a new namespace declaration, before the start() callback for the opening element that defines it. prefix is '' for the default namespace and the declared namespace prefix name otherwise. uri is the namespace URI.  New in version 3.8.  
  
end_ns(prefix)  
Is called after the end() callback of an element that declared a namespace prefix mapping, with the name of the prefix that went out of scope.  New in version 3.8.
close()  
Flushes the builder buffers, and returns the toplevel document element. Returns an Element instance.
comment(text)  
Creates a comment with the given text. If insert_comments is true, this will also add it to the tree.  New in version 3.8.
data(data)  
Adds text to the current element. data is a string. This should be either a bytestring, or a Unicode string.
doctype(name, pubid, system)  
Handles a doctype declaration. name is the doctype name. pubid is the public identifier. system is the system identifier. This method does not exist on the default TreeBuilder class.  New in version 3.2.
end(tag)  
Closes the current element. tag is the element name. Returns the closed element.
end_ns(prefix)  
Is called after the end() callback of an element that declared a namespace prefix mapping, with the name of the prefix that went out of scope.  New in version 3.8.
pi(target, text)  
Creates a comment with the given target name and text. If insert_pis is true, this will also add it to the tree.  New in version 3.8.
start(tag, attrs)  
Opens a new element. tag is the element name. attrs is a dictionary containing element attributes. Returns the opened element.
start_ns(prefix, uri)  
Is called whenever the parser encounters a new namespace declaration, before the start() callback for the opening element that defines it. prefix is '' for the default namespace and the declared namespace prefix name otherwise. uri is the namespace URI.  New in version 3.8.
xml.etree.ElementTree.XML(text, parser=None)  
Parses an XML section from a string constant. This function can be used to embed “XML literals” in Python code. text is a string containing XML data. parser is an optional parser instance. If not given, the standard XMLParser parser is used. Returns an Element instance.
xml.etree.ElementInclude.default_loader(href, parse, encoding=None)  
Default loader. This default loader reads an included resource from disk. href is a URL. parse is for parse mode either “xml” or “text”. encoding is an optional text encoding. If not given, encoding is utf-8. Returns the expanded resource. If the parse mode is "xml", this is an ElementTree instance. If the parse mode is “text”, this is a Unicode string. If the loader fails, it can return None or raise an exception.
xml.etree.ElementInclude.include(elem, loader=None, base_url=None, max_depth=6)  
This function expands XInclude directives. elem is the root element. loader is an optional resource loader. If omitted, it defaults to default_loader(). If given, it should be a callable that implements the same interface as default_loader(). base_url is base URL of the original file, to resolve relative include file references. max_depth is the maximum number of recursive inclusions. Limited to reduce the risk of malicious content explosion. Pass a negative value to disable the limitation. Returns the expanded resource. If the parse mode is "xml", this is an ElementTree instance. If the parse mode is “text”, this is a Unicode string. If the loader fails, it can return None or raise an exception.  New in version 3.9: The base_url and max_depth parameters.
xml.etree.ElementTree.XMLID(text, parser=None)  
Parses an XML section from a string constant, and also returns a dictionary which maps from element id:s to elements. text is a string containing XML data. parser is an optional parser instance. If not given, the standard XMLParser parser is used. Returns a tuple containing an Element instance and a dictionary.
class xml.etree.ElementTree.XMLParser(*, target=None, encoding=None)  
This class is the low-level building block of the module. It uses xml.parsers.expat for efficient, event-based parsing of XML. It can be fed XML data incrementally with the feed() method, and parsing events are translated to a push API - by invoking callbacks on the target object. If target is omitted, the standard TreeBuilder is used. If encoding 1 is given, the value overrides the encoding specified in the XML file.  Changed in version 3.8: Parameters are now keyword-only. The html argument no longer supported.   
close()  
Finishes feeding data to the parser. Returns the result of calling the close() method of the target passed during construction; by default, this is the toplevel document element. 
  
feed(data)  
Feeds data to the parser. data is encoded data. 
 XMLParser.feed() calls target’s start(tag, attrs_dict) method for each opening tag, its end(tag) method for each closing tag, and data is processed by method data(data). For further supported callback methods, see the TreeBuilder class. XMLParser.close() calls target’s method close(). XMLParser can be used not only for building a tree structure. This is an example of counting the maximum depth of an XML file: >>> from xml.etree.ElementTree import XMLParser
>>> class MaxDepth:                     # The target object of the parser
...     maxDepth = 0
...     depth = 0
...     def start(self, tag, attrib):   # Called for each opening tag.
...         self.depth += 1
...         if self.depth > self.maxDepth:
...             self.maxDepth = self.depth
...     def end(self, tag):             # Called for each closing tag.
...         self.depth -= 1
...     def data(self, data):
...         pass            # We do not need to do anything with data.
...     def close(self):    # Called when all data has been parsed.
...         return self.maxDepth
...
>>> target = MaxDepth()
>>> parser = XMLParser(target=target)
>>> exampleXml = """
... <a>
...   <b>
...   </b>
...   <b>
...     <c>
...       <d>
...       </d>
...     </c>
...   </b>
... </a>"""
>>> parser.feed(exampleXml)
>>> parser.close()
4
close()  
Finishes feeding data to the parser. Returns the result of calling the close() method of the target passed during construction; by default, this is the toplevel document element.
class xml.etree.ElementTree.XMLPullParser(events=None)  
A pull parser suitable for non-blocking applications. Its input-side API is similar to that of XMLParser, but instead of pushing calls to a callback target, XMLPullParser collects an internal list of parsing events and lets the user read from it. events is a sequence of events to report back. The supported events are the strings "start", "end", "comment", "pi", "start-ns" and "end-ns" (the “ns” events are used to get detailed namespace information). If events is omitted, only "end" events are reported.  
feed(data)  
Feed the given bytes data to the parser. 
  
close()  
Signal the parser that the data stream is terminated. Unlike XMLParser.close(), this method always returns None. Any events not yet retrieved when the parser is closed can still be read with read_events(). 
  
read_events()  
Return an iterator over the events which have been encountered in the data fed to the parser. The iterator yields (event, elem) pairs, where event is a string representing the type of event (e.g. "end") and elem is the encountered Element object, or other context value as follows.  
start, end: the current Element. 
comment, pi: the current comment / processing instruction 
start-ns: a tuple (prefix, uri) naming the declared namespace mapping. 
end-ns: None (this may change in a future version)  Events provided in a previous call to read_events() will not be yielded again. Events are consumed from the internal queue only when they are retrieved from the iterator, so multiple readers iterating in parallel over iterators obtained from read_events() will have unpredictable results. 
  Note XMLPullParser only guarantees that it has seen the “>” character of a starting tag when it emits a “start” event, so the attributes are defined, but the contents of the text and tail attributes are undefined at that point. The same applies to the element children; they may or may not be present. If you need a fully populated element, look for “end” events instead.   New in version 3.4.   Changed in version 3.8: The comment and pi events were added.
close()  
Signal the parser that the data stream is terminated. Unlike XMLParser.close(), this method always returns None. Any events not yet retrieved when the parser is closed can still be read with read_events().
read_events()  
Return an iterator over the events which have been encountered in the data fed to the parser. The iterator yields (event, elem) pairs, where event is a string representing the type of event (e.g. "end") and elem is the encountered Element object, or other context value as follows.  
start, end: the current Element. 
comment, pi: the current comment / processing instruction 
start-ns: a tuple (prefix, uri) naming the declared namespace mapping. 
end-ns: None (this may change in a future version)  Events provided in a previous call to read_events() will not be yielded again. Events are consumed from the internal queue only when they are retrieved from the iterator, so multiple readers iterating in parallel over iterators obtained from read_events() will have unpredictable results.
xml.parsers.expat.errors.codes  
A dictionary mapping string descriptions to their error codes.  New in version 3.2.
xml.parsers.expat.errors.messages  
A dictionary mapping numeric error codes to their string descriptions.  New in version 3.2.
xml.parsers.expat.errors.XML_ERROR_ABORTED  
This should not be reported to Python applications.
xml.parsers.expat.errors.XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF  
An entity reference in an attribute value referred to an external entity instead of an internal entity.
xml.parsers.expat.errors.XML_ERROR_BAD_CHAR_REF  
A character reference referred to a character which is illegal in XML (for example, character 0, or ‘&#0;’).
xml.parsers.expat.errors.XML_ERROR_BINARY_ENTITY_REF  
An entity reference referred to an entity which was declared with a notation, so cannot be parsed.
xml.parsers.expat.errors.XML_ERROR_CANT_CHANGE_FEATURE_ONCE_PARSING  
A behavioral change was requested after parsing started that can only be changed before parsing has started. This is (currently) only raised by UseForeignDTD().
xml.parsers.expat.errors.XML_ERROR_DUPLICATE_ATTRIBUTE  
An attribute was used more than once in a start tag.
xml.parsers.expat.errors.XML_ERROR_ENTITY_DECLARED_IN_PE
xml.parsers.expat.errors.XML_ERROR_EXTERNAL_ENTITY_HANDLING
xml.parsers.expat.errors.XML_ERROR_FEATURE_REQUIRES_XML_DTD  
An operation was requested that requires DTD support to be compiled in, but Expat was configured without DTD support. This should never be reported by a standard build of the xml.parsers.expat module.
xml.parsers.expat.errors.XML_ERROR_FINISHED  
The requested operation was made on a parser which was finished parsing input, but isn’t allowed. This includes attempts to provide additional input or to stop the parser.
xml.parsers.expat.errors.XML_ERROR_INCOMPLETE_PE  
A parameter entity contained incomplete markup.
xml.parsers.expat.errors.XML_ERROR_INVALID_TOKEN  
Raised when an input byte could not properly be assigned to a character; for example, a NUL byte (value 0) in a UTF-8 input stream.
xml.parsers.expat.errors.XML_ERROR_JUNK_AFTER_DOC_ELEMENT  
Something other than whitespace occurred after the document element.
xml.parsers.expat.errors.XML_ERROR_MISPLACED_XML_PI  
An XML declaration was found somewhere other than the start of the input data.
xml.parsers.expat.errors.XML_ERROR_NOT_STANDALONE  
The parser determined that the document was not “standalone” though it declared itself to be in the XML declaration, and the NotStandaloneHandler was set and returned 0.
xml.parsers.expat.errors.XML_ERROR_NOT_SUSPENDED  
An attempt to resume the parser was made when the parser had not been suspended.
xml.parsers.expat.errors.XML_ERROR_NO_ELEMENTS  
The document contains no elements (XML requires all documents to contain exactly one top-level element)..
xml.parsers.expat.errors.XML_ERROR_NO_MEMORY  
Expat was not able to allocate memory internally.
xml.parsers.expat.errors.XML_ERROR_PARAM_ENTITY_REF  
A parameter entity reference was found where it was not allowed.
xml.parsers.expat.errors.XML_ERROR_PARTIAL_CHAR  
An incomplete character was found in the input.
xml.parsers.expat.errors.XML_ERROR_PUBLICID  
Characters were found in the public id that are not allowed.
xml.parsers.expat.errors.XML_ERROR_RECURSIVE_ENTITY_REF  
An entity reference contained another reference to the same entity; possibly via a different name, and possibly indirectly.
xml.parsers.expat.errors.XML_ERROR_SUSPENDED  
The requested operation was made on a suspended parser, but isn’t allowed. This includes attempts to provide additional input or to stop the parser.
xml.parsers.expat.errors.XML_ERROR_SYNTAX  
Some unspecified syntax error was encountered.
xml.parsers.expat.errors.XML_ERROR_TAG_MISMATCH  
An end tag did not match the innermost open start tag.