mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
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.
This commit is contained in:
parent
c40cdf7238
commit
6f6d51d050
1 changed files with 26 additions and 26 deletions
|
@ -7,42 +7,42 @@ documented at <...>.
|
|||
|
||||
This package contains the following modules:
|
||||
|
||||
saxutils -- Implementation of the convenience functions normally used
|
||||
to work with SAX.
|
||||
handler -- Base classes and constants which define the SAX 2 API for
|
||||
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
|
||||
defined in saxlib.
|
||||
xmlreader -- Base classes and constants which define the SAX 2 API for
|
||||
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 expatreader import ExpatParser
|
||||
from _exceptions import SAXException, SAXNotRecognizedException, \
|
||||
SAXParseException, SAXNotSupportedException
|
||||
import xmlreader
|
||||
import saxutils
|
||||
SAXParseException, SAXNotSupportedException
|
||||
|
||||
def parse( filename_or_stream, handler, errorHandler=ErrorHandler() ):
|
||||
parser=ExpatParser()
|
||||
parser.setContentHandler( handler )
|
||||
parser.setErrorHandler( errorHandler )
|
||||
parser.parse( filename_or_stream )
|
||||
|
||||
def parseString( string, handler, errorHandler=ErrorHandler() ):
|
||||
def parse(filename_or_stream, handler, errorHandler=ErrorHandler()):
|
||||
parser = ExpatParser()
|
||||
parser.setContentHandler(handler)
|
||||
parser.setErrorHandler(errorHandler)
|
||||
parser.parse(filename_or_stream)
|
||||
|
||||
|
||||
def parseString(string, handler, errorHandler=ErrorHandler()):
|
||||
try:
|
||||
import cStringIO
|
||||
stringio=cStringIO.StringIO
|
||||
from cStringIO import StringIO
|
||||
except ImportError:
|
||||
import StringIO
|
||||
stringio=StringIO.StringIO
|
||||
from StringIO import StringIO
|
||||
|
||||
bufsize=len( string )
|
||||
buf=stringio( string )
|
||||
|
||||
parser=ExpatParser()
|
||||
parser.setContentHandler( handler )
|
||||
parser.setErrorHandler( errorHandler )
|
||||
parser.parse( buf )
|
||||
|
||||
if errorHandler is None:
|
||||
errorHandler = ErrorHandler()
|
||||
parser = ExpatParser()
|
||||
parser.setContentHandler(handler)
|
||||
parser.setErrorHandler(errorHandler)
|
||||
parser.parse(StringIO(string))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue