Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes
xml.dom.expatbuilder.ExpatBuilderNS Class Reference
Inheritance diagram for xml.dom.expatbuilder.ExpatBuilderNS:
Inheritance graph
[legend]
Collaboration diagram for xml.dom.expatbuilder.ExpatBuilderNS:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def reset
def createParser
def install
def start_namespace_decl_handler
def start_element_handler
def end_element_handler
def createParser
def getParser
def install
def parseFile
def parseString
def start_doctype_decl_handler
def end_doctype_decl_handler
def pi_handler
def character_data_handler_cdata
def character_data_handler
def entity_decl_handler
def notation_decl_handler
def comment_handler
def start_cdata_section_handler
def end_cdata_section_handler
def external_entity_ref_handler
def first_element_handler
def start_element_handler
def end_element_handler
def element_decl_handler
def attlist_decl_handler
def xml_decl_handler

Public Attributes

 curNode
 document
 curNode

Detailed Description

Document builder that supports namespaces.

Definition at line 818 of file expatbuilder.py.


Member Function Documentation

def xml.dom.expatbuilder.ExpatBuilder.attlist_decl_handler (   self,
  elem,
  name,
  type,
  default,
  required 
) [inherited]

Definition at line 440 of file expatbuilder.py.

00440 
00441     def attlist_decl_handler(self, elem, name, type, default, required):
00442         info = self._elem_info.get(elem)
00443         if info is None:
00444             info = ElementInfo(elem)
00445             self._elem_info[elem] = info
00446         info._attr_info.append(
00447             [None, name, None, None, default, 0, type, required])

Here is the caller graph for this function:

def xml.dom.expatbuilder.ExpatBuilder.character_data_handler (   self,
  data 
) [inherited]

Definition at line 296 of file expatbuilder.py.

00296 
00297     def character_data_handler(self, data):
00298         childNodes = self.curNode.childNodes
00299         if childNodes and childNodes[-1].nodeType == TEXT_NODE:
00300             node = childNodes[-1]
00301             d = node.__dict__
00302             d['data'] = d['nodeValue'] = node.data + data
00303             return
00304         node = minidom.Text()
00305         d = node.__dict__
00306         d['data'] = d['nodeValue'] = node.data + data
00307         d['ownerDocument'] = self.document
00308         _append_child(self.curNode, node)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 274 of file expatbuilder.py.

00274 
00275     def character_data_handler_cdata(self, data):
00276         childNodes = self.curNode.childNodes
00277         if self._cdata:
00278             if (  self._cdata_continue
00279                   and childNodes[-1].nodeType == CDATA_SECTION_NODE):
00280                 childNodes[-1].appendData(data)
00281                 return
00282             node = self.document.createCDATASection(data)
00283             self._cdata_continue = True
00284         elif childNodes and childNodes[-1].nodeType == TEXT_NODE:
00285             node = childNodes[-1]
00286             value = node.data + data
00287             d = node.__dict__
00288             d['data'] = d['nodeValue'] = value
00289             return
00290         else:
00291             node = minidom.Text()
00292             d = node.__dict__
00293             d['data'] = d['nodeValue'] = data
00294             d['ownerDocument'] = self.document
00295         _append_child(self.curNode, node)

Here is the caller graph for this function:

def xml.dom.expatbuilder.ExpatBuilder.comment_handler (   self,
  data 
) [inherited]

Definition at line 333 of file expatbuilder.py.

00333 
00334     def comment_handler(self, data):
00335         node = self.document.createComment(data)
00336         _append_child(self.curNode, node)
00337         if self._filter and self._filter.acceptNode(node) == FILTER_REJECT:
00338             self.curNode.removeChild(node)

Here is the call graph for this function:

Here is the caller graph for this function:

Create a new parser object.

Definition at line 151 of file expatbuilder.py.

00151 
00152     def createParser(self):
00153         """Create a new parser object."""
00154         return expat.ParserCreate()

Here is the caller graph for this function:

Create a new namespace-handling parser.

Definition at line 726 of file expatbuilder.py.

00726 
00727     def createParser(self):
00728         """Create a new namespace-handling parser."""
00729         parser = expat.ParserCreate(namespace_separator=" ")
00730         parser.namespace_prefixes = True
00731         return parser

