Back to index

python3.2  3.2.2
Classes | Functions | Variables
xml.dom.expatbuilder Namespace Reference

Classes

class  ElementInfo
class  ExpatBuilder
class  FilterVisibilityController
class  FilterCrutch
class  Rejecter
class  Skipper
class  FragmentBuilder
class  Namespaces
class  ExpatBuilderNS
class  FragmentBuilderNS
class  ParseEscape
class  InternalSubsetExtractor

Functions

def _intern
def _parse_ns_name
def _getDeclarations
 self._parser = None
def _getNSattrs
def external_entity_ref_handler
def parse
def parseString
def parseFragment
def parseFragmentString
def makeBuilder

Variables

 TEXT_NODE = Node.TEXT_NODE
 CDATA_SECTION_NODE = Node.CDATA_SECTION_NODE
 DOCUMENT_NODE = Node.DOCUMENT_NODE
 FILTER_ACCEPT = xmlbuilder.DOMBuilderFilter.FILTER_ACCEPT
 FILTER_REJECT = xmlbuilder.DOMBuilderFilter.FILTER_REJECT
 FILTER_SKIP = xmlbuilder.DOMBuilderFilter.FILTER_SKIP
 FILTER_INTERRUPT = xmlbuilder.DOMBuilderFilter.FILTER_INTERRUPT
tuple theDOMImplementation = minidom.getDOMImplementation()
dictionary _typeinfo_map
tuple _ALLOWED_FILTER_RETURNS = (FILTER_ACCEPT, FILTER_REJECT, FILTER_SKIP)
 _FRAGMENT_BUILDER_INTERNAL_SYSTEM_ID = \
tuple _FRAGMENT_BUILDER_TEMPLATE
 document
 fragment
 curNode
 _source

Detailed Description

Facility to use the Expat parser to load a minidom instance
from a string or file.

This avoids all the overhead of SAX and pulldom to gain performance.

Function Documentation

def xml.dom.expatbuilder._getDeclarations (   self) [private]

self._parser = None

Re-create the internal subset from the DocumentType node.

This is only needed if we don't already have the
internalSubset as a string.

Definition at line 656 of file expatbuilder.py.

00656 
00657     def _getDeclarations(self):
00658         """Re-create the internal subset from the DocumentType node.
00659 
00660         This is only needed if we don't already have the
00661         internalSubset as a string.
00662         """
00663         doctype = self.context.ownerDocument.doctype
00664         s = ""
00665         if doctype:
00666             for i in range(doctype.notations.length):
00667                 notation = doctype.notations.item(i)
00668                 if s:
00669                     s = s + "\n  "
00670                 s = "%s<!NOTATION %s" % (s, notation.nodeName)
00671                 if notation.publicId:
00672                     s = '%s PUBLIC "%s"\n             "%s">' \
00673                         % (s, notation.publicId, notation.systemId)
00674                 else:
00675                     s = '%s SYSTEM "%s">' % (s, notation.systemId)
00676             for i in range(doctype.entities.length):
00677                 entity = doctype.entities.item(i)
00678                 if s:
00679                     s = s + "\n  "
00680                 s = "%s<!ENTITY %s" % (s, entity.nodeName)
00681                 if entity.publicId:
00682                     s = '%s PUBLIC "%s"\n             "%s"' \
00683                         % (s, entity.publicId, entity.systemId)
00684                 elif entity.systemId:
00685                     s = '%s SYSTEM "%s"' % (s, entity.systemId)
00686                 else:
00687                     s = '%s "%s"' % (s, entity.firstChild.data)
00688                 if entity.notationName:
00689                     s = "%s NOTATION %s" % (s, entity.notationName)
00690                 s = s + ">"
00691         return s

def xml.dom.expatbuilder._getNSattrs (   self) [private]

Definition at line 692 of file expatbuilder.py.

00692 
00693     def _getNSattrs(self):
00694         return ""

def xml.dom.expatbuilder._intern (   builder,
  s 
) [private]

Definition at line 113 of file expatbuilder.py.

00113 
00114 def _intern(builder, s):
00115     return builder._intern_setdefault(s, s)

def xml.dom.expatbuilder._parse_ns_name (   builder,
  name 
) [private]

Definition at line 116 of file expatbuilder.py.

00116 
00117 def _parse_ns_name(builder, name):
00118     assert ' ' in name
00119     parts = name.split(' ')
00120     intern = builder._intern_setdefault
00121     if len(parts) == 3:
00122         uri, localname, prefix = parts
00123         prefix = intern(prefix, prefix)
00124         qname = "%s:%s" % (prefix, localname)
00125         qname = intern(qname, qname)
00126         localname = intern(localname, localname)
00127     else:
00128         uri, localname = parts
00129         prefix = EMPTY_PREFIX
00130         qname = localname = intern(localname, localname)
00131     return intern(uri, uri), localname, prefix, qname
00132 

Here is the caller graph for this function:

def xml.dom.expatbuilder.external_entity_ref_handler (   self,
  context,
  base,
  systemId,
  publicId 
)

Definition at line 695 of file expatbuilder.py.

00695 
00696     def external_entity_ref_handler(self, context, base, systemId, publicId):
00697         if systemId == _FRAGMENT_BUILDER_INTERNAL_SYSTEM_ID:
00698             # this entref is the one that we made to put the subtree
00699             # in; all of our given input is parsed in here.
00700             old_document = self.document
00701             old_cur_node = self.curNode
00702             parser = self._parser.ExternalEntityParserCreate(context)
00703             # put the real document back, parse into the fragment to return
00704             self.document = self.originalDocument
00705             self.fragment = self.document.createDocumentFragment()
00706             self.curNode = self.fragment
00707             try:
00708                 parser.Parse(self._source, 1)
00709             finally:
00710                 self.curNode = old_cur_node
00711                 self.document = old_document
00712                 self._source = None
00713             return -1
00714         else:
00715             return ExpatBuilder.external_entity_ref_handler(
00716                 self, context, base, systemId, publicId)
00717 

