Back to index

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

List of all members.

Public Member Functions

def __init__
def createParser
def getParser
def reset
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

 document
 curNode

Private Member Functions

def _setup_subset
def _finish_start_element
def _finish_end_element
def _handle_white_text_nodes

Private Attributes

 _options
 _filter
 _finish_start_element
 _parser
 _intern_setdefault
 _elem_info
 _cdata
 _finish_end_element
 _cdata_continue

Detailed Description

Document builder that uses Expat to build a ParsedXML.DOM document
instance.

Definition at line 133 of file expatbuilder.py.


Constructor & Destructor Documentation

def xml.dom.expatbuilder.ExpatBuilder.__init__ (   self,
  options = None 
)

Definition at line 137 of file expatbuilder.py.

00137 
00138     def __init__(self, options=None):
00139         if options is None:
00140             options = xmlbuilder.Options()
00141         self._options = options
00142         if self._options.filter is not None:
00143             self._filter = FilterVisibilityController(self._options.filter)
00144         else:
00145             self._filter = None
00146             # This *really* doesn't do anything in this case, so
00147             # override it with something fast & minimal.
00148             self._finish_start_element = id
00149         self._parser = None
00150         self.reset()

Here is the caller graph for this function:


Member Function Documentation

def xml.dom.expatbuilder.ExpatBuilder._finish_end_element (   self,
  curNode 
) [private]

Definition at line 404 of file expatbuilder.py.

00404 
00405     def _finish_end_element(self, curNode):
00406         info = self._elem_info.get(curNode.tagName)
00407         if info:
00408             self._handle_white_text_nodes(curNode, info)
00409         if self._filter:
00410             if curNode is self.document.documentElement:
00411                 return
00412             if self._filter.acceptNode(curNode) == FILTER_REJECT:
00413                 self.curNode.removeChild(curNode)
00414                 curNode.unlink()

Here is the call graph for this function:

Here is the caller graph for this function:

def xml.dom.expatbuilder.ExpatBuilder._finish_start_element (   self,
  node 
) [private]

Definition at line 376 of file expatbuilder.py.

00376 
00377     def _finish_start_element(self, node):
00378         if self._filter:
00379             # To be general, we'd have to call isSameNode(), but this
00380             # is sufficient for minidom:
00381             if node is self.document.documentElement:
00382                 return
00383             filt = self._filter.startContainer(node)
00384             if filt == FILTER_REJECT:
00385                 # ignore this node & all descendents
00386                 Rejecter(self)
00387             elif filt == FILTER_SKIP:
00388                 # ignore this node, but make it's children become
00389                 # children of the parent node
00390                 Skipper(self)
00391             else:
00392                 return
00393             self.curNode = node.parentNode
00394             node.parentNode.removeChild(node)
00395             node.unlink()

def xml.dom.expatbuilder.ExpatBuilder._handle_white_text_nodes (   self,
  node,
  info 
) [private]

Definition at line 415 of file expatbuilder.py.

00415 
00416     def _handle_white_text_nodes(self, node, info):
00417         if (self._options.whitespace_in_element_content
00418             or not info.isElementContent()):
00419             return
00420 
00421         # We have element type information and should remove ignorable
00422         # whitespace; identify for text nodes which contain only
00423         # whitespace.
00424         L = []
00425         for child in node.childNodes:
00426             if child.nodeType == TEXT_NODE and not child.data.strip():
00427                 L.append(child)
00428 
00429         # Remove ignorable whitespace from the tree.
00430         for child in L:
00431             node.removeChild(child)

Here is the caller graph for this function:

def xml.dom.expatbuilder.ExpatBuilder._setup_subset (   self,
  buffer 
) [private]
Load the internal subset if there might be one.

Definition at line 232 of file expatbuilder.py.

00232 
00233     def _setup_subset(self, buffer):
00234         """Load the internal subset if there might be one."""
00235         if self.document.doctype:
00236             extractor = InternalSubsetExtractor()
00237             extractor.parseString(buffer)
00238             subset = extractor.getSubset()
00239             self.document.doctype.internalSubset = subset

Here is the call graph for this function:

Here is the caller graph for this function:

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

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:

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:

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:

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

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:

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.ExpatBuilder.entity_decl_handler (   self,
  entityName,
  is_parameter_entity,
  value,
  base,
  systemId,
  publicId,
  notationName 
)

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 
)

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 
)

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:

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 
)
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.ExpatBuilder.notation_decl_handler (   self,
  notationName,
  base,
  systemId,
  publicId 
)

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 
)
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 
)
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 
)

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 in xml.dom.expatbuilder.FragmentBuilderNS, xml.dom.expatbuilder.ExpatBuilderNS, and xml.dom.expatbuilder.FragmentBuilder.

Definition at line 166 of file expatbuilder.py.

00166 
00167     def reset(self):
00168         """Free all data structures used during DOM construction."""
00169         self.document = theDOMImplementation.createDocument(
00170             EMPTY_NAMESPACE, None, None)
00171         self.curNode = self.document
00172         self._elem_info = self.document._elem_info
00173         self._cdata = False

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 
)

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 
)

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.ExpatBuilder.xml_decl_handler (   self,
  version,
  encoding,
  standalone 
)

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 172 of file expatbuilder.py.

Definition at line 282 of file expatbuilder.py.

Definition at line 171 of file expatbuilder.py.

Definition at line 142 of file expatbuilder.py.

Definition at line 266 of file expatbuilder.py.

Definition at line 147 of file expatbuilder.py.

Definition at line 159 of file expatbuilder.py.

Definition at line 140 of file expatbuilder.py.

Definition at line 148 of file expatbuilder.py.

Definition at line 170 of file expatbuilder.py.

Definition at line 168 of file expatbuilder.py.


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