Lines Matching full:resource
5 :synopsis: Package resource reading, opening, and access
28 Resource Access
29 <https://setuptools.readthedocs.io/en/latest/pkg_resources.html#basic-resource-access>`_
40 :class:`Loaders <importlib.abc.Loader>` that wish to support resource reading should implement a
56 representing the resource container for the package (think directory)
73 resource was extracted from e.g. a zip file.
89 .. data:: Resource
91 For *resource* arguments of the functions below, you can pass in
92 the name of a resource as a string or
95 The ``Resource`` type is defined as ``Union[str, os.PathLike]``.
97 .. function:: open_binary(package, resource)
99 Open for binary reading the *resource* within *package*.
102 ``Package`` requirements. *resource* is the name of the resource to open
111 files(package).joinpath(resource).open('rb')
114 .. function:: open_text(package, resource, encoding='utf-8', errors='strict')
116 Open for text reading the *resource* within *package*. By default, the
117 resource is opened for reading as UTF-8.
120 ``Package`` requirements. *resource* is the name of the resource to open
132 files(package).joinpath(resource).open('r', encoding=encoding)
135 .. function:: read_binary(package, resource)
137 Read and return the contents of the *resource* within *package* as
141 ``Package`` requirements. *resource* is the name of the resource to open
144 contents of the resource as :class:`bytes`.
150 files(package).joinpath(resource).read_bytes()
153 .. function:: read_text(package, resource, encoding='utf-8', errors='strict')
155 Read and return the contents of *resource* within *package* as a ``str``.
159 ``Package`` requirements. *resource* is the name of the resource to open
163 returns the contents of the resource as :class:`str`.
169 files(package).joinpath(resource).read_text(encoding=encoding)
172 .. function:: path(package, resource)
174 Return the path to the *resource* as an actual file system path. This
179 resource needs to be extracted from e.g. a zip file.
182 ``Package`` requirements. *resource* is the name of the resource to open
190 as_file(files(package).joinpath(resource))
195 Return ``True`` if there is a resource named *name* in the package,
205 files(package).joinpath(resource).is_file()
221 (resource.name for resource in files(package).iterdir() if resource.is_file())