def xml.dom.expatbuilder.ExpatBuilder.element_decl_handler (   self,
  name,
  model 
) [inherited]

Definition at line 432 of file expatbuilder.py.

00432 
00433     def element_decl_handler(self, name, model):
00434         info = self._elem_info.get(name)
00435         if info is None:
00436             self._elem_info[name] = ElementInfo(name, model)
00437         else:
00438             assert info._model is None
00439             info._model = model

Here is the caller graph for this function:

Definition at line 343 of file expatbuilder.py.

00343 
00344     def end_cdata_section_handler(self):
00345         self._cdata = False
00346         self._cdata_continue = False

Here is the caller graph for this function:

Reimplemented in xml.dom.expatbuilder.InternalSubsetExtractor.

Definition at line 261 of file expatbuilder.py.

00261 
00262     def end_doctype_decl_handler(self):
00263         if self._options.comments:
00264             self._parser.CommentHandler = self.comment_handler
00265         self._parser.ProcessingInstructionHandler = self.pi_handler
00266         if not (self._elem_info or self._filter):
00267             self._finish_end_element = id

Here is the call graph for this function:

Here is the caller graph for this function:

def xml.dom.expatbuilder.ExpatBuilder.end_element_handler (   self,
  name 
) [inherited]

Definition at line 399 of file expatbuilder.py.

00399 
00400     def end_element_handler(self, name):
00401         curNode = self.curNode
00402         self.curNode = curNode.parentNode
00403         self._finish_end_element(curNode)

Here is the caller graph for this function:

def xml.dom.expatbuilder.Namespaces.end_element_handler (   self,
  name 
) [inherited]

Definition at line 801 of file expatbuilder.py.

00801 
00802         def end_element_handler(self, name):
00803             curNode = self.curNode
00804             if ' ' in name:
00805                 uri, localname, prefix, qname = _parse_ns_name(self, name)
00806                 assert (curNode.namespaceURI == uri
00807                         and curNode.localName == localname
00808                         and curNode.prefix == prefix), \
00809                         "element stack messed up! (namespace)"
00810             else:
00811                 assert curNode.nodeName == name, \
00812                        "element stack messed up - bad nodeName"
00813                 assert curNode.namespaceURI == EMPTY_NAMESPACE, \
00814                        "element stack messed up - bad namespaceURI"
00815             self.curNode = curNode.parentNode
00816             self._finish_end_element(curNode)
00817 

Here is the call graph for this function:

def xml.dom.expatbuilder.ExpatBuilder.entity_decl_handler (   self,
  entityName,
  is_parameter_entity,
  value,
  base,
  systemId,
  publicId,
  notationName 
) [inherited]

Definition at line 310 of file expatbuilder.py.

00310 
00311                             base, systemId, publicId, notationName):
00312         if is_parameter_entity:
00313             # we don't care about parameter entities for the DOM
00314             return
00315         if not self._options.entities:
00316             return
00317         node = self.document._create_entity(entityName, publicId,
00318                                             systemId, notationName)
00319         if value is not None:
00320             # internal entity
00321             # node *should* be readonly, but we'll cheat
00322             child = self.document.createTextNode(value)
00323             node.childNodes.append(child)
00324         self.document.doctype.entities._seq.append(node)
00325         if self._filter and self._filter.acceptNode(node) == FILTER_REJECT:
00326             del self.document.doctype.entities._seq[-1]

Here is the caller graph for this function:

def xml.dom.expatbuilder.ExpatBuilder.external_entity_ref_handler (   self,
  context,
  base,
  systemId,
  publicId 
) [inherited]

Definition at line 347 of file expatbuilder.py.

00347 
00348     def external_entity_ref_handler(self, context, base, systemId, publicId):
00349         return 1

Here is the caller graph for this function:

def xml.dom.expatbuilder.ExpatBuilder.first_element_handler (   self,
  name,
  attributes 
) [inherited]

Definition at line 350 of file expatbuilder.py.

00350 
00351     def first_element_handler(self, name, attributes):
00352         if self._filter is None and not self._elem_info:
00353             self._finish_end_element = id
00354         self.getParser().StartElementHandler = self.start_element_handler
00355         self.start_element_handler(name, attributes)

