From 19e7812dd66a13d30bd3b1a67668daa7a5f182aa Mon Sep 17 00:00:00 2001 From: Viacheslav Bessonov Date: Mon, 23 Aug 2021 23:56:30 +0500 Subject: [PATCH 1/2] Force DirectoryImport._locate_file read books and covers as binary files (#24) --- scripts.py | 2 +- tests/test_scripts.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts.py b/scripts.py index d9dae09836..3ff81cd1ae 100644 --- a/scripts.py +++ b/scripts.py @@ -1747,7 +1747,7 @@ def _locate_file(cls, base_filename, directory, extensions, ext.lower() ) content = None - with open_f(path) as fh: + with open_f(path, "rb") as fh: content = fh.read() return filename, media_type, content diff --git a/tests/test_scripts.py b/tests/test_scripts.py index 2994e082d3..f153de6c01 100644 --- a/tests/test_scripts.py +++ b/tests/test_scripts.py @@ -1365,7 +1365,7 @@ def mock_exists(path): return path in mock_filesystem @contextlib.contextmanager - def mock_open(path): + def mock_open(path, mode="r"): yield StringIO(mock_filesystem[path]) mock_filesystem_operations = mock_exists, mock_open From c0d21fd7a388917c956191102751c7cd677065c7 Mon Sep 17 00:00:00 2001 From: Jonathan Green Date: Mon, 23 Aug 2021 16:48:15 -0300 Subject: [PATCH 2/2] Make sure Onix ISO8601 dates containe timezone information. (#27) * Make sure Onix ISO8601 dates containe timezone information. * Use to_utc function. --- api/onix.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/api/onix.py b/api/onix.py index 690364188a..1d44de46dc 100644 --- a/api/onix.py +++ b/api/onix.py @@ -20,7 +20,7 @@ Representation, Subject, LicensePool, EditionConstants) -from core.util.datetime_helpers import strptime_utc +from core.util.datetime_helpers import to_utc from core.util.xmlparser import XMLParser @@ -224,6 +224,12 @@ def parse(cls, file, data_source_name, default_medium=None): issued = None if publishing_date: issued = dateutil.parser.isoparse(publishing_date) + if issued.tzinfo is None: + cls._logger.warning( + "Publishing date {} does not contain timezone information. Assuming UTC." + .format(publishing_date) + ) + issued = to_utc(issued) identifier_tags = parser._xpath(record, 'productidentifier') identifiers = []