File tree Expand file tree Collapse file tree 1 file changed +7
-4
lines changed Expand file tree Collapse file tree 1 file changed +7
-4
lines changed Original file line number Diff line number Diff line change @@ -46,18 +46,21 @@ def open(package: Package, file_name: FileName) -> BinaryIO:
46
46
"""Return a file-like object opened for binary-reading of the resource."""
47
47
file_name = _normalize_path (file_name )
48
48
package = _get_package (package )
49
- package_path = pathlib .Path (package .__spec__ .origin ).resolve ().parent
50
- full_path = package_path / file_name
49
+ # Using pathlib doesn't work well here due to the lack of 'strict' argument
50
+ # for pathlib.Path.resolve() prior to Python 3.6.
51
+ absolute_package_path = os .path .abspath (package .__spec__ .origin )
52
+ package_path = os .path .dirname (absolute_package_path )
53
+ full_path = os .path .join (package_path , file_name )
51
54
try :
52
- return full_path .open ('rb' )
55
+ return builtins .open (full_path , 'rb' )
53
56
except IOError :
54
57
# Just assume the loader is a resource loader; all the relevant
55
58
# importlib.machinery loaders are and an AttributeError for get_data()
56
59
# will make it clear what is needed from the loader.
57
60
loader = typing .cast (importlib .abc .ResourceLoader ,
58
61
package .__spec__ .loader )
59
62
try :
60
- data = loader .get_data (str ( full_path ) )
63
+ data = loader .get_data (full_path )
61
64
except IOError :
62
65
package_name = package .__spec__ .name
63
66
message = '{!r} resource not found in {!r}' .format (file_name , package_name )
You can’t perform that action at this time.
0 commit comments