Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Static Public Attributes | Private Attributes | Static Private Attributes
xml.dom.pulldom.PullDOM Class Reference
Inheritance diagram for xml.dom.pulldom.PullDOM:
Inheritance graph
[legend]
Collaboration diagram for xml.dom.pulldom.PullDOM:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def pop
def setDocumentLocator
def startPrefixMapping
def endPrefixMapping
def startElementNS
def endElementNS
def startElement
def endElement
def comment
def processingInstruction
def ignorableWhitespace
def characters
def startDocument
def buildDocument
def endDocument
def clear

Public Attributes

 documentFactory
 firstEvent
 lastEvent
 elementStack
 push
 pop
 pending_events

Static Public Attributes

 document = None

Private Attributes

 _ns_contexts
 _current_context
 _xmlns_attrs

Static Private Attributes

 _locator = None

Detailed Description

Definition at line 14 of file pulldom.py.


Constructor & Destructor Documentation

def xml.dom.pulldom.PullDOM.__init__ (   self,
  documentFactory = None 
)

Definition at line 18 of file pulldom.py.

00018 
00019     def __init__(self, documentFactory=None):
00020         from xml.dom import XML_NAMESPACE
00021         self.documentFactory = documentFactory
00022         self.firstEvent = [None, None]
00023         self.lastEvent = self.firstEvent
00024         self.elementStack = []
00025         self.push = self.elementStack.append
00026         try:
00027             self.pop = self.elementStack.pop
00028         except AttributeError:
00029             # use class' pop instead
00030             pass
00031         self._ns_contexts = [{XML_NAMESPACE:'xml'}] # contains uri -> prefix dicts
00032         self._current_context = self._ns_contexts[-1]
00033         self.pending_events = []

Here is the caller graph for this function:


Member Function Documentation

def xml.dom.pulldom.PullDOM.buildDocument (   self,
  uri,
  tagname 
)

Definition at line 165 of file pulldom.py.

00165 
00166     def buildDocument(self, uri, tagname):
00167         # Can't do that in startDocument, since we need the tagname
00168         # XXX: obtain DocumentType
00169         node = self.documentFactory.createDocument(uri, tagname, None)
00170         self.document = node
00171         self.lastEvent[1] = [(START_DOCUMENT, node), None]
00172         self.lastEvent = self.lastEvent[1]
00173         self.push(node)
00174         # Put everything we have seen so far into the document
00175         for e in self.pending_events:
00176             if e[0][0] == PROCESSING_INSTRUCTION:
00177                 _,target,data = e[0]
00178                 n = self.document.createProcessingInstruction(target, data)
00179                 e[0] = (PROCESSING_INSTRUCTION, n)
00180             elif e[0][0] == COMMENT:
00181                 n = self.document.createComment(e[0][1])
00182                 e[0] = (COMMENT, n)
00183             else:
00184                 raise AssertionError("Unknown pending event ",e[0][0])
00185             self.lastEvent[1] = e
00186             self.lastEvent = e
00187         self.pending_events = None
00188         return node.firstChild

Here is the caller graph for this function:

def xml.dom.pulldom.PullDOM.characters (   self,
  chars 
)

Reimplemented in xml.dom.pulldom.SAX2DOM.

Definition at line 155 of file pulldom.py.

00155 
00156     def characters(self, chars):
00157         node = self.document.createTextNode(chars)
00158         self.lastEvent[1] = [(CHARACTERS, node), None]
00159         self.lastEvent = self.lastEvent[1]

Definition at line 193 of file pulldom.py.

00193 
00194     def clear(self):
00195         "clear(): Explicitly release parsing structures"
00196         self.document = None

def xml.dom.pulldom.PullDOM.comment (   self,
  s 
)

Definition at line 132 of file pulldom.py.

00132 
00133     def comment(self, s):
00134         if self.document:
00135             node = self.document.createComment(s)
00136             self.lastEvent[1] = [(COMMENT, node), None]
00137             self.lastEvent = self.lastEvent[1]
00138         else:
00139             event = [(COMMENT, s), None]
00140             self.pending_events.append(event)

Definition at line 189 of file pulldom.py.

00189 
00190     def endDocument(self):
00191         self.lastEvent[1] = [(END_DOCUMENT, self.document), None]
00192         self.pop()

def xml.dom.pulldom.PullDOM.endElement (   self,
  name 
)

Definition at line 128 of file pulldom.py.

00128 
00129     def endElement(self, name):
00130         self.lastEvent[1] = [(END_ELEMENT, self.pop()), None]
00131         self.lastEvent = self.lastEvent[1]

def xml.dom.pulldom.PullDOM.endElementNS (   self,
  name,
  tagName 
)

Definition at line 109 of file pulldom.py.

00109 
00110     def endElementNS(self, name, tagName):
00111         self.lastEvent[1] = [(END_ELEMENT, self.pop()), None]
00112         self.lastEvent = self.lastEvent[1]

def xml.dom.pulldom.PullDOM.endPrefixMapping (   self,
  prefix 
)

Definition at line 49 of file pulldom.py.

00049 
00050     def endPrefixMapping(self, prefix):
00051         self._current_context = self._ns_contexts.pop()

def xml.dom.pulldom.PullDOM.ignorableWhitespace (   self,
  chars 
)

Reimplemented in xml.dom.pulldom.SAX2DOM.

Definition at line 150 of file pulldom.py.

00150 
00151     def ignorableWhitespace(self, chars):
00152         node = self.document.createTextNode(chars)
00153         self.lastEvent[1] = [(IGNORABLE_WHITESPACE, node), None]
00154         self.lastEvent = self.lastEvent[1]

Definition at line 34 of file pulldom.py.

