(filename)
| 531 | |
| 532 | |
| 533 | def exists(filename): |
| 534 | if os_path_exists(filename): |
| 535 | return True |
| 536 | |
| 537 | if not os.path.isabs(filename): |
| 538 | filename = _get_relative_filename_abs_path(filename, os.path.abspath) |
| 539 | if os_path_exists(filename): |
| 540 | return True |
| 541 | |
| 542 | ind = filename.find(".zip") |
| 543 | if ind == -1: |
| 544 | ind = filename.find(".egg") |
| 545 | |
| 546 | if ind != -1: |
| 547 | ind += 4 |
| 548 | zip_path = filename[:ind] |
| 549 | inner_path = filename[ind:] |
| 550 | if inner_path.startswith("!"): |
| 551 | # Note (fabioz): although I can replicate this by creating a file ending as |
| 552 | # .zip! or .egg!, I don't really know what's the real-world case for this |
| 553 | # (still kept as it was added by @jetbrains, but it should probably be reviewed |
| 554 | # later on). |
| 555 | # Note 2: it goes hand-in-hand with '_apply_func_and_normalize_case'. |
| 556 | inner_path = inner_path[1:] |
| 557 | zip_path = zip_path + "!" |
| 558 | |
| 559 | zip_file_obj = _ZIP_SEARCH_CACHE.get(zip_path, _NOT_FOUND_SENTINEL) |
| 560 | if zip_file_obj is None: |
| 561 | return False |
| 562 | elif zip_file_obj is _NOT_FOUND_SENTINEL: |
| 563 | try: |
| 564 | import zipfile |
| 565 | |
| 566 | zip_file_obj = zipfile.ZipFile(zip_path, "r") |
| 567 | _ZIP_SEARCH_CACHE[zip_path] = zip_file_obj |
| 568 | except: |
| 569 | _ZIP_SEARCH_CACHE[zip_path] = _NOT_FOUND_SENTINEL |
| 570 | return False |
| 571 | |
| 572 | try: |
| 573 | if inner_path.startswith("/") or inner_path.startswith("\\"): |
| 574 | inner_path = inner_path[1:] |
| 575 | |
| 576 | _info = zip_file_obj.getinfo(inner_path.replace("\\", "/")) |
| 577 | |
| 578 | return join(zip_path, inner_path) |
| 579 | except KeyError: |
| 580 | return False |
| 581 | |
| 582 | else: |
| 583 | pydev_log.debug("os.path.exists(%r) returned False.", filename) |
| 584 | |
| 585 | return False |
| 586 | |
| 587 | |
| 588 | try: |
no test coverage detected