<s> __all__ = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:error>" , "<STR_LIT>" ] <EOL> import sys <EOL> if not sys . platform . startswith ( '<STR_LIT>' ) : <EOL> raise ImportError ( "<STR_LIT>" ) <EOL> import re <EOL> import types <EOL> from org . python . core import Py <EOL> from org . python . core . util import StringUtil <EOL> from jarray import array <EOL> from java . io import ByteArrayInputStream <EOL> from java . lang import String , StringBuilder <EOL> from org . xml . sax import InputSource <EOL> from org . xml . sax import SAXNotRecognizedException , SAXParseException <EOL> from org . xml . sax . helpers import XMLReaderFactory <EOL> from org . xml . sax . ext import DefaultHandler2 <EOL> try : <EOL> import org . python . apache . xerces . parsers . SAXParser <EOL> _xerces_parser = "<STR_LIT>" <EOL> except ImportError : <EOL> _xerces_parser = "<STR_LIT>" <EOL> _register = { } <EOL> def ParserCreate ( encoding = None , namespace_separator = None ) : <EOL> return XMLParser ( encoding , namespace_separator ) <EOL> class XMLParser ( object ) : <EOL> def __init__ ( self , encoding , namespace_separator ) : <EOL> self . encoding = encoding <EOL> self . CurrentLineNumber = <NUM_LIT:1> <EOL> self . CurrentColumnNumber = <NUM_LIT:0> <EOL> self . _NextLineNumber = <NUM_LIT:1> <EOL> self . _NextColumnNumber = <NUM_LIT:0> <EOL> self . ErrorLineNumber = - <NUM_LIT:1> <EOL> self . ErrorColumnNumber = - <NUM_LIT:1> <EOL> self . ErrorCode = None <EOL> if namespace_separator is None : <EOL> self . namespace_separator = namespace_separator <EOL> elif isinstance ( namespace_separator , basestring ) : <EOL> self . namespace_separator = str ( namespace_separator ) <EOL> if len ( self . namespace_separator ) > <NUM_LIT:1> : <EOL> error = ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> raise ValueError ( error ) <EOL> else : <EOL> error = ( "<STR_LIT>" <EOL> "<STR_LIT>" % type ( namespace_separator ) . __name__ ) <EOL> raise TypeError ( error ) <EOL> self . _reader = XMLReaderFactory . createXMLReader ( _xerces_parser ) <EOL> if self . namespace_separator is None : <EOL> try : <EOL> feature = "<STR_LIT>" <EOL> self . _reader . setFeature ( feature , False ) <EOL> except SAXNotRecognizedException : <EOL> error = ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> raise ValueError ( error ) <EOL> self . _base = None <EOL> self . _buffer_text = True <EOL> self . _returns_unicode = True <EOL> self . _data = StringBuilder ( ) <EOL> self . _handler = XMLEventHandler ( self ) <EOL> self . _reader . setContentHandler ( self . _handler ) <EOL> self . _reader . setErrorHandler ( self . _handler ) <EOL> self . _reader . setDTDHandler ( self . _handler ) <EOL> self . _reader . setEntityResolver ( self . _handler ) <EOL> sax_properties = ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> for name in sax_properties : <EOL> try : <EOL> name = "<STR_LIT>" + name <EOL> self . _reader . setProperty ( name , self . _handler ) <EOL> except SAXNotRecognizedException : <EOL> error = "<STR_LIT>" % name <EOL> raise NotImplementedError ( error ) <EOL> apache_features = ( ( "<STR_LIT>" , False ) , ) <EOL> for name , value in apache_features : <EOL> try : <EOL> name = "<STR_LIT>" + name <EOL> self . _reader . setFeature ( name , value ) <EOL> except SAXNotRecognizedException : <EOL> error = "<STR_LIT>" % name <EOL> raise NotImplementedError ( error ) <EOL> f = "<STR_LIT>" <EOL> f = "<STR_LIT>" <EOL> assert self . _reader . getFeature ( f ) <EOL> def GetBase ( self ) : <EOL> return self . _base <EOL> def SetBase ( self , base ) : <EOL> self . _base = base <EOL> def _error ( self , value = None ) : <EOL> raise AttributeError ( "<STR_LIT>" ) <EOL> def _get_buffer_text ( self ) : <EOL> return self . _buffer_text <EOL> def _set_buffer_text ( self , value ) : <EOL> self . _buffer_text = bool ( value ) <EOL> def _get_returns_unicode ( self ) : <EOL> return bool ( self . _returns_unicode ) <EOL> def _set_returns_unicode ( self , value ) : <EOL> self . _returns_unicode = value <EOL> ordered_attributes = property ( _error , _error ) <EOL> specified_attributes = property ( _error , _error ) <EOL> buffer_text = property ( _get_buffer_text , _set_buffer_text ) <EOL> buffer_used = property ( lambda self : None ) <EOL> buffer_size = property ( lambda self : None ) <EOL> returns_unicode = property ( _get_returns_unicode , _set_returns_unicode ) <EOL> def _expat_error ( self , sax_error ) : <EOL> sax_message = sax_error . getMessage ( ) <EOL> pattern = '<STR_LIT>' <EOL> if re . match ( pattern , sax_message ) : <EOL> expat_message = "<STR_LIT>" % ( self . ErrorLineNumber , self . ErrorColumnNumber ) <EOL> else : <EOL> expat_message = sax_message <EOL> error = ExpatError ( expat_message ) <EOL> error . lineno = self . ErrorLineNumber <EOL> error . offset = self . ErrorColumnNumber <EOL> error . code = self . ErrorCode <EOL> return error <EOL> def Parse ( self , data , isfinal = False ) : <EOL> if isinstance ( data , unicode ) : <EOL> data = data . encode ( sys . getdefaultencoding ( ) ) <EOL> self . _data . append ( data ) <EOL> if isfinal : <EOL> bytes = StringUtil . toBytes ( self . _data . toString ( ) ) <EOL> byte_stream = ByteArrayInputStream ( bytes ) <EOL> source = InputSource ( byte_stream ) <EOL> if self . encoding is not None : <EOL> source . setEncoding ( self . encoding ) <EOL> try : <EOL> self . _reader . parse ( source ) <EOL> except SAXParseException , sax_error : <EOL> self . ErrorLineNumber = self . _NextLineNumber <EOL> self . ErrorColumnNumber = self . _NextColumnNumber <EOL> self . ErrorCode = None <EOL> raise self . _expat_error ( sax_error ) <EOL> return <NUM_LIT:1> <EOL> def ParseFile ( self , file ) : <EOL> return self . Parse ( file . read ( ) , isfinal = True ) <EOL> XMLParserType = XMLParser <EOL> def _encode ( arg , encoding ) : <EOL> if isinstance ( arg , unicode ) : <EOL> return arg . encode ( encoding ) <EOL> else : <EOL> if isinstance ( arg , dict ) : <EOL> iterator = arg . iteritems ( ) <EOL> else : <EOL> iterator = iter ( arg ) <EOL> return type ( arg ) ( _encode ( _arg , encoding ) for _arg in iterator ) <EOL> def expat ( callback = None , guard = True , force = False , returns = None ) : <EOL> def _expat ( method ) : <EOL> name = method . __name__ <EOL> context = id ( sys . _getframe ( <NUM_LIT:1> ) ) <EOL> key = name , context <EOL> append = _register . setdefault ( key , [ ] ) . append <EOL> append ( ( method , callback , guard , force , returns ) ) <EOL> def new_method ( * args ) : <EOL> self = args [ <NUM_LIT:0> ] <EOL> parser = self . parser <EOL> self . _update_location ( event = name ) <EOL> for ( method , callback , guard , force , returns ) in _register [ key ] : <EOL> if guard not in ( True , False ) : <EOL> guard = getattr ( self , guard ) <EOL> _callback = callback and guard and getattr ( parser , callback , None ) <EOL> if _callback or force : <EOL> results = method ( * args ) <EOL> if _callback : <EOL> if not isinstance ( results , tuple ) : <EOL> results = ( results , ) <EOL> if not parser . returns_unicode : <EOL> results = _encode ( results , "<STR_LIT:utf-8>" ) <EOL> _callback ( * results ) <EOL> return returns <EOL> new_method . __name__ = name <EOL> return new_method <EOL> return _expat <EOL> class XMLEventHandler ( DefaultHandler2 ) : <EOL> def __init__ ( self , parser ) : <EOL> self . parser = parser <EOL> self . _tags = { } <EOL> self . not_in_dtd = True <EOL> self . _entity = { } <EOL> self . _previous_event = None <EOL> def _intern ( self , tag ) : <EOL> return self . _tags . setdefault ( tag , tag ) <EOL> def _qualify ( self , local_name , qname , namespace = None ) : <EOL> namespace_separator = self . parser . namespace_separator <EOL> if namespace_separator is None : <EOL> return qname <EOL> if not namespace : <EOL> return local_name <EOL> else : <EOL> return namespace + namespace_separator + local_name <EOL> def _char_slice_to_unicode ( self , characters , start , length ) : <EOL> """<STR_LIT>""" <EOL> text = Py . newUnicode ( String ( characters [ start : start + length ] ) ) <EOL> return text <EOL> def _expat_content_model ( self , name , model_ ) : <EOL> return ( name , model_ ) <EOL> def _update_location ( self , event = None ) : <EOL> parser = self . parser <EOL> locator = self . _locator <EOL> if event == "<STR_LIT>" and self . _previous_event == "<STR_LIT>" : <EOL> parser . _NextColumnNumber = max ( parser . _NextColumnNumber - <NUM_LIT:1> , <NUM_LIT:0> ) <EOL> if event == "<STR_LIT>" and self . _previous_event == "<STR_LIT>" : <EOL> parser . _NextColumnNumber = max ( parser . _NextColumnNumber - <NUM_LIT:2> , <NUM_LIT:0> ) <EOL> parser . CurrentLineNumber = parser . _NextLineNumber <EOL> parser . CurrentColumnNumber = parser . _NextColumnNumber <EOL> parser . _NextLineNumber = locator . getLineNumber ( ) <EOL> parser . _NextColumnNumber = locator . getColumnNumber ( ) - <NUM_LIT:1> <EOL> self . _previous_event = event <EOL> @ expat ( "<STR_LIT>" ) <EOL> def processingInstruction ( self , target , data ) : <EOL> return target , data <EOL> @ expat ( "<STR_LIT>" ) <EOL> def startElement ( self , namespace , local_name , qname , attributes ) : <EOL> tag = self . _qualify ( local_name , qname , namespace ) <EOL> attribs = { } <EOL> length = attributes . getLength ( ) <EOL> for index in range ( length ) : <EOL> local_name = attributes . getLocalName ( index ) <EOL> qname = attributes . getQName ( index ) <EOL> namespace = attributes . getURI ( index ) <EOL> name = self . _qualify ( local_name , qname , namespace ) <EOL> value = attributes . getValue ( index ) <EOL> attribs [ name ] = value <EOL> return self . _intern ( tag ) , attribs <EOL> @ expat ( "<STR_LIT>" ) <EOL> def endElement ( self , namespace , local_name , qname ) : <EOL> return self . _intern ( self . _qualify ( local_name , qname , namespace ) ) <EOL> @ expat ( "<STR_LIT>" ) <EOL> def characters ( self , characters , start , length ) : <EOL> return self . _char_slice_to_unicode ( characters , start , length ) <EOL> @ expat ( "<STR_LIT>" ) <EOL> def characters ( self , characters , start , length ) : <EOL> return self . _char_slice_to_unicode ( characters , start , length ) <EOL> @ expat ( "<STR_LIT>" ) <EOL> def characters ( self , characters , start , length ) : <EOL> if self . _entity [ "<STR_LIT:location>" ] == ( self . parser . CurrentLineNumber , <EOL> self . parser . CurrentColumnNumber ) : <EOL> return "<STR_LIT>" % self . _entity [ "<STR_LIT:name>" ] <EOL> else : <EOL> return self . _char_slice_to_unicode ( characters , start , length ) <EOL> @ expat ( "<STR_LIT>" ) <EOL> def startPrefixMapping ( self , prefix , uri ) : <EOL> return prefix , uri <EOL> @ expat ( "<STR_LIT>" ) <EOL> def endPrefixMapping ( self , prefix ) : <EOL> return prefix <EOL> empty_source = InputSource ( ByteArrayInputStream ( array ( [ ] , "<STR_LIT:b>" ) ) ) <EOL> @ expat ( "<STR_LIT>" , guard = "<STR_LIT>" , <EOL> returns = empty_source ) <EOL> def resolveEntity ( self , name , publicId , baseURI , systemId ) : <EOL> context = name <EOL> base = self . parser . GetBase ( ) <EOL> return context , base , systemId , publicId <EOL> @ expat ( "<STR_LIT>" , guard = "<STR_LIT>" , <EOL> returns = empty_source ) <EOL> def resolveEntity ( self , name , publicId , baseURI , systemId ) : <EOL> return "<STR_LIT>" % name <EOL> @ expat ( "<STR_LIT>" , guard = "<STR_LIT>" , <EOL> returns = empty_source ) <EOL> def resolveEntity ( self , name , publicId , baseURI , systemId ) : <EOL> return "<STR_LIT>" % name <EOL> @ expat ( force = True , returns = empty_source ) <EOL> def resolveEntity ( self , name , publicId , baseURI , systemId ) : <EOL> pass <EOL> def setDocumentLocator ( self , locator ) : <EOL> self . _locator = locator <EOL> def skippedEntity ( self , name ) : <EOL> error = ExpatError ( ) <EOL> error . lineno = self . ErrorLineNumber = self . parser . _NextLineNumber <EOL> error . offset = self . ErrorColumnNumber = self . parser . _NextColumnNumber <EOL> error . code = self . ErrorCode = None <EOL> message = "<STR_LIT>" <EOL> message = message % ( name , error . lineno , error . offset ) <EOL> error . __init__ ( message ) <EOL> raise error <EOL> @ expat ( "<STR_LIT>" ) <EOL> def comment ( self , characters , start , length ) : <EOL> return self . _char_slice_to_unicode ( characters , start , length ) <EOL> @ expat ( "<STR_LIT>" ) <EOL> def startCDATA ( self ) : <EOL> return ( ) <EOL> @ expat ( "<STR_LIT>" ) <EOL> def endCDATA ( self ) : <EOL> return ( ) <EOL> @ expat ( "<STR_LIT>" , force = True ) <EOL> def startDTD ( self , name , publicId , systemId ) : <EOL> self . not_in_dtd = False <EOL> has_internal_subset = <NUM_LIT:0> <EOL> return name , systemId , publicId , has_internal_subset <EOL> @ expat ( "<STR_LIT>" , force = True ) <EOL> def endDTD ( self ) : <EOL> self . not_in_dtd = True <EOL> def startEntity ( self , name ) : <EOL> self . _entity = { } <EOL> self . _entity [ "<STR_LIT:location>" ] = ( self . parser . _NextLineNumber , <EOL> self . parser . _NextColumnNumber ) <EOL> self . _entity [ "<STR_LIT:name>" ] = name <EOL> def endEntity ( self , name ) : <EOL> pass <EOL> @ expat ( "<STR_LIT>" ) <EOL> def notationDecl ( self , name , publicId , systemId ) : <EOL> base = self . parser . GetBase ( ) <EOL> return name , base , systemId , publicId <EOL> @ expat ( "<STR_LIT>" ) <EOL> def unparsedEntityDecl ( self , name , publicId , systemId , notationName ) : <EOL> base = self . parser . GetBase ( ) <EOL> return name , base , systemId , publicId , notationName <EOL> @ expat ( "<STR_LIT>" ) <EOL> def attributeDecl ( self , eName , aName , type , mode , value ) : <EOL> required = False <EOL> return eName , aName , type , value , required <EOL> @ expat ( "<STR_LIT>" ) <EOL> def elementDecl ( self , name , model ) : <EOL> return self . _expat_content_model ( name , model ) <EOL> @ expat ( "<STR_LIT>" ) <EOL> def externalEntityDecl ( self , name , publicId , systemId ) : <EOL> base = self . parser . GetBase ( ) <EOL> value = None <EOL> is_parameter_entity = None <EOL> notation_name = None <EOL> return ( name , is_parameter_entity , value , base , systemId , publicId , <EOL> notation_name ) <EOL> @ expat ( "<STR_LIT>" ) <EOL> def internalEntityDecl ( self , name , value ) : <EOL> base = self . parser . GetBase ( ) <EOL> is_parameter_entity = None <EOL> notation_name = None <EOL> systemId , publicId = None , None <EOL> return ( name , is_parameter_entity , value , base , systemId , publicId , <EOL> notation_name ) <EOL> def _init_model ( ) : <EOL> global model <EOL> model = types . ModuleType ( "<STR_LIT>" ) <EOL> model . __doc__ = "<STR_LIT>" <EOL> quantifiers = "<STR_LIT>" <EOL> for i , quantifier in enumerate ( quantifiers . split ( "<STR_LIT:U+002CU+0020>" ) ) : <EOL> setattr ( model , "<STR_LIT>" + quantifier , i ) <EOL> types_ = "<STR_LIT>" <EOL> for i , type_ in enumerate ( types_ . split ( "<STR_LIT:U+002CU+0020>" ) ) : <EOL> setattr ( model , "<STR_LIT>" + type_ , i + <NUM_LIT:1> ) <EOL> _init_model ( ) <EOL> del _init_model <EOL> class ExpatError ( Exception ) : <EOL> pass <EOL> error = ExpatError <EOL> def _init_error_strings ( ) : <EOL> global ErrorString <EOL> error_strings = ( <EOL> None , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" ) <EOL> def ErrorString ( code ) : <EOL> try : <EOL> return error_strings [ code ] <EOL> except IndexError : <EOL> return None <EOL> _init_error_strings ( ) <EOL> del _init_error_strings <EOL> def _init_errors ( ) : <EOL> global errors <EOL> errors = types . ModuleType ( "<STR_LIT>" ) <EOL> errors . __doc__ = "<STR_LIT>" <EOL> error_names = """<STR_LIT>""" <EOL> error_names = [ name . strip ( ) for name in error_names . split ( '<STR_LIT:U+002C>' ) ] <EOL> for i , name in enumerate ( error_names [ <NUM_LIT:1> : ] ) : <EOL> setattr ( errors , name , ErrorString ( i + <NUM_LIT:1> ) ) <EOL> _init_errors ( ) <EOL> del _init_errors </s>
