Back to index

python3.2  3.2.2
Public Member Functions | Private Member Functions | Private Attributes
xml.sax.expatreader.ExpatParser Class Reference
Inheritance diagram for xml.sax.expatreader.ExpatParser:
Inheritance graph
[legend]
Collaboration diagram for xml.sax.expatreader.ExpatParser:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def parse
def prepareParser
def setContentHandler
def getFeature
def setFeature
def getProperty
def setProperty
def feed
def close
def reset
def getColumnNumber
def getLineNumber
def getPublicId
def getSystemId
def start_element
def end_element
def start_element_ns
def end_element_ns
def processing_instruction
def character_data
def start_namespace_decl
def end_namespace_decl
def start_doctype_decl
def unparsed_entity_decl
def notation_decl
def external_entity_ref
def skipped_entity_handler
def feed
def getContentHandler
def getDTDHandler
def setDTDHandler
def getEntityResolver
def setEntityResolver
def getErrorHandler
def setErrorHandler
def setLocale

Private Member Functions

def _reset_cont_handler
def _reset_lex_handler_prop

Private Attributes

 _source
 _parser
 _namespaces
 _lex_handler_prop
 _parsing
 _entity_stack
 _external_ges
 _interning
 _decl_handler_prop

Detailed Description

SAX driver for the pyexpat C module.

Definition at line 84 of file expatreader.py.


Constructor & Destructor Documentation

def xml.sax.expatreader.ExpatParser.__init__ (   self,
  namespaceHandling = 0,
  bufsize = 2**16-20 
)

Definition at line 87 of file expatreader.py.

00087 
00088     def __init__(self, namespaceHandling=0, bufsize=2**16-20):
00089         xmlreader.IncrementalParser.__init__(self, bufsize)
00090         self._source = xmlreader.InputSource()
00091         self._parser = None
00092         self._namespaces = namespaceHandling
00093         self._lex_handler_prop = None
00094         self._parsing = 0
00095         self._entity_stack = []
00096         self._external_ges = 1
00097         self._interning = None

Here is the caller graph for this function:


Member Function Documentation

Definition at line 226 of file expatreader.py.

00226 
00227     def _reset_cont_handler(self):
00228         self._parser.ProcessingInstructionHandler = \
00229                                     self._cont_handler.processingInstruction
00230         self._parser.CharacterDataHandler = self._cont_handler.characters

Here is the caller graph for this function:

Definition at line 231 of file expatreader.py.

00231 
00232     def _reset_lex_handler_prop(self):
00233         lex = self._lex_handler_prop
00234         parser = self._parser
00235         if lex is None:
00236             parser.CommentHandler = None
00237             parser.StartCdataSectionHandler = None
00238             parser.EndCdataSectionHandler = None
00239             parser.StartDoctypeDeclHandler = None
00240             parser.EndDoctypeDeclHandler = None
00241         else:
00242             parser.CommentHandler = lex.comment
00243             parser.StartCdataSectionHandler = lex.startCDATA
00244             parser.EndCdataSectionHandler = lex.endCDATA
00245             parser.StartDoctypeDeclHandler = self.start_doctype_decl
00246             parser.EndDoctypeDeclHandler = lex.endDTD

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 359 of file expatreader.py.

00359 
00360     def character_data(self, data):
00361         self._cont_handler.characters(data)

This method is called when the entire XML document has been
passed to the parser through the feed method, to notify the
parser that there are no more data. This allows the parser to
do the final checks on the document and empty the internal
data buffer.

The parser will not be ready to parse another document until
the reset method has been called.

close may raise SAXException.

Reimplemented from xml.sax.xmlreader.IncrementalParser.

Definition at line 213 of file expatreader.py.

00213 
00214     def close(self):
00215         if self._entity_stack:
00216             # If we are completing an external entity, do nothing here
00217             return
00218         self.feed("", isFinal = 1)
00219         self._cont_handler.endDocument()
00220         self._parsing = 0
00221         # break cycle created by expat handlers pointing to our methods
00222         self._parser = None
00223         bs = self._source.getByteStream()
00224         if bs is not None:
00225             bs.close()

Here is the call graph for this function:

Here is the caller graph for this function:

def xml.sax.expatreader.ExpatParser.end_element (   self,
  name 
)

Definition at line 306 of file expatreader.py.

00306 
00307     def end_element(self, name):
00308         self._cont_handler.endElement(name)

Here is the caller graph for this function:

