def import_string(import_name, silent=False):
 if isinstance(import_name, unicode):
  import_name = str(import_name)
 try:
  if (':' in import_name):
   (module, obj) = import_name.split(':', 1)
  elif ('.' in import_name):
   (module, obj) = import_name.rsplit('.', 1)
  else:
   return __import__(import_name)
  if isinstance(obj, unicode):
   obj = obj.encode('utf-8')
  try:
   return getattr(__import__(module, None, None, [obj]), obj)
  except (ImportError, AttributeError):
   modname = ((module + '.') + obj)
   __import__(modname)
   return sys.modules[modname]
 except ImportError as e:
  if (not silent):
   raise ImportStringError(import_name, e), None, sys.exc_info()[2]

def import_string ( import_name , silent = False ) : if isinstance ( import_name , unicode ) : import_name = str ( import_name ) try : if ( ':' in import_name ) : ( module , obj ) = import_name . split ( ':' , 1 ) elif ( '.' in import_name ) : ( module , obj ) = import_name . rsplit ( '.' , 1 ) else : return __import__ ( import_name ) if isinstance ( obj , unicode ) : obj = obj . encode ( 'utf-8' ) try : return getattr ( __import__ ( module , None , None , [ obj ] ) , obj ) except ( ImportError , AttributeError ) : modname = ( ( module + '.' ) + obj ) __import__ ( modname ) return sys . modules [ modname ] except ImportError as e : if ( not silent ) : raise ImportStringError ( import_name , e ) , None , sys . exc_info ( ) [ 2 ]
imports an object based on a string .