Here is the call graph for this function:

Here is the caller graph for this function:

def xml.dom.expatbuilder.ExpatBuilder.getParser (   self) [inherited]
Return the parser object, creating a new one if needed.

Definition at line 155 of file expatbuilder.py.

00155 
00156     def getParser(self):
00157         """Return the parser object, creating a new one if needed."""
00158         if not self._parser:
00159             self._parser = self.createParser()
00160             self._intern_setdefault = self._parser.intern.setdefault
00161             self._parser.buffer_text = True
00162             self._parser.ordered_attributes = True
00163             self._parser.specified_attributes = True
00164             self.install(self._parser)
00165         return self._parser

Here is the call graph for this function:

Here is the caller graph for this function:

def xml.dom.expatbuilder.ExpatBuilder.install (   self,
  parser 
) [inherited]
Install the callbacks needed to build the DOM into the parser.

Reimplemented in xml.dom.expatbuilder.InternalSubsetExtractor.

Definition at line 174 of file expatbuilder.py.

00174 
00175     def install(self, parser):
00176         """Install the callbacks needed to build the DOM into the parser."""
00177         # This creates circular references!
00178         parser.StartDoctypeDeclHandler = self.start_doctype_decl_handler
00179         parser.StartElementHandler = self.first_element_handler
00180         parser.EndElementHandler = self.end_element_handler
00181         parser.ProcessingInstructionHandler = self.pi_handler
00182         if self._options.entities:
00183             parser.EntityDeclHandler = self.entity_decl_handler
00184         parser.NotationDeclHandler = self.notation_decl_handler
00185         if self._options.comments:
00186             parser.CommentHandler = self.comment_handler
00187         if self._options.cdata_sections:
00188             parser.StartCdataSectionHandler = self.start_cdata_section_handler
00189             parser.EndCdataSectionHandler = self.end_cdata_section_handler
00190             parser.CharacterDataHandler = self.character_data_handler_cdata
00191         else:
00192             parser.CharacterDataHandler = self.character_data_handler
00193         parser.ExternalEntityRefHandler = self.external_entity_ref_handler
00194         parser.XmlDeclHandler = self.xml_decl_handler
00195         parser.ElementDeclHandler = self.element_decl_handler
00196         parser.AttlistDeclHandler = self.attlist_decl_handler

Here is the call graph for this function:

def xml.dom.expatbuilder.Namespaces.install (   self,
  parser 
) [inherited]
Insert the namespace-handlers onto the parser.

Definition at line 732 of file expatbuilder.py.

00732 
00733     def install(self, parser):
00734         """Insert the namespace-handlers onto the parser."""
00735         ExpatBuilder.install(self, parser)
00736         if self._options.namespace_declarations:
00737             parser.StartNamespaceDeclHandler = (
00738                 self.start_namespace_decl_handler)

Here is the call graph for this function:

def xml.dom.expatbuilder.ExpatBuilder.notation_decl_handler (   self,
  notationName,
  base,
  systemId,
  publicId 
) [inherited]

Definition at line 327 of file expatbuilder.py.

00327 
00328     def notation_decl_handler(self, notationName, base, systemId, publicId):
00329         node = self.document._create_notation(notationName, publicId, systemId)
00330         self.document.doctype.notations._seq.append(node)
00331         if self._filter and self._filter.acceptNode(node) == FILTER_ACCEPT:
00332             del self.document.doctype.notations._seq[-1]

Here is the caller graph for this function:

def xml.dom.expatbuilder.ExpatBuilder.parseFile (   self,
  file 
) [inherited]
Parse a document from a file object, returning the document
node.

Reimplemented in xml.dom.expatbuilder.InternalSubsetExtractor, and xml.dom.expatbuilder.FragmentBuilder.

Definition at line 197 of file expatbuilder.py.