Definition at line 343 of file expatreader.py.

00343 
00344     def end_element_ns(self, name):
00345         pair = name.split()
00346         if len(pair) == 1:
00347             pair = (None, name)
00348         elif len(pair) == 3:
00349             pair = pair[0], pair[1]
00350         else:
00351             pair = tuple(pair)
00352 
00353         self._cont_handler.endElementNS(pair, None)

Here is the caller graph for this function:

Definition at line 365 of file expatreader.py.

00365 
00366     def end_namespace_decl(self, prefix):
00367         self._cont_handler.endPrefixMapping(prefix)

Here is the caller graph for this function:

def xml.sax.expatreader.ExpatParser.external_entity_ref (   self,
  context,
  base,
  sysid,
  pubid 
)

Definition at line 377 of file expatreader.py.

00377 
00378     def external_entity_ref(self, context, base, sysid, pubid):
00379         if not self._external_ges:
00380             return 1
00381 
00382         source = self._ent_handler.resolveEntity(pubid, sysid)
00383         source = saxutils.prepare_input_source(source,
00384                                                self._source.getSystemId() or
00385                                                "")
00386 
00387         self._entity_stack.append((self._parser, self._source))
00388         self._parser = self._parser.ExternalEntityParserCreate(context)
00389         self._source = source
00390 
00391         try:
00392             xmlreader.IncrementalParser.parse(self, source)
00393         except:
00394             return 0  # FIXME: save error info here?
00395 
00396         (self._parser, self._source) = self._entity_stack[-1]
00397         del self._entity_stack[-1]
00398         return 1

def xml.sax.xmlreader.IncrementalParser.feed (   self,
  data 
) [inherited]
This method gives the raw XML data in the data parameter to
the parser and makes it parse the data, emitting the
corresponding events. It is allowed for XML constructs to be
split across several calls to feed.

feed may raise SAXException.

Definition at line 127 of file xmlreader.py.

00127 
00128     def feed(self, data):
00129         """This method gives the raw XML data in the data parameter to
00130         the parser and makes it parse the data, emitting the
00131         corresponding events. It is allowed for XML constructs to be
00132         split across several calls to feed.
00133 
00134         feed may raise SAXException."""
00135         raise NotImplementedError("This method must be implemented!")

Here is the caller graph for this function:

def xml.sax.expatreader.ExpatParser.feed (   self,
  data,
  isFinal = 0 
)

Definition at line 196 of file expatreader.py.

00196 
00197     def feed(self, data, isFinal = 0):
00198         if not self._parsing:
00199             self.reset()
00200             self._parsing = 1
00201             self._cont_handler.startDocument()
00202 
00203         try:
00204             # The isFinal parameter is internal to the expat reader.
00205             # If it is set to true, expat will check validity of the entire
00206             # document. When feeding chunks, they are not normally final -
00207             # except when invoked from close.
00208             self._parser.Parse(data, isFinal)
00209         except expat.error as e:
00210             exc = SAXParseException(expat.ErrorString(e.code), e, self)
00211             # FIXME: when to invoke error()?
00212             self._err_handler.fatalError(exc)

Here is the caller graph for this function:

Reimplemented from xml.sax.xmlreader.Locator.

Definition at line 286 of file expatreader.py.

00286 
00287     def getColumnNumber(self):
00288         if self._parser is None:
00289             return None
00290         return self._parser.ErrorColumnNumber

Definition at line 34 of file xmlreader.py.

00034 
00035     def getContentHandler(self):
00036         "Returns the current ContentHandler."
00037         return self._cont_handler

def xml.sax.xmlreader.XMLReader.getDTDHandler (   self) [inherited]

Definition at line 42 of file xmlreader.py.

00042 
00043     def getDTDHandler(self):
00044         "Returns the current DTD handler."
00045         return self._dtd_handler

Definition at line 50 of file xmlreader.py.

00050 
00051     def getEntityResolver(self):
00052         "Returns the current EntityResolver."
00053         return self._ent_handler

def xml.sax.xmlreader.XMLReader.getErrorHandler (   self) [inherited]

Definition at line 58 of file xmlreader.py.

00058 
00059     def getErrorHandler(self):
00060         "Returns the current ErrorHandler."
00061         return self._err_handler

def xml.sax.expatreader.ExpatParser.getFeature (   self,
  name 
)

Reimplemented from xml.sax.xmlreader.XMLReader.

Definition at line 120 of file expatreader.py.

