diff options
Diffstat (limited to 'devdocs/python~3.12/library%2Fimportlib.resources.abc.html')
| -rw-r--r-- | devdocs/python~3.12/library%2Fimportlib.resources.abc.html | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/devdocs/python~3.12/library%2Fimportlib.resources.abc.html b/devdocs/python~3.12/library%2Fimportlib.resources.abc.html new file mode 100644 index 00000000..f349f95c --- /dev/null +++ b/devdocs/python~3.12/library%2Fimportlib.resources.abc.html @@ -0,0 +1,57 @@ + <span id="importlib-resources-abc-abstract-base-classes-for-resources"></span><h1>importlib.resources.abc – Abstract base classes for resources</h1> <p><strong>Source code:</strong> <a class="reference external" href="https://github.com/python/cpython/tree/3.12/Lib/importlib/resources/abc.py">Lib/importlib/resources/abc.py</a></p> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.11.</span></p> </div> <dl class="py class"> <dt class="sig sig-object py" id="importlib.resources.abc.ResourceReader"> +<code>class importlib.resources.abc.ResourceReader</code> </dt> <dd> +<p><em>Superseded by TraversableResources</em></p> <p>An <a class="reference internal" href="../glossary#term-abstract-base-class"><span class="xref std std-term">abstract base class</span></a> to provide the ability to read <em>resources</em>.</p> <p>From the perspective of this ABC, a <em>resource</em> is a binary artifact that is shipped within a package. Typically this is something like a data file that lives next to the <code>__init__.py</code> file of the package. The purpose of this class is to help abstract out the accessing of such data files so that it does not matter if the package and its data file(s) are stored in a e.g. zip file versus on the file system.</p> <p>For any of methods of this class, a <em>resource</em> argument is expected to be a <a class="reference internal" href="../glossary#term-path-like-object"><span class="xref std std-term">path-like object</span></a> which represents conceptually just a file name. This means that no subdirectory paths should be included in the <em>resource</em> argument. This is because the location of the package the reader is for, acts as the “directory”. Hence the metaphor for directories and file names is packages and resources, respectively. This is also why instances of this class are expected to directly correlate to a specific package (instead of potentially representing multiple packages or a module).</p> <p>Loaders that wish to support resource reading are expected to provide a method called <code>get_resource_reader(fullname)</code> which returns an object implementing this ABC’s interface. If the module specified by fullname is not a package, this method should return <a class="reference internal" href="constants#None" title="None"><code>None</code></a>. An object compatible with this ABC should only be returned when the specified module is a package.</p> <div class="deprecated-removed"> <p><span class="versionmodified">Deprecated since version 3.12, will be removed in version 3.14: </span>Use <a class="reference internal" href="#importlib.resources.abc.TraversableResources" title="importlib.resources.abc.TraversableResources"><code>importlib.resources.abc.TraversableResources</code></a> instead.</p> </div> <dl class="py method"> <dt class="sig sig-object py" id="importlib.resources.abc.ResourceReader.open_resource"> +<code>abstractmethod open_resource(resource)</code> </dt> <dd> +<p>Returns an opened, <a class="reference internal" href="../glossary#term-file-like-object"><span class="xref std std-term">file-like object</span></a> for binary reading of the <em>resource</em>.</p> <p>If the resource cannot be found, <a class="reference internal" href="exceptions#FileNotFoundError" title="FileNotFoundError"><code>FileNotFoundError</code></a> is raised.</p> </dd> +</dl> <dl class="py method"> <dt class="sig sig-object py" id="importlib.resources.abc.ResourceReader.resource_path"> +<code>abstractmethod resource_path(resource)</code> </dt> <dd> +<p>Returns the file system path to the <em>resource</em>.</p> <p>If the resource does not concretely exist on the file system, raise <a class="reference internal" href="exceptions#FileNotFoundError" title="FileNotFoundError"><code>FileNotFoundError</code></a>.</p> </dd> +</dl> <dl class="py method"> <dt class="sig sig-object py" id="importlib.resources.abc.ResourceReader.is_resource"> +<code>abstractmethod is_resource(name)</code> </dt> <dd> +<p>Returns <code>True</code> if the named <em>name</em> is considered a resource. <a class="reference internal" href="exceptions#FileNotFoundError" title="FileNotFoundError"><code>FileNotFoundError</code></a> is raised if <em>name</em> does not exist.</p> </dd> +</dl> <dl class="py method"> <dt class="sig sig-object py" id="importlib.resources.abc.ResourceReader.contents"> +<code>abstractmethod contents()</code> </dt> <dd> +<p>Returns an <a class="reference internal" href="../glossary#term-iterable"><span class="xref std std-term">iterable</span></a> of strings over the contents of the package. Do note that it is not required that all names returned by the iterator be actual resources, e.g. it is acceptable to return names for which <a class="reference internal" href="#importlib.resources.abc.ResourceReader.is_resource" title="importlib.resources.abc.ResourceReader.is_resource"><code>is_resource()</code></a> would be false.</p> <p>Allowing non-resource names to be returned is to allow for situations where how a package and its resources are stored are known a priori and the non-resource names would be useful. For instance, returning subdirectory names is allowed so that when it is known that the package and resources are stored on the file system then those subdirectory names can be used directly.</p> <p>The abstract method returns an iterable of no items.</p> </dd> +</dl> </dd> +</dl> <dl class="py class"> <dt class="sig sig-object py" id="importlib.resources.abc.Traversable"> +<code>class importlib.resources.abc.Traversable</code> </dt> <dd> +<p>An object with a subset of <a class="reference internal" href="pathlib#pathlib.Path" title="pathlib.Path"><code>pathlib.Path</code></a> methods suitable for traversing directories and opening files.</p> <p>For a representation of the object on the file-system, use <a class="reference internal" href="importlib.resources#importlib.resources.as_file" title="importlib.resources.as_file"><code>importlib.resources.as_file()</code></a>.</p> <dl class="py attribute"> <dt class="sig sig-object py" id="importlib.resources.abc.Traversable.name"> +<code>name</code> </dt> <dd> +<p>Abstract. The base name of this object without any parent references.</p> </dd> +</dl> <dl class="py method"> <dt class="sig sig-object py" id="importlib.resources.abc.Traversable.iterdir"> +<code>abstractmethod iterdir()</code> </dt> <dd> +<p>Yield Traversable objects in self.</p> </dd> +</dl> <dl class="py method"> <dt class="sig sig-object py" id="importlib.resources.abc.Traversable.is_dir"> +<code>abstractmethod is_dir()</code> </dt> <dd> +<p>Return True if self is a directory.</p> </dd> +</dl> <dl class="py method"> <dt class="sig sig-object py" id="importlib.resources.abc.Traversable.is_file"> +<code>abstractmethod is_file()</code> </dt> <dd> +<p>Return True if self is a file.</p> </dd> +</dl> <dl class="py method"> <dt class="sig sig-object py" id="importlib.resources.abc.Traversable.joinpath"> +<code>abstractmethod joinpath(child)</code> </dt> <dd> +<p>Return Traversable child in self.</p> </dd> +</dl> <dl class="py method"> <dt class="sig sig-object py" id="importlib.resources.abc.Traversable.__truediv__"> +<code>abstractmethod __truediv__(child)</code> </dt> <dd> +<p>Return Traversable child in self.</p> </dd> +</dl> <dl class="py method"> <dt class="sig sig-object py" id="importlib.resources.abc.Traversable.open"> +<code>abstractmethod open(mode='r', *args, **kwargs)</code> </dt> <dd> +<p><em>mode</em> may be ‘r’ or ‘rb’ to open as text or binary. Return a handle suitable for reading (same as <a class="reference internal" href="pathlib#pathlib.Path.open" title="pathlib.Path.open"><code>pathlib.Path.open</code></a>).</p> <p>When opening as text, accepts encoding parameters such as those accepted by <a class="reference internal" href="io#io.TextIOWrapper" title="io.TextIOWrapper"><code>io.TextIOWrapper</code></a>.</p> </dd> +</dl> <dl class="py method"> <dt class="sig sig-object py" id="importlib.resources.abc.Traversable.read_bytes"> +<code>read_bytes()</code> </dt> <dd> +<p>Read contents of self as bytes.</p> </dd> +</dl> <dl class="py method"> <dt class="sig sig-object py" id="importlib.resources.abc.Traversable.read_text"> +<code>read_text(encoding=None)</code> </dt> <dd> +<p>Read contents of self as text.</p> </dd> +</dl> </dd> +</dl> <dl class="py class"> <dt class="sig sig-object py" id="importlib.resources.abc.TraversableResources"> +<code>class importlib.resources.abc.TraversableResources</code> </dt> <dd> +<p>An abstract base class for resource readers capable of serving the <a class="reference internal" href="importlib.resources#importlib.resources.files" title="importlib.resources.files"><code>importlib.resources.files()</code></a> interface. Subclasses <a class="reference internal" href="#importlib.resources.abc.ResourceReader" title="importlib.resources.abc.ResourceReader"><code>ResourceReader</code></a> and provides concrete implementations of the <code>ResourceReader</code>’s abstract methods. Therefore, any loader supplying <code>TraversableResources</code> also supplies <code>ResourceReader</code>.</p> <p>Loaders that wish to support resource reading are expected to implement this interface.</p> <dl class="py method"> <dt class="sig sig-object py" id="importlib.resources.abc.TraversableResources.files"> +<code>abstractmethod files()</code> </dt> <dd> +<p>Returns a <a class="reference internal" href="#importlib.resources.abc.Traversable" title="importlib.resources.abc.Traversable"><code>importlib.resources.abc.Traversable</code></a> object for the loaded package.</p> </dd> +</dl> </dd> +</dl> <div class="_attribution"> + <p class="_attribution-p"> + © 2001–2023 Python Software Foundation<br>Licensed under the PSF License.<br> + <a href="https://docs.python.org/3.12/library/importlib.resources.abc.html" class="_attribution-link">https://docs.python.org/3.12/library/importlib.resources.abc.html</a> + </p> +</div> |
