MCPcopy Create free account
hub / github.com/numpy/numpy / exists

Method exists

numpy/lib/_datasource.py:431–485  ·  view source on GitHub ↗

Test if path exists. Test if `path` exists as (and in this order): - a local file. - a remote URL that has been downloaded and stored locally in the `DataSource` directory. - a remote URL that has not been downloaded, but is valid and ac

(self, path)

Source from the content-addressed store, hash-verified

429 return path
430
431 def exists(self, path):
432 """
433 Test if path exists.
434
435 Test if `path` exists as (and in this order):
436
437 - a local file.
438 - a remote URL that has been downloaded and stored locally in the
439 `DataSource` directory.
440 - a remote URL that has not been downloaded, but is valid and
441 accessible.
442
443 Parameters
444 ----------
445 path : str
446 Can be a local file or a remote URL.
447
448 Returns
449 -------
450 out : bool
451 True if `path` exists.
452
453 Notes
454 -----
455 When `path` is an URL, `exists` will return True if it's either
456 stored locally in the `DataSource` directory, or is a valid remote
457 URL. `DataSource` does not discriminate between the two, the file
458 is accessible if it exists in either location.
459
460 """
461
462 # First test for local path
463 if os.path.exists(path):
464 return True
465
466 # We import this here because importing urllib is slow and
467 # a significant fraction of numpy's total import time.
468 from urllib.request import urlopen
469 from urllib.error import URLError
470
471 # Test cached url
472 upath = self.abspath(path)
473 if os.path.exists(upath):
474 return True
475
476 # Test remote url
477 if self._isurl(path):
478 try:
479 netfile = urlopen(path)
480 netfile.close()
481 del(netfile)
482 return True
483 except URLError:
484 return False
485 return False
486
487 def open(self, path, mode='r', encoding=None, newline=None):
488 """

Callers 15

_findfileMethod · 0.95
sdistFunction · 0.45
build_projectFunction · 0.45
setup.pyFile · 0.45
check_submodulesFunction · 0.45
mainFunction · 0.45
iter_included_filesFunction · 0.45
mainFunction · 0.45
get_hashFunction · 0.45
unpack_windows_zipFunction · 0.45
unpack_targzFunction · 0.45
collect_statsFunction · 0.45

Calls 3

abspathMethod · 0.95
_isurlMethod · 0.95
closeMethod · 0.45

Tested by 11

build_projectFunction · 0.36
test_ValidHTTPMethod · 0.36
test_InvalidHTTPMethod · 0.36
test_ValidFileMethod · 0.36
test_InvalidFileMethod · 0.36
test_ValidFileMethod · 0.36
test_InvalidFileMethod · 0.36
test_RemoveHTTPFileMethod · 0.36
test_CachedHTTPFileMethod · 0.36
test_gen_pyfFunction · 0.36
test_mod_gen_f77Function · 0.36