Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# guard against problems
if source is None or not isinstance(source, string_types):
return False
is_path = False
try:
is_path = os.path.exists(source)
except UnicodeEncodeError:
is_path = os.path.exists(source.encode('utf-8'))
except: # noqa
# still false
pass
if not is_path:
# check if it's an URL
result = urlparse(source)
if result.scheme in ["http", "https"]:
is_path = True
elif result.scheme and result.netloc and result.path:
# complete uri including one with a network path
is_path = True
elif result.scheme == "file" and result.path:
is_path = os.path.exists(url2path(source))
return is_path