Retrieve a finder for the given path item The returned finder is cached in sys.path_importer_cache if it was newly created by a path hook. The cache (or part of it) can be cleared manually if a rescan of sys.path_hooks is necessary.
(path_item)
| 405 | |
| 406 | |
| 407 | def get_importer(path_item): |
| 408 | """Retrieve a finder for the given path item |
| 409 | |
| 410 | The returned finder is cached in sys.path_importer_cache |
| 411 | if it was newly created by a path hook. |
| 412 | |
| 413 | The cache (or part of it) can be cleared manually if a |
| 414 | rescan of sys.path_hooks is necessary. |
| 415 | """ |
| 416 | path_item = os.fsdecode(path_item) |
| 417 | try: |
| 418 | importer = sys.path_importer_cache[path_item] |
| 419 | except KeyError: |
| 420 | for path_hook in sys.path_hooks: |
| 421 | try: |
| 422 | importer = path_hook(path_item) |
| 423 | sys.path_importer_cache.setdefault(path_item, importer) |
| 424 | break |
| 425 | except ImportError: |
| 426 | pass |
| 427 | else: |
| 428 | importer = None |
| 429 | return importer |
| 430 | |
| 431 | |
| 432 | def iter_importers(fullname=""): |
no test coverage detected