Commit 6f6d51d0 authored by Fred Drake's avatar Fred Drake

Remove two unnecessary imports.

Update the module docstring to reflect the actual list of modules in the
xml.sax package.

Make the code better conform to the Python style guide.
parent c40cdf72
...@@ -7,42 +7,42 @@ documented at <...>. ...@@ -7,42 +7,42 @@ documented at <...>.
This package contains the following modules: This package contains the following modules:
saxutils -- Implementation of the convenience functions normally used handler -- Base classes and constants which define the SAX 2 API for
to work with SAX. the 'client-side' of SAX for Python.
saxlib -- Implementation of the shared SAX 2 classes. saxutils -- Implementation of the convenience classes commonly used to
work with SAX.
drv_pyexpat -- Driver that allows use of the Expat parser with the classes xmlreader -- Base classes and constants which define the SAX 2 API for
defined in saxlib. the parsers used with SAX for Python.
expatreader -- Driver that allows use of the Expat parser with the
classes defined in saxlib.
""" """
from handler import ContentHandler, ErrorHandler from handler import ContentHandler, ErrorHandler
from expatreader import ExpatParser from expatreader import ExpatParser
from _exceptions import SAXException, SAXNotRecognizedException, \ from _exceptions import SAXException, SAXNotRecognizedException, \
SAXParseException, SAXNotSupportedException SAXParseException, SAXNotSupportedException
import xmlreader
import saxutils
def parse( filename_or_stream, handler, errorHandler=ErrorHandler() ): def parse(filename_or_stream, handler, errorHandler=ErrorHandler()):
parser=ExpatParser() parser = ExpatParser()
parser.setContentHandler( handler ) parser.setContentHandler(handler)
parser.setErrorHandler( errorHandler ) parser.setErrorHandler(errorHandler)
parser.parse( filename_or_stream ) parser.parse(filename_or_stream)
def parseString( string, handler, errorHandler=ErrorHandler() ):
def parseString(string, handler, errorHandler=ErrorHandler()):
try: try:
import cStringIO from cStringIO import StringIO
stringio=cStringIO.StringIO
except ImportError: except ImportError:
import StringIO from StringIO import StringIO
stringio=StringIO.StringIO
bufsize=len( string ) if errorHandler is None:
buf=stringio( string ) errorHandler = ErrorHandler()
parser = ExpatParser()
parser=ExpatParser() parser.setContentHandler(handler)
parser.setContentHandler( handler ) parser.setErrorHandler(errorHandler)
parser.setErrorHandler( errorHandler ) parser.parse(StringIO(string))
parser.parse( buf )
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment