[Python-Dev] 2.5 issues need resolving in a few days

engelbert.gruber at ssg.co.at engelbert.gruber at ssg.co.at
Mon Jun 12 11:23:10 CEST 2006


On Sat, 10 Jun 2006, Fredrik Lundh wrote:

> if all undocumented modules had as much documentation and articles as
> ET, the world would be a lot better documented ;-)
>
> I've posted a text version of the xml.etree.ElementTree PythonDoc here:
>
>     http://www.python.org/sf/1504046
>
> hopefully, one of the anything-to-latex volunteers will pick this up
> shortly; otherwise, I'll deal with that early next week.

i am new to anything-to-latex but gave it a try

elementtree.txt is the modified text version

    1. add a classifier to function and class documentation
    2. remove the Arguments:/Returns: definition lists, first because the
       tool does not handle it in a useful way, second i couldnt find this
       style in lib/*.tex and therefore dont know how it should be handled.

elementtree.text is the version generated from this version (rst2docpy)

cheers
-------------- next part --------------
:Module: elementtree

:Summary: The xml.etree.ElementTree Module

:Module Type: standard

:Author: Fredrik Lundh <fredrik at pythonware.com>

:Version Added: 2.5

:Synopsis: This module provides implementations of the Element and ElementTree

           types, plus support classes.



           A C version of this API is available as xml.etree.cElementTree.



Overview

--------



The Element type is a flexible container object, designed to store

hierarchical data structures in memory. The type can be described as a

cross between a list and a dictionary.



Each element has a number of properties associated with it:



* a tag. This is a string identifying what kind of data

  this element represents (the element type, in other words).

* a number of attributes, stored in a Python dictionary.

* a text string.

* an optional tail string.

* a number of child elements, stored in a Python sequence



To create an element instance, use the Element or SubElement factory

functions.



The ElementTree class can be used to wrap an element

structure, and convert it from and to XML.



Functions

---------



Comment(text=None) : funcdesc

  Comment element factory.  This factory function creates a special

  element that will be serialized as an XML comment.



  The comment string can be either an 8-bit ASCII string or a Unicode

  string.



  text: A string containing the comment string.



  Returns: An element instance, representing a comment.



dump(elem) : funcdesc

  Writes an element tree or element structure to sys.stdout.  This

  function should be used for debugging only.



  The exact output format is implementation dependent.  In this

  version, it's written as an ordinary XML file.



  elem: An element tree or an individual element.



Element(tag, attrib={}, **extra) : funcdesc

  Element factory.  This function returns an object implementing the

  standard Element interface.  The exact class or type of that object

  is implementation dependent, but it will always be compatible with

  the _ElementInterface class in this module.



  The element name, attribute names, and attribute values can be

  either 8-bit ASCII strings or Unicode strings.



  tag: The element name.



  attrib: An optional dictionary, containing element attributes.



  extra: Additional attributes, given as keyword arguments.



  Returns: An element instance.



fromstring(text) : funcdesc

  Parses an XML document from a string constant.  Same as XML.



  source: A string containing XML data.



  Returns: An Element instance.



iselement(element) : funcdesc

  Checks if an object appears to be a valid element object.



  element: element instance.



  Returns: A true value if this is an element object.



iterparse(source, events=None) : funcdesc

  Parses an XML document into an element tree incrementally, and reports

  what's going on to the user.



  source: A filename or file object containing XML data.



  events: A list of events to report back.  If omitted, only "end"

  events are reported.



  Returns: A (event, elem) iterator.



parse(source, parser=None) : funcdesc

  Parses an XML document into an element tree.



  source: A filename or file object containing XML data.



  parser: An optional parser instance.  If not given, the

  standard XMLTreeBuilder parser is used.



  Returns: An ElementTree instance



ProcessingInstruction(target, text=None) : funcdesc

  PI element factory.  This factory function creates a special element

  that will be serialized as an XML processing instruction.



  target: A string containing the PI target.



  text: A string containing the PI contents, if any.



  Returns: An element instance, representing a PI.



SubElement(parent, tag, attrib={}, **extra) : funcdesc

  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 8-bit ASCII strings or Unicode strings.



  parent: The parent element.



  tag: The subelement name.



  attrib: An optional dictionary, containing element attributes.



  extra: Additional attributes, given as keyword arguments.



  Returns: An element instance.



tostring(element, encoding=None) : funcdesc

  Generates a string representation of an XML element, including all

  subelements.



  element: An Element instance.



  Returns: An encoded string containing the XML data.



XML(text) : funcdesc

  Parses an XML document from a string constant.  This function can

  be used to embed "XML literals" in Python code.



  source: A string containing XML data.



  Returns: An Element instance.



XMLID(text) : funcdesc

  Parses an XML document from a string constant, and also returns

  a dictionary which maps from element id:s to elements.



  source: A string containing XML data.



  Returns: A tuple containing an Element instance and a dictionary.



ElementTree Objects

-------------------



class ElementTree(element=None, file=None) : classdesc

  ElementTree wrapper class.  This class represents an entire element

  hierarchy, and adds some extra support for serialization to and from

  standard XML.



  element: Optional root element.



  file (keyword): Optional file handle or name.  If given, the

  tree is initialized with the contents of this XML file.



_setroot(element) : methoddesc

  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: An element instance.



find(path) : methoddesc

  Finds the first toplevel element with given tag.

  Same as getroot().find(path).



  path: What element to look for.



  Returns: The first matching element, or None if no element was found.



findall(path) : methoddesc

  Finds all toplevel elements with the given tag.

  Same as getroot().findall(path).



  path: What element to look for.



  Returns: A list or iterator containing all matching elements,

  in document order.



findtext(path, default=None) : methoddesc

  Finds the element text for the first toplevel element with given

  tag.  Same as getroot().findtext(path).



  path: What toplevel element to look for.



  default: What to return if the element was not found.



  Returns: The text content of the first matching element, or the

  default value no element was found.  Note that if the element

  has is found, but has no text content, this method returns an

  empty string.



getiterator(tag=None) : methoddesc

  Creates a tree iterator for the root element.  The iterator loops

  over all elements in this tree, in document order.



  tag: What tags to look for (default is to return all elements)



  Returns: An iterator.



getroot() : methoddesc

  Gets the root element for this tree.



  Returns:

    An element instance.



parse(source, parser=None) : methoddesc

  Loads an external XML document into this element tree.



  source: A file name or file object.



  parser: An optional parser instance.  If not given, the

  standard XMLTreeBuilder parser is used.



  Returns: The document root element.



write(file, encoding="us-ascii") : methoddesc

  Writes the element tree to a file, as XML.



  file: A file name, or a file object opened for writing.



  encoding: Optional output encoding (default is US-ASCII).



QName Objects

-------------



class QName(text_or_uri, tag=None) : classdesc

  QName wrapper.  This can be used to wrap a QName attribute value, in

  order to get proper namespace handling on output.



  text: A string containing the QName value, in the form {uri}local,

  or, if the tag argument is given, the URI part of a QName.



  tag: Optional tag.  If given, the first argument is interpreted as

  an URI, and this argument is interpreted as a local name.



  Returns: An opaque object, representing the QName.



TreeBuilder Objects

-------------------



class TreeBuilder(element_factory=None) : classdesc

  Generic element structure builder.  This builder converts a sequence

  of start, data, and end 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: Optional element factory.  This factory

  is called to create new Element instances, as necessary.



close() : methoddesc

  Flushes the parser buffers, and returns the toplevel documen

  element.



  Returns:

    An Element instance.



data(data) : methoddesc

  Adds text to the current element.



  data: A string.  This should be either an 8-bit string

  containing ASCII text, or a Unicode string.



end(tag) : methoddesc

  Closes the current element.



  tag: The element name.



  Returns: The closed element.



start(tag, attrs) : methoddesc

  Opens a new element.



  tag: The element name.



  attrib: A dictionary containing element attributes.



  Returns: The opened element.



XMLTreeBuilder Objects

----------------------



class XMLTreeBuilder(html=0, target=None) : classdesc

  Element structure builder for XML source data, based on the

  expat parser.



  target (keyword): Target object.  If omitted, the builder uses an

  instance of the standard TreeBuilder class.



  html (keyword): Predefine HTML entities.  This flag is not supported

  by the current implementation.



close() : methoddesc

  Finishes feeding data to the parser.



  Returns:

    An element structure.



doctype(name, pubid, system) : methoddesc

  Handles a doctype declaration.



  name: Doctype name.



  pubid: Public identifier.



  system: System identifier.



feed(data) : methoddesc

  Feeds data to the parser.



  data: Encoded data.



-------------- next part --------------
A non-text attachment was scrubbed...
Name: elementtree.tex
Type: text/x-tex
Size: 10885 bytes
Desc: 
Url : http://mail.python.org/pipermail/python-dev/attachments/20060612/cad92d1c/attachment-0001.tex 


More information about the Python-Dev mailing list