equal
deleted
inserted
replaced
57 # importlib.resources exists from Python 3.7; see fallback in except clause |
57 # importlib.resources exists from Python 3.7; see fallback in except clause |
58 # further down |
58 # further down |
59 from importlib import resources # pytype: disable=import-error |
59 from importlib import resources # pytype: disable=import-error |
60 |
60 |
61 # Force loading of the resources module |
61 # Force loading of the resources module |
62 resources.open_binary # pytype: disable=module-attr |
62 if pycompat.safehasattr(resources, 'files'): |
|
63 resources.files # pytype: disable=module-attr |
|
64 else: |
|
65 resources.open_binary # pytype: disable=module-attr |
63 |
66 |
64 # py2exe raises an AssertionError if uses importlib.resources |
67 # py2exe raises an AssertionError if uses importlib.resources |
65 if getattr(sys, "frozen", None) in ("console_exe", "windows_exe"): |
68 if getattr(sys, "frozen", None) in ("console_exe", "windows_exe"): |
66 raise ImportError |
69 raise ImportError |
67 |
70 |
90 |
93 |
91 else: |
94 else: |
92 from .. import encoding |
95 from .. import encoding |
93 |
96 |
94 def open_resource(package, name): |
97 def open_resource(package, name): |
95 return resources.open_binary( # pytype: disable=module-attr |
98 if pycompat.safehasattr(resources, 'files'): |
96 pycompat.sysstr(package), pycompat.sysstr(name) |
99 return ( |
97 ) |
100 resources.files( # pytype: disable=module-attr |
|
101 pycompat.sysstr(package) |
|
102 ) |
|
103 .joinpath(pycompat.sysstr(name)) |
|
104 .open('rb') |
|
105 ) |
|
106 else: |
|
107 return resources.open_binary( # pytype: disable=module-attr |
|
108 pycompat.sysstr(package), pycompat.sysstr(name) |
|
109 ) |
98 |
110 |
99 def is_resource(package, name): |
111 def is_resource(package, name): |
100 return resources.is_resource( # pytype: disable=module-attr |
112 return resources.is_resource( # pytype: disable=module-attr |
101 pycompat.sysstr(package), encoding.strfromlocal(name) |
113 pycompat.sysstr(package), encoding.strfromlocal(name) |
102 ) |
114 ) |