@@ -233,7 +233,6 @@ ABC hierarchy::
233
233
| +-- MetaPathFinder
234
234
| +-- PathEntryFinder
235
235
+-- Loader
236
- +-- ResourceReader
237
236
+-- ResourceLoader --------+
238
237
+-- InspectLoader |
239
238
+-- ExecutionLoader --+
@@ -370,6 +369,13 @@ ABC hierarchy::
370
369
An abstract base class for a :term: `loader `.
371
370
See :pep: `302 ` for the exact definition for a loader.
372
371
372
+ For loaders that wish to support resource reading, they should
373
+ implement a ``get_resource_reader(fullname) `` method as specified
374
+ by :class: `importlib.abc.ResourceReader `.
375
+
376
+ .. versionchanged :: 3.7
377
+ Introduced the optional ``get_resource_reader() `` method.
378
+
373
379
.. method :: create_module(spec)
374
380
375
381
A method that returns the module object to use when
@@ -471,8 +477,7 @@ ABC hierarchy::
471
477
472
478
.. class :: ResourceReader
473
479
474
- An :term: `abstract base class ` for :term: `package `
475
- :term: `loaders <loader> ` to provide the ability to read
480
+ An :term: `abstract base class ` to provide the ability to read
476
481
*resources *.
477
482
478
483
From the perspective of this ABC, a *resource * is a binary
@@ -487,13 +492,20 @@ ABC hierarchy::
487
492
expected to be a :term: `path-like object ` which represents
488
493
conceptually just a file name. This means that no subdirectory
489
494
paths should be included in the *resource * argument. This is
490
- because the location of the package that the loader is for acts
491
- as the "directory". Hence the metaphor for directories and file
495
+ because the location of the package the reader is for, acts as the
496
+ "directory". Hence the metaphor for directories and file
492
497
names is packages and resources, respectively. This is also why
493
498
instances of this class are expected to directly correlate to
494
499
a specific package (instead of potentially representing multiple
495
500
packages or a module).
496
501
502
+ Loaders that wish to support resource reading are expected to
503
+ provide a method called ``get_resource_loader(fullname) `` which
504
+ returns an object implementing this ABC's interface. If the module
505
+ specified by fullname is not a package, this method should return
506
+ :const: `None `. An object compatible with this ABC should only be
507
+ returned when the specified module is a package.
508
+
497
509
.. versionadded :: 3.7
498
510
499
511
.. abstractmethod :: open_resource(resource)
@@ -529,9 +541,10 @@ ABC hierarchy::
529
541
are known a priori and the non-resource names would be useful.
530
542
For instance, returning subdirectory names is allowed so that
531
543
when it is known that the package and resources are stored on
532
- the file system then those subdirectory names can be used.
544
+ the file system then those subdirectory names can be used
545
+ directly.
533
546
534
- The abstract method returns an empty iterator.
547
+ The abstract method returns an iterator of no items .
535
548
536
549
537
550
.. class :: ResourceLoader
@@ -540,6 +553,10 @@ ABC hierarchy::
540
553
:pep: `302 ` protocol for loading arbitrary resources from the storage
541
554
back-end.
542
555
556
+ .. deprecated :: 3.7
557
+ This ABC is deprecated in favour of supporting resource loading
558
+ through :class: `importlib.abc.ResourceReader `.
559
+
543
560
.. abstractmethod :: get_data(path)
544
561
545
562
An abstract method to return the bytes for the data located at *path *.
0 commit comments