<s> """<STR_LIT>""" <EOL> from xml . dom . minicompat import * <EOL> well_known_implementations = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> registered = { } <EOL> def registerDOMImplementation ( name , factory ) : <EOL> """<STR_LIT>""" <EOL> registered [ name ] = factory <EOL> def _good_enough ( dom , features ) : <EOL> "<STR_LIT>" <EOL> for f , v in features : <EOL> if not dom . hasFeature ( f , v ) : <EOL> return <NUM_LIT:0> <EOL> return <NUM_LIT:1> <EOL> def getDOMImplementation ( name = None , features = ( ) ) : <EOL> """<STR_LIT>""" <EOL> import os <EOL> creator = None <EOL> mod = well_known_implementations . get ( name ) <EOL> if mod : <EOL> mod = __import__ ( mod , { } , { } , [ '<STR_LIT>' ] ) <EOL> return mod . getDOMImplementation ( ) <EOL> elif name : <EOL> return registered [ name ] ( ) <EOL> elif os . environ . has_key ( "<STR_LIT>" ) : <EOL> return getDOMImplementation ( name = os . environ [ "<STR_LIT>" ] ) <EOL> if isinstance ( features , StringTypes ) : <EOL> features = _parse_feature_string ( features ) <EOL> for creator in registered . values ( ) : <EOL> dom = creator ( ) <EOL> if _good_enough ( dom , features ) : <EOL> return dom <EOL> for creator in well_known_implementations . keys ( ) : <EOL> try : <EOL> dom = getDOMImplementation ( name = creator ) <EOL> except StandardError : <EOL> continue <EOL> if _good_enough ( dom , features ) : <EOL> return dom <EOL> raise ImportError , "<STR_LIT>" <EOL> def _parse_feature_string ( s ) : <EOL> features = [ ] <EOL> parts = s . split ( ) <EOL> i = <NUM_LIT:0> <EOL> length = len ( parts ) <EOL> while i < length : <EOL> feature = parts [ i ] <EOL> if feature [ <NUM_LIT:0> ] in "<STR_LIT>" : <EOL> raise ValueError , "<STR_LIT>" % ( feature , ) <EOL> i = i + <NUM_LIT:1> <EOL> version = None <EOL> if i < length : <EOL> v = parts [ i ] <EOL> if v [ <NUM_LIT:0> ] in "<STR_LIT>" : <EOL> i = i + <NUM_LIT:1> <EOL> version = v <EOL> features . append ( ( feature , version ) ) <EOL> return tuple ( features ) </s>