00120 
00121     def getFeature(self, name):
00122         if name == feature_namespaces:
00123             return self._namespaces
00124         elif name == feature_string_interning:
00125             return self._interning is not None
00126         elif name in (feature_validation, feature_external_pes,
00127                       feature_namespace_prefixes):
00128             return 0
00129         elif name == feature_external_ges:
00130             return self._external_ges
00131         raise SAXNotRecognizedException("Feature '%s' not recognized" % name)

Reimplemented from xml.sax.xmlreader.Locator.

Definition at line 291 of file expatreader.py.

00291 
00292     def getLineNumber(self):
00293         if self._parser is None:
00294             return 1
00295         return self._parser.ErrorLineNumber

def xml.sax.expatreader.ExpatParser.getProperty (   self,
  name 
)

Reimplemented from xml.sax.xmlreader.XMLReader.

Definition at line 162 of file expatreader.py.

00162 
00163     def getProperty(self, name):
00164         if name == handler.property_lexical_handler:
00165             return self._lex_handler_prop
00166         elif name == property_interning_dict:
00167             return self._interning
00168         elif name == property_xml_string:
00169             if self._parser:
00170                 if hasattr(self._parser, "GetInputContext"):
00171                     return self._parser.GetInputContext()
00172                 else:
00173                     raise SAXNotRecognizedException(
00174                         "This version of expat does not support getting"
00175                         " the XML string")
00176             else:
00177                 raise SAXNotSupportedException(
00178                     "XML string cannot be returned when not parsing")
00179         raise SAXNotRecognizedException("Property '%s' not recognized" % name)

Reimplemented from xml.sax.xmlreader.Locator.

Definition at line 296 of file expatreader.py.

00296 
00297     def getPublicId(self):
00298         return self._source.getPublicId()

Reimplemented from xml.sax.xmlreader.Locator.

Definition at line 299 of file expatreader.py.

00299 
00300     def getSystemId(self):
00301         return self._source.getSystemId()

def xml.sax.expatreader.ExpatParser.notation_decl (   self,
  name,
  base,
  sysid,
  pubid 
)

Definition at line 374 of file expatreader.py.

00374 
00375     def notation_decl(self, name, base, sysid, pubid):
00376         self._dtd_handler.notationDecl(name, pubid, sysid)

Here is the caller graph for this function:

def xml.sax.expatreader.ExpatParser.parse (   self,
  source 
)

Reimplemented from xml.sax.xmlreader.IncrementalParser.

Definition at line 100 of file expatreader.py.

00100 
00101     def parse(self, source):
00102         "Parse an XML document from a URL or an InputSource."
00103         source = saxutils.prepare_input_source(source)
00104 
00105         self._source = source
00106         self.reset()
00107         self._cont_handler.setDocumentLocator(ExpatLocator(self))
00108         xmlreader.IncrementalParser.parse(self, source)

Here is the caller graph for this function:

def xml.sax.expatreader.ExpatParser.prepareParser (   self,
  source 
)
This method is called by the parse implementation to allow
the SAX 2.0 driver to prepare itself for parsing.

Reimplemented from xml.sax.xmlreader.IncrementalParser.

Definition at line 109 of file expatreader.py.

00109 
00110     def prepareParser(self, source):
00111         if source.getSystemId() is not None:
00112             self._parser.SetBase(source.getSystemId())

Here is the caller graph for this function:

def xml.sax.expatreader.ExpatParser.processing_instruction (   self,
  target,
  data 
)

Definition at line 355 of file expatreader.py.

00355 
00356     def processing_instruction(self, target, data):
00357         self._cont_handler.processingInstruction(target, data)

This method is called after close has been called to reset
the parser so that it is ready to parse new documents. The
results of calling parse or feed after close without calling
reset are undefined.

Reimplemented from xml.sax.xmlreader.IncrementalParser.

Definition at line 247 of file expatreader.py.

