MCPcopy
hub / github.com/numpy/numpy / exists

Method exists

numpy/lib/_datasource.py:427–481  ·  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

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

Callers 15

_findfileMethod · 0.95
test_ValidHTTPMethod · 0.95
test_InvalidHTTPMethod · 0.95
test_ValidFileMethod · 0.95
test_InvalidFileMethod · 0.95
mainFunction · 0.45
check_requirements_filesFunction · 0.45
collect_statsFunction · 0.45
mainFunction · 0.45
doxy_genFunction · 0.45

Calls 3

abspathMethod · 0.95
_isurlMethod · 0.95
closeMethod · 0.45

Tested by 6

test_ValidHTTPMethod · 0.76
test_InvalidHTTPMethod · 0.76
test_ValidFileMethod · 0.76
test_InvalidFileMethod · 0.76
test_gen_pyfFunction · 0.36
test_mod_gen_f77Function · 0.36