def get_module_part(dotted_name, context_file=None):
 if dotted_name.startswith('os.path'):
  return 'os.path'
 parts = dotted_name.split('.')
 if (context_file is not None):
  if (parts[0] in BUILTIN_MODULES):
   if (len(parts) > 2):
    raise ImportError(dotted_name)
   return parts[0]
 path = None
 starti = 0
 if (parts[0] == ''):
  assert (context_file is not None), 'explicit relative import, but no context_file?'
  path = []
  starti = 1
 while (parts[starti] == ''):
  starti += 1
  context_file = dirname(context_file)
 for i in range(starti, len(parts)):
  try:
   file_from_modpath(parts[starti:(i + 1)], path=path, context_file=context_file)
  except ImportError:
   if (not (i >= max(1, (len(parts) - 2)))):
    raise
   return '.'.join(parts[:i])
 return dotted_name

def get_module_part ( dotted_name , context_file = None ) : if dotted_name . startswith ( 'os.path' ) : return 'os.path' parts = dotted_name . split ( '.' ) if ( context_file is not None ) : if ( parts [ 0 ] in BUILTIN_MODULES ) : if ( len ( parts ) > 2 ) : raise ImportError ( dotted_name ) return parts [ 0 ] path = None starti = 0 if ( parts [ 0 ] == '' ) : assert ( context_file is not None ) , 'explicit relative import, but no context_file?' path = [ ] starti = 1 while ( parts [ starti ] == '' ) : starti += 1 context_file = dirname ( context_file ) for i in range ( starti , len ( parts ) ) : try : file_from_modpath ( parts [ starti : ( i + 1 ) ] , path = path , context_file = context_file ) except ImportError : if ( not ( i >= max ( 1 , ( len ( parts ) - 2 ) ) ) ) : raise return '.' . join ( parts [ : i ] ) return dotted_name
given a dotted name return the module part of the name : .