equal
deleted
inserted
replaced
62 from .. import encoding |
62 from .. import encoding |
63 |
63 |
64 # Force loading of the resources module |
64 # Force loading of the resources module |
65 resources.open_binary # pytype: disable=module-attr |
65 resources.open_binary # pytype: disable=module-attr |
66 |
66 |
67 # pytype: disable=import-error |
|
68 from importlib.resources import FileNotFoundError |
|
69 |
|
70 # pytype: enable=import-error |
|
71 |
|
72 def open_resource(package, name): |
67 def open_resource(package, name): |
73 return resources.open_binary( # pytype: disable=module-attr |
68 return resources.open_binary( # pytype: disable=module-attr |
74 pycompat.sysstr(package), pycompat.sysstr(name) |
69 pycompat.sysstr(package), pycompat.sysstr(name) |
75 ) |
70 ) |
76 |
71 |
88 |
83 |
89 except (ImportError, AttributeError): |
84 except (ImportError, AttributeError): |
90 # importlib.resources was not found (almost definitely because we're on a |
85 # importlib.resources was not found (almost definitely because we're on a |
91 # Python version before 3.7) |
86 # Python version before 3.7) |
92 |
87 |
93 class FileNotFoundError(RuntimeError): |
|
94 pass |
|
95 |
|
96 def open_resource(package, name): |
88 def open_resource(package, name): |
97 path = os.path.join(_package_path(package), name) |
89 path = os.path.join(_package_path(package), name) |
98 return open(path, "rb") |
90 return open(path, "rb") |
99 |
91 |
100 def is_resource(package, name): |
92 def is_resource(package, name): |