7from __future__
import unicode_literals
18from .
import DistlibException
19from .util
import cached_property, get_cache_base, Cache
31 base =
os.path.join(get_cache_base(), str(
'resource-cache'))
36 Is the cache stale for the given resource?
38 :param resource: The :class:`Resource` being cached.
39 :param path: The path of the resource in the cache.
40 :return: True if the cache is stale.
45 def get(self, resource):
47 Get a resource into the cache,
49 :param resource: A :class:`Resource` instance.
50 :return: The pathname of the resource in the cache.
63 stale = self.
is_stale(resource, path)
66 with open(result,
'wb')
as f:
79 A class representing an in-package resource, such as a data file. This is
80 not normally instantiated by user code, but rather by a
81 :class:`ResourceFinder` which manages the resource.
87 Get the resource as a stream.
89 This is not a property to make it obvious that it returns a new stream
92 return self.
finder.get_stream(self)
103 return self.
finder.get_bytes(self)
107 return self.
finder.get_size(self)
115 return self.
finder.get_resources(self)
120 Resource finder for file system resources.
124 skipped_extensions = (
'.pyc',
'.pyo',
'.class')
126 skipped_extensions = (
'.pyc',
'.pyo')
156 if not self.
_find(path):
162 result =
Resource(self, resource_name)
178 return (f !=
'__pycache__' and not
188 resource = self.
find(resource_name)
189 if resource
is not None:
200 new_name =
'/'.join([rname, name])
201 child = self.
find(new_name)
210 Resource finder for resources in .zip files.
231 if path
and path[-1] !=
os.sep:
257 return self.
_files[path][3]
261 if path
and path[-1] !=
os.sep:
269 s = self.
index[i][plen:]
276 if path
and path[-1] !=
os.sep:
287 type(
None): ResourceFinder,
294 import _frozen_importlib_external
as _fi
296 import _frozen_importlib
as _fi
302except (ImportError, AttributeError):
307 _finder_registry[type(loader)] = finder_maker
315 Return a resource finder for a package.
316 :param package: The name of the package.
317 :return: A :class:`ResourceFinder` instance for the package.
319 if package
in _finder_cache:
320 result = _finder_cache[package]
325 path =
getattr(module,
'__path__',
None)
327 raise DistlibException(
'You cannot get a finder for a module, '
328 'only for a package')
329 loader =
getattr(module,
'__loader__',
None)
331 if finder_maker
is None:
332 raise DistlibException(
'Unable to locate finder for %r' % package)
334 _finder_cache[package] = result
343 Return a resource finder for a path, which should represent a container.
345 :param path: The path.
346 :return: A :class:`ResourceFinder` instance for the path.
354 module = _dummy_module
357 result = finder(module)
__init__(self, finder, name)
__init__(self, base=None)
is_stale(self, resource, path)
get_stream(self, resource)
_make_path(self, resource_name)
get_resources(self, resource)
get_cache_info(self, resource)
iterator(self, resource_name)
get_bytes(self, resource)
find(self, resource_name)
is_container(self, resource)
get_stream(self, resource)
get_resources(self, resource)
get_cache_info(self, resource)
get_bytes(self, resource)
prefix_to_dir(self, prefix)
register_finder(loader, finder_maker)