Skip to content

Commit 77f0a27

Browse files
authored
Recognise COMMITTED status (#88)
This is an interim release Fix py3.9 deprecated method open_binary() AB#9188
1 parent 9309353 commit 77f0a27

9 files changed

Lines changed: 73 additions & 26 deletions

File tree

archivist_samples/c2pa/c2pa.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22
# pylint:disable=missing-module-docstring # docstrings
33
# pylint:disable=missing-class-docstring # docstrings
44

5-
from importlib import resources
5+
try:
6+
# Python < 3.9
7+
import importlib_resources as res
8+
except ImportError:
9+
import importlib.resources as res
610

711
import logging
812

@@ -23,7 +27,9 @@
2327

2428

2529
def upload_attachment(arch, attachment_description: AttachmentDescription):
26-
with resources.open_binary(c2pa_files, attachment_description.filename) as fd:
30+
with res.files(c2pa_files).joinpath(attachment_description.filename).open(
31+
"rb"
32+
) as fd:
2733
blob = arch.attachments.upload(fd)
2834
attachment = {
2935
# sample-specific attr to relay attachment name
@@ -38,7 +44,9 @@ def upload_attachment(arch, attachment_description: AttachmentDescription):
3844

3945

4046
def attachment_create(arch, attachment_description: AttachmentDescription):
41-
with resources.open_binary(c2pa_files, attachment_description.filename) as fd:
47+
with res.files(c2pa_files).joinpath(attachment_description.filename).open(
48+
"rb"
49+
) as fd:
4250
attachment = arch.attachments.upload(fd)
4351
result = {
4452
"arc_attribute_type": "arc_attachment",

archivist_samples/document/document.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22
# pylint:disable=missing-module-docstring # docstrings
33
# pylint:disable=missing-class-docstring # docstrings
44

5-
from importlib import resources
5+
try:
6+
# Python < 3.9
7+
import importlib_resources as res
8+
except ImportError:
9+
import importlib.resources as res
610

711
import logging
812

@@ -23,7 +27,9 @@
2327

2428

2529
def upload_attachment(arch, attachment_description: AttachmentDescription):
26-
with resources.open_binary(document_files, attachment_description.filename) as fd:
30+
with res.files(document_files).joinpath(attachment_description.filename).open(
31+
"rb"
32+
) as fd:
2733
blob = arch.attachments.upload(fd)
2834
attachment = {
2935
# sample-specific attr to relay attachment name
@@ -38,7 +44,9 @@ def upload_attachment(arch, attachment_description: AttachmentDescription):
3844

3945

4046
def attachment_create(arch, attachment_description: AttachmentDescription):
41-
with resources.open_binary(document_files, attachment_description.filename) as fd:
47+
with res.files(document_files).joinpath(attachment_description.filename).open(
48+
"rb"
49+
) as fd:
4250
attachment = arch.attachments.upload(fd)
4351
result = {
4452
"arc_attribute_type": "arc_attachment",

archivist_samples/door_entry/run.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
# pylint: disable=missing-docstring
44

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

812
from copy import copy
913
import logging
@@ -30,7 +34,9 @@
3034

3135

3236
def attachment_create(doors, attachment_description: AttachmentDescription):
33-
with resources.open_binary(images_assets, attachment_description.filename) as fd:
37+
with res.files(images_assets).joinpath(attachment_description.filename).open(
38+
"rb"
39+
) as fd:
3440
attachment = doors.attachments.upload(fd)
3541
result = {
3642
"arc_attribute_type": "arc_attachment",
@@ -478,7 +484,7 @@ def open_door(doors, doorid, cards, cardid):
478484
# time but if the use case demands it is perfectly possible to
479485
# attach the same attachment ID to multiple assets/events rather
480486
# than duplicating them
481-
with resources.open_binary(images_events, "dooropen.png") as fd:
487+
with res.files(images_events).joinpath("dooropen.png").open("rb") as fd:
482488
image = doors.attachments.upload(fd)
483489

484490
# Issue RecordEvidence logs on each.

archivist_samples/sample_scripts/c2pa/c2pa_verify.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@
2525
import sample
2626

2727
try:
28-
import importlib.resources as pkg_resources
28+
# Python < 3.9
29+
import importlib_resources as res
2930
except ImportError:
30-
import importlib_resources as pkg_resources
31+
import importlib.resources as res
3132

3233

3334
# DataTrails Connection Parameters -- Honest Abe
@@ -72,7 +73,7 @@ def evil_arch():
7273

7374
# Uploads attachments to DataTrails
7475
def upload_attachment(arch, path, name):
75-
with pkg_resources.open_binary(sample, path) as fd:
76+
with res.files(sample).joinpath(path).open("rb") as fd:
7677
blob = arch.attachments.upload(fd)
7778
attachment = {
7879
"arc_display_name": name,

archivist_samples/sbom_document/software_package.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44
# pylint:disable=unused-import # To prevent cyclical import errors forward referencing is used
55
# pylint:disable=cyclic-import # but pylint doesn't understand this feature
66

7-
from importlib import resources
7+
try:
8+
# Python < 3.9
9+
import importlib_resources as res
10+
except ImportError:
11+
import importlib.resources as res
812

913
import logging
1014
from sys import exit as sys_exit
@@ -22,7 +26,9 @@
2226

2327
def attachment_create(arch, attachment_description: AttachmentDescription):
2428
LOGGER.info("sbom attachment creator: %s", attachment_description.filename)
25-
with resources.open_binary(sbom_files, attachment_description.filename) as fd:
29+
with res.files(sbom_files).joinpath(attachment_description.filename).open(
30+
"rb"
31+
) as fd:
2632
attachment = arch.attachments.upload(fd)
2733
result = {
2834
"arc_attribute_type": "arc_attachment",

archivist_samples/software_bill_of_materials/software_package.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44
# pylint:disable=unused-import # To prevent cyclical import errors forward referencing is used
55
# pylint:disable=cyclic-import # but pylint doesn't understand this feature
66

7-
from importlib import resources
7+
try:
8+
# Python < 3.9
9+
import importlib_resources as res
10+
except ImportError:
11+
import importlib.resources as res
812

913
import logging
1014
from sys import exit as sys_exit
@@ -22,7 +26,9 @@
2226

2327
def attachment_create(sboms, attachment_description: AttachmentDescription):
2428
LOGGER.info("sbom attachment creator: %s", attachment_description.filename)
25-
with resources.open_binary(sbom_files, attachment_description.filename) as fd:
29+
with res.files(sbom_files).joinpath(attachment_description.filename).open(
30+
"rb"
31+
) as fd:
2632
attachment = sboms.attachments.upload(fd)
2733
result = {
2834
"arc_attribute_type": "arc_attachment",

archivist_samples/synsation/util.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
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

812
from yaml import full_load
913

@@ -16,14 +20,14 @@
1620

1721

1822
def 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

2529
def 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"]

archivist_samples/wipp/wipp.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22
# pylint:disable=missing-module-docstring # docstrings
33
# pylint:disable=missing-class-docstring # docstrings
44

5-
from importlib import resources
5+
try:
6+
# Python < 3.9
7+
import importlib_resources as res
8+
except ImportError:
9+
import importlib.resources as res
610

711
import logging
812

@@ -22,7 +26,9 @@
2226

2327

2428
def upload_attachment(arch, attachment_description: AttachmentDescription):
25-
with resources.open_binary(wipp_files, attachment_description.filename) as fd:
29+
with res.files(wipp_files).joinpath(attachment_description.filename).open(
30+
"rb"
31+
) as fd:
2632
blob = arch.attachments.upload(fd)
2733
attachment = {
2834
# sample-specific attr to relay attachment name
@@ -37,7 +43,9 @@ def upload_attachment(arch, attachment_description: AttachmentDescription):
3743

3844

3945
def attachment_create(arch, attachment_description: AttachmentDescription):
40-
with resources.open_binary(wipp_files, attachment_description.filename) as fd:
46+
with res.files(wipp_files).joinpath(attachment_description.filename).open(
47+
"rb"
48+
) as fd:
4149
attachment = arch.attachments.upload(fd)
4250
result = {
4351
"arc_attribute_type": "arc_attachment",

requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
cryptography~=41.0.2
2-
# TODO change to datatrails when released
3-
datatrails-archivist==0.27.1
2+
importlib-resources==3.0.0; python_version < '3.9'
3+
datatrails-archivist==0.29.0a1
44
pyyaml~=6.0.1

0 commit comments

Comments
 (0)