<s> import sys <EOL> def _resolve_name ( name , package , level ) : <EOL> """<STR_LIT>""" <EOL> if not hasattr ( package , '<STR_LIT>' ) : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> dot = len ( package ) <EOL> for x in xrange ( level , <NUM_LIT:1> , - <NUM_LIT:1> ) : <EOL> try : <EOL> dot = package . rindex ( '<STR_LIT:.>' , <NUM_LIT:0> , dot ) <EOL> except ValueError : <EOL> raise ValueError ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> return "<STR_LIT>" % ( package [ : dot ] , name ) <EOL> def import_module ( name , package = None ) : <EOL> """<STR_LIT>""" <EOL> if name . startswith ( '<STR_LIT:.>' ) : <EOL> if not package : <EOL> raise TypeError ( "<STR_LIT>" ) <EOL> level = <NUM_LIT:0> <EOL> for character in name : <EOL> if character != '<STR_LIT:.>' : <EOL> break <EOL> level += <NUM_LIT:1> <EOL> name = _resolve_name ( name [ level : ] , package , level ) <EOL> __import__ ( name ) <EOL> return sys . modules [ name ] </s>
