##// END OF EJS Templates
resourceutil: implement `is_resource()`...
Matt Harbison -
r44480:42a897bf default
parent child Browse files
Show More
@@ -40,6 +40,8 b' else:'
40 try:
40 try:
41 from importlib import resources
41 from importlib import resources
42
42
43 from .. import encoding
44
43 # Force loading of the resources module
45 # Force loading of the resources module
44 resources.open_binary # pytype: disable=module-attr
46 resources.open_binary # pytype: disable=module-attr
45
47
@@ -48,6 +50,11 b' try:'
48 pycompat.sysstr(package), pycompat.sysstr(name)
50 pycompat.sysstr(package), pycompat.sysstr(name)
49 )
51 )
50
52
53 def is_resource(package, name):
54 return resources.is_resource(
55 pycompat.sysstr(package), encoding.strfromlocal(name)
56 )
57
51
58
52 except (ImportError, AttributeError):
59 except (ImportError, AttributeError):
53
60
@@ -57,3 +64,11 b' except (ImportError, AttributeError):'
57 def open_resource(package, name):
64 def open_resource(package, name):
58 path = os.path.join(_package_path(package), name)
65 path = os.path.join(_package_path(package), name)
59 return open(path, 'rb')
66 return open(path, 'rb')
67
68 def is_resource(package, name):
69 path = os.path.join(_package_path(package), name)
70
71 try:
72 return os.path.isfile(pycompat.fsdecode(path))
73 except (IOError, OSError):
74 return False
General Comments 0
You need to be logged in to leave comments. Login now