Create a builder based on an Options object.

Definition at line 978 of file expatbuilder.py.

00978 
00979 def makeBuilder(options):
00980     """Create a builder based on an Options object."""
00981     if options.namespaces:
00982         return ExpatBuilderNS(options)
00983     else:
00984         return ExpatBuilder(options)

Here is the caller graph for this function:

def xml.dom.expatbuilder.parse (   file,
  namespaces = True 
)
Parse a document, returning the resulting Document node.

'file' may be either a file name or an open file object.

Definition at line 911 of file expatbuilder.py.

00911 
00912 def parse(file, namespaces=True):
00913     """Parse a document, returning the resulting Document node.
00914 
00915     'file' may be either a file name or an open file object.
00916     """
00917     if namespaces:
00918         builder = ExpatBuilderNS()
00919     else:
00920         builder = ExpatBuilder()
00921 
00922     if isinstance(file, str):
00923         fp = open(file, 'rb')
00924         try:
00925             result = builder.parseFile(fp)
00926         finally:
00927             fp.close()
00928     else:
00929         result = builder.parseFile(file)
00930     return result
00931 

def xml.dom.expatbuilder.parseFragment (   file,
  context,
  namespaces = True 
)
Parse a fragment of a document, given the context from which it
was originally extracted.  context should be the parent of the
node(s) which are in the fragment.

'file' may be either a file name or an open file object.

Definition at line 943 of file expatbuilder.py.

00943 
00944 def parseFragment(file, context, namespaces=True):
00945     """Parse a fragment of a document, given the context from which it
00946     was originally extracted.  context should be the parent of the
00947     node(s) which are in the fragment.
00948 
00949     'file' may be either a file name or an open file object.
00950     """
00951     if namespaces:
00952         builder = FragmentBuilderNS(context)
00953     else:
00954         builder = FragmentBuilder(context)
00955 
00956     if isinstance(file, str):
00957         fp = open(file, 'rb')
00958         try:
00959             result = builder.parseFile(fp)
00960         finally:
00961             fp.close()
00962     else:
00963         result = builder.parseFile(file)
00964     return result
00965 

def xml.dom.expatbuilder.parseFragmentString (   string,
  context,
  namespaces = True 
)
Parse a fragment of a document from a string, given the context
from which it was originally extracted.  context should be the
parent of the node(s) which are in the fragment.

Definition at line 966 of file expatbuilder.py.

00966 
00967 def parseFragmentString(string, context, namespaces=True):
00968     """Parse a fragment of a document from a string, given the context
00969     from which it was originally extracted.  context should be the
00970     parent of the node(s) which are in the fragment.
00971     """
00972     if namespaces:
00973         builder = FragmentBuilderNS(context)
00974     else:
00975         builder = FragmentBuilder(context)
00976     return builder.parseString(string)
00977 

def xml.dom.expatbuilder.parseString (   string,
  namespaces = True 
)
Parse a document from a string, returning the resulting
Document node.

Definition at line 932 of file expatbuilder.py.

00932 
00933 def parseString(string, namespaces=True):
00934     """Parse a document from a string, returning the resulting
00935     Document node.
00936     """
00937     if namespaces:
00938         builder = ExpatBuilderNS()
00939     else:
00940         builder = ExpatBuilder()
00941     return builder.parseString(string)
00942 


Variable Documentation

Definition at line 461 of file expatbuilder.py.

Definition at line 585 of file expatbuilder.py.

Initial value:
00001 (
00002     '''\
00003 <!DOCTYPE wrapper
00004   %%s [
00005   <!ENTITY fragment-builder-internal
00006     SYSTEM "%s">
00007 %%s
00008 ]>
00009 <wrapper %%s
00010 >&fragment-builder-internal;</wrapper>'''
00011     % _FRAGMENT_BUILDER_INTERNAL_SYSTEM_ID)

Definition at line 588 of file expatbuilder.py.

Definition at line 711 of file expatbuilder.py.

Initial value:
00001 {
00002     "CDATA":    minidom.TypeInfo(None, "cdata"),
00003     "ENUM":     minidom.TypeInfo(None, "enumeration"),
00004     "ENTITY":   minidom.TypeInfo(None, "entity"),
00005     "ENTITIES": minidom.TypeInfo(None, "entities"),
00006     "ID":       minidom.TypeInfo(None, "id"),
00007     "IDREF":    minidom.TypeInfo(None, "idref"),
00008     "IDREFS":   minidom.TypeInfo(None, "idrefs"),
00009     "NMTOKEN":  minidom.TypeInfo(None, "nmtoken"),
00010     "NMTOKENS": minidom.TypeInfo(None, "nmtokens"),
00011     }

Definition at line 50 of file expatbuilder.py.

Definition at line 39 of file expatbuilder.py.

Definition at line 705 of file expatbuilder.py.

Definition at line 703 of file expatbuilder.py.

Definition at line 40 of file expatbuilder.py.

Definition at line 42 of file expatbuilder.py.

Definition at line 45 of file expatbuilder.py.

Definition at line 43 of file expatbuilder.py.

Definition at line 44 of file expatbuilder.py.

Definition at line 704 of file expatbuilder.py.

Definition at line 38 of file expatbuilder.py.

Definition at line 47 of file expatbuilder.py.