00034 
00035     def pop(self):
00036         result = self.elementStack[-1]
00037         del self.elementStack[-1]
00038         return result

def xml.dom.pulldom.PullDOM.processingInstruction (   self,
  target,
  data 
)

Reimplemented in xml.dom.pulldom.SAX2DOM.

Definition at line 141 of file pulldom.py.

00141 
00142     def processingInstruction(self, target, data):
00143         if self.document:
00144             node = self.document.createProcessingInstruction(target, data)
00145             self.lastEvent[1] = [(PROCESSING_INSTRUCTION, node), None]
00146             self.lastEvent = self.lastEvent[1]
00147         else:
00148             event = [(PROCESSING_INSTRUCTION, target, data), None]
00149             self.pending_events.append(event)

def xml.dom.pulldom.PullDOM.setDocumentLocator (   self,
  locator 
)

Definition at line 39 of file pulldom.py.

00039 
00040     def setDocumentLocator(self, locator):
00041         self._locator = locator

Definition at line 160 of file pulldom.py.

00160 
00161     def startDocument(self):
00162         if self.documentFactory is None:
00163             import xml.dom.minidom
00164             self.documentFactory = xml.dom.minidom.Document.implementation

def xml.dom.pulldom.PullDOM.startElement (   self,
  name,
  attrs 
)

Reimplemented in xml.dom.pulldom.SAX2DOM.

Definition at line 113 of file pulldom.py.

00113 
00114     def startElement(self, name, attrs):
00115         if self.document:
00116             node = self.document.createElement(name)
00117         else:
00118             node = self.buildDocument(None, name)
00119 
00120         for aname,value in attrs.items():
00121             attr = self.document.createAttribute(aname)
00122             attr.value = value
00123             node.setAttributeNode(attr)
00124 
00125         self.lastEvent[1] = [(START_ELEMENT, node), None]
00126         self.lastEvent = self.lastEvent[1]
00127         self.push(node)

Here is the call graph for this function:

def xml.dom.pulldom.PullDOM.startElementNS (   self,
  name,
  tagName,
  attrs 
)

Reimplemented in xml.dom.pulldom.SAX2DOM.

Definition at line 52 of file pulldom.py.

00052 
00053     def startElementNS(self, name, tagName , attrs):
00054         # Retrieve xml namespace declaration attributes.
00055         xmlns_uri = 'http://www.w3.org/2000/xmlns/'
00056         xmlns_attrs = getattr(self, '_xmlns_attrs', None)
00057         if xmlns_attrs is not None:
00058             for aname, value in xmlns_attrs:
00059                 attrs._attrs[(xmlns_uri, aname)] = value
00060             self._xmlns_attrs = []
00061         uri, localname = name
00062         if uri:
00063             # When using namespaces, the reader may or may not
00064             # provide us with the original name. If not, create
00065             # *a* valid tagName from the current context.
00066             if tagName is None:
00067                 prefix = self._current_context[uri]
00068                 if prefix:
00069                     tagName = prefix + ":" + localname
00070                 else:
00071                     tagName = localname
00072             if self.document:
00073                 node = self.document.createElementNS(uri, tagName)
00074             else:
00075                 node = self.buildDocument(uri, tagName)
00076         else:
00077             # When the tagname is not prefixed, it just appears as
00078             # localname
00079             if self.document:
00080                 node = self.document.createElement(localname)
00081             else:
00082                 node = self.buildDocument(None, localname)
00083 
00084         for aname,value in attrs.items():
00085             a_uri, a_localname = aname
00086             if a_uri == xmlns_uri:
00087                 if a_localname == 'xmlns':
00088                     qname = a_localname
00089                 else:
00090                     qname = 'xmlns:' + a_localname
00091                 attr = self.document.createAttributeNS(a_uri, qname)
00092                 node.setAttributeNodeNS(attr)
00093             elif a_uri:
00094                 prefix = self._current_context[a_uri]
00095                 if prefix:
00096                     qname = prefix + ":" + a_localname
00097                 else:
00098                     qname = a_localname
00099                 attr = self.document.createAttributeNS(a_uri, qname)
00100                 node.setAttributeNodeNS(attr)
00101             else:
00102                 attr = self.document.createAttribute(a_localname)
00103                 node.setAttributeNode(attr)
00104             attr.value = value
00105 
00106         self.lastEvent[1] = [(START_ELEMENT, node), None]
00107         self.lastEvent = self.lastEvent[1]
00108         self.push(node)

Here is the call graph for this function:

def xml.dom.pulldom.PullDOM.startPrefixMapping (   self,
  prefix,
  uri 
)

Definition at line 42 of file pulldom.py.

00042 
00043     def startPrefixMapping(self, prefix, uri):
00044         if not hasattr(self, '_xmlns_attrs'):
00045             self._xmlns_attrs = []
00046         self._xmlns_attrs.append((prefix or 'xmlns', uri))
00047         self._ns_contexts.append(self._current_context.copy())
00048         self._current_context[uri] = prefix or None


Member Data Documentation

Definition at line 31 of file pulldom.py.

xml.dom.pulldom.PullDOM._locator = None [static, private]

Definition at line 15 of file pulldom.py.

Definition at line 30 of file pulldom.py.

Definition at line 44 of file pulldom.py.

Definition at line 16 of file pulldom.py.

Definition at line 20 of file pulldom.py.

Definition at line 23 of file pulldom.py.

Definition at line 21 of file pulldom.py.

Definition at line 22 of file pulldom.py.

Definition at line 32 of file pulldom.py.

Definition at line 26 of file pulldom.py.

Definition at line 24 of file pulldom.py.


The documentation for this class was generated from the following file: