<s> """<STR_LIT>""" <EOL> from xmlreader import InputSource <EOL> from handler import ContentHandler , ErrorHandler <EOL> from _exceptions import SAXException , SAXNotRecognizedException , SAXParseException , SAXNotSupportedException , SAXReaderNotAvailable <EOL> def parse ( source , handler , errorHandler = ErrorHandler ( ) ) : <EOL> parser = make_parser ( ) <EOL> parser . setContentHandler ( handler ) <EOL> parser . setErrorHandler ( errorHandler ) <EOL> parser . parse ( source ) <EOL> def parseString ( string , handler , errorHandler = ErrorHandler ( ) ) : <EOL> try : <EOL> from cStringIO import StringIO <EOL> except ImportError : <EOL> from StringIO import StringIO <EOL> if errorHandler is None : <EOL> errorHandler = ErrorHandler ( ) <EOL> parser = make_parser ( ) <EOL> parser . setContentHandler ( handler ) <EOL> parser . setErrorHandler ( errorHandler ) <EOL> inpsrc = InputSource ( ) <EOL> inpsrc . setByteStream ( StringIO ( string ) ) <EOL> parser . parse ( inpsrc ) <EOL> default_parser_list = [ "<STR_LIT>" ] <EOL> _false = <NUM_LIT:0> <EOL> if _false : <EOL> import xml . sax . drivers2 . drv_javasax <EOL> import os , sys <EOL> if os . environ . has_key ( "<STR_LIT>" ) : <EOL> default_parser_list = os . environ [ "<STR_LIT>" ] . split ( "<STR_LIT:U+002C>" ) <EOL> del os <EOL> _key = "<STR_LIT>" <EOL> if sys . platform [ : <NUM_LIT:4> ] == "<STR_LIT>" and sys . registry . containsKey ( _key ) : <EOL> default_parser_list = sys . registry . getProperty ( _key ) . split ( "<STR_LIT:U+002C>" ) <EOL> def make_parser ( parser_list = [ ] ) : <EOL> """<STR_LIT>""" <EOL> for parser_name in parser_list + default_parser_list : <EOL> try : <EOL> return _create_parser ( parser_name ) <EOL> except ImportError , e : <EOL> import sys <EOL> if sys . modules . has_key ( parser_name ) : <EOL> raise <EOL> except SAXReaderNotAvailable : <EOL> pass <EOL> raise SAXReaderNotAvailable ( "<STR_LIT>" , None ) <EOL> def _create_parser ( parser_name ) : <EOL> drv_module = __import__ ( parser_name , { } , { } , [ '<STR_LIT>' ] ) <EOL> return drv_module . create_parser ( ) <EOL> del sys </s>
