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)
| 33 | # create a copy of the function we need to properly ignore this exception when |
| 34 | # running the program. |
| 35 | def pkgutil_get_importer(path_item): |
| 36 | """Retrieve a finder for the given path item |
| 37 | |
| 38 | The returned finder is cached in sys.path_importer_cache |
| 39 | if it was newly created by a path hook. |
| 40 | |
| 41 | The cache (or part of it) can be cleared manually if a |
| 42 | rescan of sys.path_hooks is necessary. |
| 43 | """ |
| 44 | try: |
| 45 | importer = sys.path_importer_cache[path_item] |
| 46 | except KeyError: |
| 47 | for path_hook in sys.path_hooks: |
| 48 | try: |
| 49 | importer = path_hook(path_item) |
| 50 | sys.path_importer_cache.setdefault(path_item, importer) |
| 51 | break |
| 52 | except ImportError: |
| 53 | pass |
| 54 | else: |
| 55 | importer = None |
| 56 | return importer |
| 57 | |
| 58 | |
| 59 | class _TempModule(object): |