33
44# pylint: disable=missing-docstring
55
6- from importlib import resources
6+ try :
7+ # Python < 3.9
8+ import importlib_resources as res
9+ except ImportError :
10+ import importlib .resources as res
711
812from yaml import full_load
913
1620
1721
1822def asset_attachment_upload_from_file (arch , name , mtype ):
19- with resources . open_binary (images_assets , name ) as fd :
23+ with res . files (images_assets ). joinpath ( name ). open ( "rb" ) as fd :
2024 attachment = arch .attachments .upload (fd , mtype = mtype )
2125
2226 return attachment
2327
2428
2529def attachment_upload_from_file (arch , name , mtype ):
26- with resources . open_binary (images , name ) as fd :
30+ with res . files (images ). joinpath ( name ). open ( "rb" ) as fd :
2731 attachment = arch .attachments .upload (fd , mtype = mtype )
2832
2933 return attachment
@@ -34,7 +38,7 @@ def locations_create_from_yaml_file(arch, name):
3438
3539 assumes there is only one document in the file.
3640 """
37- with resources . open_binary (locations , name ) as fd :
41+ with res . files (locations ). joinpath ( name ). open ( "rb" ) as fd :
3842 data = full_load (fd )
3943 attrs = data ["attributes" ]
4044 del data ["attributes" ]
@@ -46,7 +50,7 @@ def locations_from_yaml_file(name):
4650
4751 assumes there is only one document in the file.
4852 """
49- with resources . open_binary (locations , name ) as fd :
53+ with res . files (locations ). joinpath ( name ). open ( "rb" ) as fd :
5054 data = full_load (fd )
5155 attrs = data ["attributes" ]
5256 del data ["attributes" ]
0 commit comments