00197 
00198     def parseFile(self, file):
00199         """Parse a document from a file object, returning the document
00200         node."""
00201         parser = self.getParser()
00202         first_buffer = True
00203         try:
00204             while 1:
00205                 buffer = file.read(16*1024)
00206                 if not buffer:
00207                     break
00208                 parser.Parse(buffer, 0)
00209                 if first_buffer and self.document.documentElement:
00210                     self._setup_subset(buffer)
00211                 first_buffer = False
00212             parser.Parse("", True)
00213         except ParseEscape:
00214             pass
00215         doc = self.document
00216         self.reset()
00217         self._parser = None
00218         return doc

def xml.dom.expatbuilder.ExpatBuilder.parseString (   self,
  string 
) [inherited]
Parse a document from a string, returning the document node.

Reimplemented in xml.dom.expatbuilder.InternalSubsetExtractor, and xml.dom.expatbuilder.FragmentBuilder.

Definition at line 219 of file expatbuilder.py.

00219 
00220     def parseString(self, string):
00221         """Parse a document from a string, returning the document node."""
00222         parser = self.getParser()
00223         try:
00224             parser.Parse(string, True)
00225             self._setup_subset(string)
00226         except ParseEscape:
00227             pass
00228         doc = self.document
00229         self.reset()
00230         self._parser = None
00231         return doc

Here is the caller graph for this function:

def xml.dom.expatbuilder.ExpatBuilder.pi_handler (   self,
  target,
  data 
) [inherited]

Definition at line 268 of file expatbuilder.py.

00268 
00269     def pi_handler(self, target, data):
00270         node = self.document.createProcessingInstruction(target, data)
00271         _append_child(self.curNode, node)
00272         if self._filter and self._filter.acceptNode(node) == FILTER_REJECT:
00273             self.curNode.removeChild(node)

Here is the call graph for this function:

Here is the caller graph for this function:

Free all data structures used during DOM construction.

Reimplemented from xml.dom.expatbuilder.ExpatBuilder.

Definition at line 821 of file expatbuilder.py.

00821 
00822     def reset(self):
00823         ExpatBuilder.reset(self)
00824         self._initNamespaces()
00825 

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 339 of file expatbuilder.py.

00339 
00340     def start_cdata_section_handler(self):
00341         self._cdata = True
00342         self._cdata_continue = False

Here is the caller graph for this function:

def xml.dom.expatbuilder.ExpatBuilder.start_doctype_decl_handler (   self,
  doctypeName,
  systemId,
  publicId,
  has_internal_subset 
) [inherited]

Reimplemented in xml.dom.expatbuilder.InternalSubsetExtractor.

Definition at line 241 of file expatbuilder.py.

00241 
00242                                    has_internal_subset):
00243         doctype = self.document.implementation.createDocumentType(
00244             doctypeName, publicId, systemId)
00245         doctype.ownerDocument = self.document
00246         _append_child(self.document, doctype)
00247         self.document.doctype = doctype
00248         if self._filter and self._filter.acceptNode(doctype) == FILTER_REJECT:
00249             self.document.doctype = None
00250             del self.document.childNodes[-1]
00251             doctype = None
00252             self._parser.EntityDeclHandler = None
00253             self._parser.NotationDeclHandler = None
00254         if has_internal_subset:
00255             if doctype is not None:
00256                 doctype.entities._seq = []
00257                 doctype.notations._seq = []
00258             self._parser.CommentHandler = None
00259             self._parser.ProcessingInstructionHandler = None
00260             self._parser.EndDoctypeDeclHandler = self.end_doctype_decl_handler

Here is the call graph for this function:

Here is the caller graph for this function:

def xml.dom.expatbuilder.ExpatBuilder.start_element_handler (   self,
  name,
  attributes 
) [inherited]

Reimplemented in xml.dom.expatbuilder.InternalSubsetExtractor.

Definition at line 356 of file expatbuilder.py.

00356 
00357     def start_element_handler(self, name, attributes):
00358         node = self.document.createElement(name)
00359         _append_child(self.curNode, node)
00360         self.curNode = node
00361 
00362         if attributes:
00363             for i in range(0, len(attributes), 2):
00364                 a = minidom.Attr(attributes[i], EMPTY_NAMESPACE,
00365                                  None, EMPTY_PREFIX)
00366                 value = attributes[i+1]
00367                 d = a.childNodes[0].__dict__
00368                 d['data'] = d['nodeValue'] = value
00369                 d = a.__dict__
00370                 d['value'] = d['nodeValue'] = value
00371                 d['ownerDocument'] = self.document
00372                 _set_attribute_node(node, a)
00373 
00374         if node is not self.document.documentElement:
00375             self._finish_start_element(node)