00247 
00248     def reset(self):
00249         if self._namespaces:
00250             self._parser = expat.ParserCreate(self._source.getEncoding(), " ",
00251                                               intern=self._interning)
00252             self._parser.namespace_prefixes = 1
00253             self._parser.StartElementHandler = self.start_element_ns
00254             self._parser.EndElementHandler = self.end_element_ns
00255         else:
00256             self._parser = expat.ParserCreate(self._source.getEncoding(),
00257                                               intern = self._interning)
00258             self._parser.StartElementHandler = self.start_element
00259             self._parser.EndElementHandler = self.end_element
00260 
00261         self._reset_cont_handler()
00262         self._parser.UnparsedEntityDeclHandler = self.unparsed_entity_decl
00263         self._parser.NotationDeclHandler = self.notation_decl
00264         self._parser.StartNamespaceDeclHandler = self.start_namespace_decl
00265         self._parser.EndNamespaceDeclHandler = self.end_namespace_decl
00266 
00267         self._decl_handler_prop = None
00268         if self._lex_handler_prop:
00269             self._reset_lex_handler_prop()
00270 #         self._parser.DefaultHandler =
00271 #         self._parser.DefaultHandlerExpand =
00272 #         self._parser.NotStandaloneHandler =
00273         self._parser.ExternalEntityRefHandler = self.external_entity_ref
00274         try:
00275             self._parser.SkippedEntityHandler = self.skipped_entity_handler
00276         except AttributeError:
00277             # This pyexpat does not support SkippedEntity
00278             pass
00279         self._parser.SetParamEntityParsing(
00280             expat.XML_PARAM_ENTITY_PARSING_UNLESS_STANDALONE)
00281 
00282         self._parsing = 0
00283         self._entity_stack = []

Here is the call graph for this function:

Here is the caller graph for this function:

Reimplemented from xml.sax.xmlreader.XMLReader.

Definition at line 115 of file expatreader.py.

00115 
00116     def setContentHandler(self, handler):
00117         xmlreader.IncrementalParser.setContentHandler(self, handler)
00118         if self._parsing:
00119             self._reset_cont_handler()

Here is the call graph for this function:

def xml.sax.xmlreader.XMLReader.setDTDHandler (   self,
  handler 
) [inherited]

Definition at line 46 of file xmlreader.py.

00046 
00047     def setDTDHandler(self, handler):
00048         "Register an object to receive basic DTD-related events."
00049         self._dtd_handler = handler

def xml.sax.xmlreader.XMLReader.setEntityResolver (   self,
  resolver 
) [inherited]

Definition at line 54 of file xmlreader.py.

00054 
00055     def setEntityResolver(self, resolver):
00056         "Register an object to resolve external entities."
00057         self._ent_handler = resolver

def xml.sax.xmlreader.XMLReader.setErrorHandler (   self,
  handler 
) [inherited]

Definition at line 62 of file xmlreader.py.

00062 
00063     def setErrorHandler(self, handler):
00064         "Register an object to receive error-message events."
00065         self._err_handler = handler

def xml.sax.expatreader.ExpatParser.setFeature (   self,
  name,
  state 
)

Reimplemented from xml.sax.xmlreader.XMLReader.

Definition at line 132 of file expatreader.py.

00132 
00133     def setFeature(self, name, state):
00134         if self._parsing:
00135             raise SAXNotSupportedException("Cannot set features while parsing")
00136 
00137         if name == feature_namespaces:
00138             self._namespaces = state
00139         elif name == feature_external_ges:
00140             self._external_ges = state
00141         elif name == feature_string_interning:
00142             if state:
00143                 if self._interning is None:
00144                     self._interning = {}
00145             else:
00146                 self._interning = None
00147         elif name == feature_validation:
00148             if state:
00149                 raise SAXNotSupportedException(
00150                     "expat does not support validation")
00151         elif name == feature_external_pes:
00152             if state:
00153                 raise SAXNotSupportedException(
00154                     "expat does not read external parameter entities")
00155         elif name == feature_namespace_prefixes:
00156             if state:
00157                 raise SAXNotSupportedException(
00158                     "expat does not report namespace prefixes")
00159         else:
00160             raise SAXNotRecognizedException(
00161                 "Feature '%s' not recognized" % name)

def xml.sax.xmlreader.XMLReader.setLocale (   self,
  locale 
) [inherited]
Allow an application to set the locale for errors and warnings.

SAX parsers are not required to provide localization for errors
and warnings; if they cannot support the requested locale,
however, they must throw a SAX exception. Applications may
request a locale change in the middle of a parse.

Reimplemented in xml.sax.saxutils.XMLFilterBase.

Definition at line 66 of file xmlreader.py.

00066 
00067     def setLocale(self, locale):
00068         """Allow an application to set the locale for errors and warnings.
00069 
00070         SAX parsers are not required to provide localization for errors
00071         and warnings; if they cannot support the requested locale,
00072         however, they must throw a SAX exception. Applications may
00073         request a locale change in the middle of a parse."""
00074         raise SAXNotSupportedException("Locale support not implemented")

