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 |
67 def open_resource(package, name): |
72 def open_resource(package, name): |
68 return resources.open_binary( # pytype: disable=module-attr |
73 return resources.open_binary( # pytype: disable=module-attr |
69 pycompat.sysstr(package), pycompat.sysstr(name) |
74 pycompat.sysstr(package), pycompat.sysstr(name) |
70 ) |
75 ) |
71 |
76 |
83 |
88 |
84 except (ImportError, AttributeError): |
89 except (ImportError, AttributeError): |
85 # importlib.resources was not found (almost definitely because we're on a |
90 # importlib.resources was not found (almost definitely because we're on a |
86 # Python version before 3.7) |
91 # Python version before 3.7) |
87 |
92 |
|
93 class FileNotFoundError(RuntimeError): |
|
94 pass |
|
95 |
88 def open_resource(package, name): |
96 def open_resource(package, name): |
89 path = os.path.join(_package_path(package), name) |
97 path = os.path.join(_package_path(package), name) |
90 return open(path, "rb") |
98 return open(path, "rb") |
91 |
99 |
92 def is_resource(package, name): |
100 def is_resource(package, name): |