#NEWLINE# def import_module( name , package = None ) : #NEWLINE# #INDENT# "Import a module.\n        The 'package' argument is required when performing a relative import.\n        It specifies the package to use as the anchor point from which to\n        resolve the relative import to an absolute import." #NEWLINE# if name . startswith ( '.' ) : #NEWLINE# #INDENT# if ( not package ) : #NEWLINE# #INDENT# raise TypeError ( "relative imports require the 'package' argument" ) #NEWLINE# #UNINDENT# level = 0 #NEWLINE# for character in name : #NEWLINE# #INDENT# if ( character != '.' ) : #NEWLINE# #INDENT# break #NEWLINE# #UNINDENT# level += 1 #NEWLINE# #UNINDENT# name = _resolve_name ( level [ level : ] , package , level ) #NEWLINE# #UNINDENT# __import__ ( name ) #NEWLINE# return sys . modules [ name ]