def xml.sax.expatreader.ExpatParser.setProperty (   self,
  name,
  value 
)

Reimplemented from xml.sax.xmlreader.XMLReader.

Definition at line 180 of file expatreader.py.

00180 
00181     def setProperty(self, name, value):
00182         if name == handler.property_lexical_handler:
00183             self._lex_handler_prop = value
00184             if self._parsing:
00185                 self._reset_lex_handler_prop()
00186         elif name == property_interning_dict:
00187             self._interning = value
00188         elif name == property_xml_string:
00189             raise SAXNotSupportedException("Property '%s' cannot be set" %
00190                                            name)
00191         else:
00192             raise SAXNotRecognizedException("Property '%s' not recognized" %
00193                                             name)

Here is the call graph for this function:

def xml.sax.expatreader.ExpatParser.skipped_entity_handler (   self,
  name,
  is_pe 
)

Definition at line 399 of file expatreader.py.

00399 
00400     def skipped_entity_handler(self, name, is_pe):
00401         if is_pe:
00402             # The SAX spec requires to report skipped PEs with a '%'
00403             name = '%'+name
00404         self._cont_handler.skippedEntity(name)
00405 
00406 # ---

def xml.sax.expatreader.ExpatParser.start_doctype_decl (   self,
  name,
  sysid,
  pubid,
  has_internal_subset 
)

Definition at line 368 of file expatreader.py.

00368 
00369     def start_doctype_decl(self, name, sysid, pubid, has_internal_subset):
00370         self._lex_handler_prop.startDTD(name, pubid, sysid)

Here is the caller graph for this function:

def xml.sax.expatreader.ExpatParser.start_element (   self,
  name,
  attrs 
)

Definition at line 303 of file expatreader.py.

00303 
00304     def start_element(self, name, attrs):
00305         self._cont_handler.startElement(name, AttributesImpl(attrs))

Here is the caller graph for this function:

def xml.sax.expatreader.ExpatParser.start_element_ns (   self,
  name,
  attrs 
)

Definition at line 309 of file expatreader.py.

00309 
00310     def start_element_ns(self, name, attrs):
00311         pair = name.split()
00312         if len(pair) == 1:
00313             # no namespace
00314             pair = (None, name)
00315         elif len(pair) == 3:
00316             pair = pair[0], pair[1]
00317         else:
00318             # default namespace
00319             pair = tuple(pair)
00320 
00321         newattrs = {}
00322         qnames = {}
00323         for (aname, value) in attrs.items():
00324             parts = aname.split()
00325             length = len(parts)
00326             if length == 1:
00327                 # no namespace
00328                 qname = aname
00329                 apair = (None, aname)
00330             elif length == 3:
00331                 qname = "%s:%s" % (parts[2], parts[1])
00332                 apair = parts[0], parts[1]
00333             else:
00334                 # default namespace
00335                 qname = parts[1]
00336                 apair = tuple(parts)
00337 
00338             newattrs[apair] = value
00339             qnames[apair] = qname
00340 
00341         self._cont_handler.startElementNS(pair, None,
00342                                           AttributesNSImpl(newattrs, qnames))

Here is the caller graph for this function:

def xml.sax.expatreader.ExpatParser.start_namespace_decl (   self,
  prefix,
  uri 
)

Definition at line 362 of file expatreader.py.

00362 
00363     def start_namespace_decl(self, prefix, uri):
00364         self._cont_handler.startPrefixMapping(prefix, uri)

Here is the caller graph for this function:

def xml.sax.expatreader.ExpatParser.unparsed_entity_decl (   self,
  name,
  base,
  sysid,
  pubid,
  notation_name 
)

Definition at line 371 of file expatreader.py.

00371 
00372     def unparsed_entity_decl(self, name, base, sysid, pubid, notation_name):
00373         self._dtd_handler.unparsedEntityDecl(name, pubid, sysid, notation_name)

Here is the caller graph for this function:


Member Data Documentation

Definition at line 266 of file expatreader.py.

Definition at line 94 of file expatreader.py.

Definition at line 95 of file expatreader.py.

Definition at line 96 of file expatreader.py.

Definition at line 92 of file expatreader.py.

Definition at line 91 of file expatreader.py.

Definition at line 90 of file expatreader.py.

Definition at line 93 of file expatreader.py.

Definition at line 89 of file expatreader.py.


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