def get_path_if_valid(pathstr, cwd=None, relative=False, check_exists=False):
 pathstr = pathstr.strip()
 log.url.debug('Checking if {!r} is a path'.format(pathstr))
 expanded = os.path.expanduser(pathstr)
 if os.path.isabs(expanded):
  path = expanded
 elif (relative and cwd):
  path = os.path.join(cwd, expanded)
 elif relative:
  try:
   path = os.path.abspath(expanded)
  except OSError:
   path = None
 else:
  path = None
 if check_exists:
  if ((path is not None) and os.path.exists(path)):
   log.url.debug('URL is a local file')
  else:
   path = None
 return path

def get_path_if_valid ( pathstr , cwd = None , relative = False , check_exists = False ) : pathstr = pathstr . strip ( ) log . url . debug ( 'Checking if {!r} is a path' . format ( pathstr ) ) expanded = os . path . expanduser ( pathstr ) if os . path . isabs ( expanded ) : path = expanded elif ( relative and cwd ) : path = os . path . join ( cwd , expanded ) elif relative : try : path = os . path . abspath ( expanded ) except OSError : path = None else : path = None if check_exists : if ( ( path is not None ) and os . path . exists ( path ) ) : log . url . debug ( 'URL is a local file' ) else : path = None return path
check if path is a valid path .