This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author indygreg
Recipients barry, indygreg
Date 2019-02-26.21:05:00
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1551215100.55.0.236644911032.issue36128@roundup.psfhosted.org>
In-reply-to
Content
The implementation of the ResourceReader API for the FileLoader class in importlib/_bootstrap_external.py is inconsistent with regards to handling of path separators.

Specifically, "is_resource()" returns False if "resource" has a path separator. But "open_resource()" will happily open resources containing a path separator.

I would think the two would agree about whether a path with separators is a resource or not. The documentation at https://docs.python.org/3.7/library/importlib.html#importlib.abc.ResourceReader implies that resources in subdirectories should not be allowed.

One can easily demonstrate this behavior oddity with Mercurial:

(Pdb) p sys.modules['mercurial'].__spec__.loader.get_resource_reader('mercurial').open_resource('help/config.txt')
<_io.FileIO name='/home/gps/src/hg/mercurial/help/config.txt' mode='rb' closefd=True>
(Pdb) p sys.modules['mercurial'].__spec__.loader.get_resource_reader('mercurial').is_resource('help/config.txt')
False

The behavior has been present since the functionality was added (https://github.com/python/cpython/pull/5168).
History
Date User Action Args
2019-02-26 21:05:00indygregsetrecipients: + indygreg, barry
2019-02-26 21:05:00indygregsetmessageid: <1551215100.55.0.236644911032.issue36128@roundup.psfhosted.org>
2019-02-26 21:05:00indygreglinkissue36128 messages
2019-02-26 21:05:00indygregcreate