<s> """<STR_LIT>""" <EOL> import copy <EOL> import xml . dom <EOL> from xml . dom . NodeFilter import NodeFilter <EOL> __all__ = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> class Options : <EOL> """<STR_LIT>""" <EOL> namespaces = <NUM_LIT:1> <EOL> namespace_declarations = True <EOL> validation = False <EOL> external_parameter_entities = True <EOL> external_general_entities = True <EOL> external_dtd_subset = True <EOL> validate_if_schema = False <EOL> validate = False <EOL> datatype_normalization = False <EOL> create_entity_ref_nodes = True <EOL> entities = True <EOL> whitespace_in_element_content = True <EOL> cdata_sections = True <EOL> comments = True <EOL> charset_overrides_xml_encoding = True <EOL> infoset = False <EOL> supported_mediatypes_only = False <EOL> errorHandler = None <EOL> filter = None <EOL> class DOMBuilder : <EOL> entityResolver = None <EOL> errorHandler = None <EOL> filter = None <EOL> ACTION_REPLACE = <NUM_LIT:1> <EOL> ACTION_APPEND_AS_CHILDREN = <NUM_LIT:2> <EOL> ACTION_INSERT_AFTER = <NUM_LIT:3> <EOL> ACTION_INSERT_BEFORE = <NUM_LIT:4> <EOL> _legal_actions = ( ACTION_REPLACE , ACTION_APPEND_AS_CHILDREN , <EOL> ACTION_INSERT_AFTER , ACTION_INSERT_BEFORE ) <EOL> def __init__ ( self ) : <EOL> self . _options = Options ( ) <EOL> def _get_entityResolver ( self ) : <EOL> return self . entityResolver <EOL> def _set_entityResolver ( self , entityResolver ) : <EOL> self . entityResolver = entityResolver <EOL> def _get_errorHandler ( self ) : <EOL> return self . errorHandler <EOL> def _set_errorHandler ( self , errorHandler ) : <EOL> self . errorHandler = errorHandler <EOL> def _get_filter ( self ) : <EOL> return self . filter <EOL> def _set_filter ( self , filter ) : <EOL> self . filter = filter <EOL> def setFeature ( self , name , state ) : <EOL> if self . supportsFeature ( name ) : <EOL> state = state and <NUM_LIT:1> or <NUM_LIT:0> <EOL> try : <EOL> settings = self . _settings [ ( _name_xform ( name ) , state ) ] <EOL> except KeyError : <EOL> raise xml . dom . NotSupportedErr ( <EOL> "<STR_LIT>" % ( name , ) ) <EOL> else : <EOL> for name , value in settings : <EOL> setattr ( self . _options , name , value ) <EOL> else : <EOL> raise xml . dom . NotFoundErr ( "<STR_LIT>" + repr ( name ) ) <EOL> def supportsFeature ( self , name ) : <EOL> return hasattr ( self . _options , _name_xform ( name ) ) <EOL> def canSetFeature ( self , name , state ) : <EOL> key = ( _name_xform ( name ) , state and <NUM_LIT:1> or <NUM_LIT:0> ) <EOL> return key in self . _settings <EOL> _settings = { <EOL> ( "<STR_LIT>" , <NUM_LIT:0> ) : [ <EOL> ( "<STR_LIT>" , <NUM_LIT:0> ) ] , <EOL> ( "<STR_LIT>" , <NUM_LIT:1> ) : [ <EOL> ( "<STR_LIT>" , <NUM_LIT:1> ) ] , <EOL> ( "<STR_LIT>" , <NUM_LIT:0> ) : [ <EOL> ( "<STR_LIT>" , <NUM_LIT:0> ) ] , <EOL> ( "<STR_LIT>" , <NUM_LIT:0> ) : [ <EOL> ( "<STR_LIT>" , <NUM_LIT:0> ) ] , <EOL> ( "<STR_LIT>" , <NUM_LIT:1> ) : [ <EOL> ( "<STR_LIT>" , <NUM_LIT:1> ) ] , <EOL> ( "<STR_LIT>" , <NUM_LIT:0> ) : [ <EOL> ( "<STR_LIT>" , <NUM_LIT:0> ) ] , <EOL> ( "<STR_LIT>" , <NUM_LIT:1> ) : [ <EOL> ( "<STR_LIT>" , <NUM_LIT:1> ) ] , <EOL> ( "<STR_LIT>" , <NUM_LIT:0> ) : [ <EOL> ( "<STR_LIT>" , <NUM_LIT:0> ) ] , <EOL> ( "<STR_LIT>" , <NUM_LIT:0> ) : [ <EOL> ( "<STR_LIT>" , <NUM_LIT:0> ) ] , <EOL> ( "<STR_LIT>" , <NUM_LIT:1> ) : [ <EOL> ( "<STR_LIT>" , <NUM_LIT:1> ) ] , <EOL> ( "<STR_LIT>" , <NUM_LIT:0> ) : [ <EOL> ( "<STR_LIT>" , <NUM_LIT:0> ) , <EOL> ( "<STR_LIT>" , <NUM_LIT:0> ) ] , <EOL> ( "<STR_LIT>" , <NUM_LIT:1> ) : [ <EOL> ( "<STR_LIT>" , <NUM_LIT:1> ) ] , <EOL> ( "<STR_LIT>" , <NUM_LIT:0> ) : [ <EOL> ( "<STR_LIT>" , <NUM_LIT:0> ) ] , <EOL> ( "<STR_LIT>" , <NUM_LIT:1> ) : [ <EOL> ( "<STR_LIT>" , <NUM_LIT:1> ) ] , <EOL> ( "<STR_LIT>" , <NUM_LIT:0> ) : [ <EOL> ( "<STR_LIT>" , <NUM_LIT:0> ) ] , <EOL> ( "<STR_LIT>" , <NUM_LIT:1> ) : [ <EOL> ( "<STR_LIT>" , <NUM_LIT:1> ) ] , <EOL> ( "<STR_LIT>" , <NUM_LIT:0> ) : [ <EOL> ( "<STR_LIT>" , <NUM_LIT:0> ) ] , <EOL> ( "<STR_LIT>" , <NUM_LIT:1> ) : [ <EOL> ( "<STR_LIT>" , <NUM_LIT:1> ) ] , <EOL> ( "<STR_LIT>" , <NUM_LIT:0> ) : [ <EOL> ( "<STR_LIT>" , <NUM_LIT:0> ) ] , <EOL> ( "<STR_LIT>" , <NUM_LIT:1> ) : [ <EOL> ( "<STR_LIT>" , <NUM_LIT:1> ) ] , <EOL> ( "<STR_LIT>" , <NUM_LIT:0> ) : [ ] , <EOL> ( "<STR_LIT>" , <NUM_LIT:1> ) : [ <EOL> ( "<STR_LIT>" , <NUM_LIT:0> ) , <EOL> ( "<STR_LIT>" , <NUM_LIT:0> ) , <EOL> ( "<STR_LIT>" , <NUM_LIT:0> ) , <EOL> ( "<STR_LIT>" , <NUM_LIT:0> ) , <EOL> ( "<STR_LIT>" , <NUM_LIT:0> ) , <EOL> ( "<STR_LIT>" , <NUM_LIT:1> ) , <EOL> ( "<STR_LIT>" , <NUM_LIT:1> ) , <EOL> ( "<STR_LIT>" , <NUM_LIT:1> ) , <EOL> ( "<STR_LIT>" , <NUM_LIT:1> ) ] , <EOL> ( "<STR_LIT>" , <NUM_LIT:0> ) : [ <EOL> ( "<STR_LIT>" , <NUM_LIT:0> ) ] , <EOL> ( "<STR_LIT>" , <NUM_LIT:0> ) : [ <EOL> ( "<STR_LIT>" , <NUM_LIT:0> ) ] , <EOL> ( "<STR_LIT>" , <NUM_LIT:1> ) : [ <EOL> ( "<STR_LIT>" , <NUM_LIT:1> ) ] , <EOL> } <EOL> def getFeature ( self , name ) : <EOL> xname = _name_xform ( name ) <EOL> try : <EOL> return getattr ( self . _options , xname ) <EOL> except AttributeError : <EOL> if name == "<STR_LIT>" : <EOL> options = self . _options <EOL> return ( options . datatype_normalization <EOL> and options . whitespace_in_element_content <EOL> and options . comments <EOL> and options . charset_overrides_xml_encoding <EOL> and not ( options . namespace_declarations <EOL> or options . validate_if_schema <EOL> or options . create_entity_ref_nodes <EOL> or options . entities <EOL> or options . cdata_sections ) ) <EOL> raise xml . dom . NotFoundErr ( "<STR_LIT>" % repr ( name ) ) <EOL> def parseURI ( self , uri ) : <EOL> if self . entityResolver : <EOL> input = self . entityResolver . resolveEntity ( None , uri ) <EOL> else : <EOL> input = DOMEntityResolver ( ) . resolveEntity ( None , uri ) <EOL> return self . parse ( input ) <EOL> def parse ( self , input ) : <EOL> options = copy . copy ( self . _options ) <EOL> options . filter = self . filter <EOL> options . errorHandler = self . errorHandler <EOL> fp = input . byteStream <EOL> if fp is None and options . systemId : <EOL> import urllib . request <EOL> fp = urllib . request . urlopen ( input . systemId ) <EOL> return self . _parse_bytestream ( fp , options ) <EOL> def parseWithContext ( self , input , cnode , action ) : <EOL> if action not in self . _legal_actions : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> raise NotImplementedError ( "<STR_LIT>" ) <EOL> def _parse_bytestream ( self , stream , options ) : <EOL> import xml . dom . expatbuilder <EOL> builder = xml . dom . expatbuilder . makeBuilder ( options ) <EOL> return builder . parseFile ( stream ) <EOL> def _name_xform ( name ) : <EOL> return name . lower ( ) . replace ( '<STR_LIT:->' , '<STR_LIT:_>' ) <EOL> class DOMEntityResolver ( object ) : <EOL> __slots__ = '<STR_LIT>' , <EOL> def resolveEntity ( self , publicId , systemId ) : <EOL> assert systemId is not None <EOL> source = DOMInputSource ( ) <EOL> source . publicId = publicId <EOL> source . systemId = systemId <EOL> source . byteStream = self . _get_opener ( ) . open ( systemId ) <EOL> source . encoding = self . _guess_media_encoding ( source ) <EOL> import posixpath , urllib . parse <EOL> parts = urllib . parse . urlparse ( systemId ) <EOL> scheme , netloc , path , params , query , fragment = parts <EOL> if path and not path . endswith ( "<STR_LIT:/>" ) : <EOL> path = posixpath . dirname ( path ) + "<STR_LIT:/>" <EOL> parts = scheme , netloc , path , params , query , fragment <EOL> source . baseURI = urllib . parse . urlunparse ( parts ) <EOL> return source <EOL> def _get_opener ( self ) : <EOL> try : <EOL> return self . _opener <EOL> except AttributeError : <EOL> self . _opener = self . _create_opener ( ) <EOL> return self . _opener <EOL> def _create_opener ( self ) : <EOL> import urllib . request <EOL> return urllib . request . build_opener ( ) <EOL> def _guess_media_encoding ( self , source ) : <EOL> info = source . byteStream . info ( ) <EOL> if "<STR_LIT:Content-Type>" in info : <EOL> for param in info . getplist ( ) : <EOL> if param . startswith ( "<STR_LIT>" ) : <EOL> return param . split ( "<STR_LIT:=>" , <NUM_LIT:1> ) [ <NUM_LIT:1> ] . lower ( ) <EOL> class DOMInputSource ( object ) : <EOL> __slots__ = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> def __init__ ( self ) : <EOL> self . byteStream = None <EOL> self . characterStream = None <EOL> self . stringData = None <EOL> self . encoding = None <EOL> self . publicId = None <EOL> self . systemId = None <EOL> self . baseURI = None <EOL> def _get_byteStream ( self ) : <EOL> return self . byteStream <EOL> def _set_byteStream ( self , byteStream ) : <EOL> self . byteStream = byteStream <EOL> def _get_characterStream ( self ) : <EOL> return self . characterStream <EOL> def _set_characterStream ( self , characterStream ) : <EOL> self . characterStream = characterStream <EOL> def _get_stringData ( self ) : <EOL> return self . stringData <EOL> def _set_stringData ( self , data ) : <EOL> self . stringData = data <EOL> def _get_encoding ( self ) : <EOL> return self . encoding <EOL> def _set_encoding ( self , encoding ) : <EOL> self . encoding = encoding <EOL> def _get_publicId ( self ) : <EOL> return self . publicId <EOL> def _set_publicId ( self , publicId ) : <EOL> self . publicId = publicId <EOL> def _get_systemId ( self ) : <EOL> return self . systemId <EOL> def _set_systemId ( self , systemId ) : <EOL> self . systemId = systemId <EOL> def _get_baseURI ( self ) : <EOL> return self . baseURI <EOL> def _set_baseURI ( self , uri ) : <EOL> self . baseURI = uri <EOL> class DOMBuilderFilter : <EOL> """<STR_LIT>""" <EOL> FILTER_ACCEPT = <NUM_LIT:1> <EOL> FILTER_REJECT = <NUM_LIT:2> <EOL> FILTER_SKIP = <NUM_LIT:3> <EOL> FILTER_INTERRUPT = <NUM_LIT:4> <EOL> whatToShow = NodeFilter . SHOW_ALL <EOL> def _get_whatToShow ( self ) : <EOL> return self . whatToShow <EOL> def acceptNode ( self , element ) : <EOL> return self . FILTER_ACCEPT <EOL> def startContainer ( self , element ) : <EOL> return self . FILTER_ACCEPT <EOL> del NodeFilter <EOL> class DocumentLS : <EOL> """<STR_LIT>""" <EOL> async = False <EOL> def _get_async ( self ) : <EOL> return False <EOL> def _set_async ( self , async ) : <EOL> if async : <EOL> raise xml . dom . NotSupportedErr ( <EOL> "<STR_LIT>" ) <EOL> def abort ( self ) : <EOL> raise NotImplementedError ( <EOL> "<STR_LIT>" ) <EOL> def load ( self , uri ) : <EOL> raise NotImplementedError ( "<STR_LIT>" ) <EOL> def loadXML ( self , source ) : <EOL> raise NotImplementedError ( "<STR_LIT>" ) <EOL> def saveXML ( self , snode ) : <EOL> if snode is None : <EOL> snode = self <EOL> elif snode . ownerDocument is not self : <EOL> raise xml . dom . WrongDocumentErr ( ) <EOL> return snode . toxml ( ) <EOL> class DOMImplementationLS : <EOL> MODE_SYNCHRONOUS = <NUM_LIT:1> <EOL> MODE_ASYNCHRONOUS = <NUM_LIT:2> <EOL> def createDOMBuilder ( self , mode , schemaType ) : <EOL> if schemaType is not None : <EOL> raise xml . dom . NotSupportedErr ( <EOL> "<STR_LIT>" ) <EOL> if mode == self . MODE_SYNCHRONOUS : <EOL> return DOMBuilder ( ) <EOL> if mode == self . MODE_ASYNCHRONOUS : <EOL> raise xml . dom . NotSupportedErr ( <EOL> "<STR_LIT>" ) <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> def createDOMWriter ( self ) : <EOL> raise NotImplementedError ( <EOL> "<STR_LIT>" ) <EOL> def createDOMInputSource ( self ) : <EOL> return DOMInputSource ( ) </s>