Here is the call graph for this function:

Here is the caller graph for this function:

def xml.dom.expatbuilder.Namespaces.start_element_handler (   self,
  name,
  attributes 
) [inherited]

Definition at line 743 of file expatbuilder.py.

00743 
00744     def start_element_handler(self, name, attributes):
00745         if ' ' in name:
00746             uri, localname, prefix, qname = _parse_ns_name(self, name)
00747         else:
00748             uri = EMPTY_NAMESPACE
00749             qname = name
00750             localname = None
00751             prefix = EMPTY_PREFIX
00752         node = minidom.Element(qname, uri, prefix, localname)
00753         node.ownerDocument = self.document
00754         _append_child(self.curNode, node)
00755         self.curNode = node
00756 
00757         if self._ns_ordered_prefixes:
00758             for prefix, uri in self._ns_ordered_prefixes:
00759                 if prefix:
00760                     a = minidom.Attr(_intern(self, 'xmlns:' + prefix),
00761                                      XMLNS_NAMESPACE, prefix, "xmlns")
00762                 else:
00763                     a = minidom.Attr("xmlns", XMLNS_NAMESPACE,
00764                                      "xmlns", EMPTY_PREFIX)
00765                 d = a.childNodes[0].__dict__
00766                 d['data'] = d['nodeValue'] = uri
00767                 d = a.__dict__
00768                 d['value'] = d['nodeValue'] = uri
00769                 d['ownerDocument'] = self.document
00770                 _set_attribute_node(node, a)
00771             del self._ns_ordered_prefixes[:]
00772 
00773         if attributes:
00774             _attrs = node._attrs
00775             _attrsNS = node._attrsNS
00776             for i in range(0, len(attributes), 2):
00777                 aname = attributes[i]
00778                 value = attributes[i+1]
00779                 if ' ' in aname:
00780                     uri, localname, prefix, qname = _parse_ns_name(self, aname)
00781                     a = minidom.Attr(qname, uri, localname, prefix)
00782                     _attrs[qname] = a
00783                     _attrsNS[(uri, localname)] = a
00784                 else:
00785                     a = minidom.Attr(aname, EMPTY_NAMESPACE,
00786                                      aname, EMPTY_PREFIX)
00787                     _attrs[aname] = a
00788                     _attrsNS[(EMPTY_NAMESPACE, aname)] = a
00789                 d = a.childNodes[0].__dict__
00790                 d['data'] = d['nodeValue'] = value
00791                 d = a.__dict__
00792                 d['ownerDocument'] = self.document
00793                 d['value'] = d['nodeValue'] = value
00794                 d['ownerElement'] = node

Here is the call graph for this function:

def xml.dom.expatbuilder.Namespaces.start_namespace_decl_handler (   self,
  prefix,
  uri 
) [inherited]
Push this namespace declaration on our storage.

Definition at line 739 of file expatbuilder.py.

00739 
00740     def start_namespace_decl_handler(self, prefix, uri):
00741         """Push this namespace declaration on our storage."""
00742         self._ns_ordered_prefixes.append((prefix, uri))

Here is the caller graph for this function:

def xml.dom.expatbuilder.ExpatBuilder.xml_decl_handler (   self,
  version,
  encoding,
  standalone 
) [inherited]

Definition at line 448 of file expatbuilder.py.

00448 
00449     def xml_decl_handler(self, version, encoding, standalone):
00450         self.document.version = version
00451         self.document.encoding = encoding
00452         # This is still a little ugly, thanks to the pyexpat API. ;-(
00453         if standalone >= 0:
00454             if standalone:
00455                 self.document.standalone = True
00456             else:
00457                 self.document.standalone = False
00458 
00459 
00460 # Don't include FILTER_INTERRUPT, since that's checked separately
# where allowed.

Here is the caller graph for this function:


Member Data Documentation

Definition at line 170 of file expatbuilder.py.

Definition at line 754 of file expatbuilder.py.

Definition at line 168 of file expatbuilder.py.


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