"""Read ddex file from s3.""" import os import time import botocore from ddex_ingester_common.constants.xmltodict import DDEX_LIST_FIELDS from ddex_ingester_common.helpers.xml_document_helper import ( get_conditional_text_value, get_root_element, ) from ddex_ingester_common.lambda_exceptions import ParseDDEXException from ddex_ingester_common.schemas.ddex_schema import DDEXSchema from ddex_ingester_common.schemas.purged_ddex_schema import PurgedDDEXSchema from marshmallow.utils import get_value import xmltodict READ_EXTENDED_METADATA_TIME_SLEEP_SECONDS = 10 READ_EXTENDED_METADATA_RETRY_COUNT = 3 def read_ddex(s3_client, bucket, key, logger): """Read and parse ddex file form s3.""" xml_data = s3_client.get_object(Bucket=bucket, Key=key).get('Body').read() doc = xmltodict.parse(xml_data, force_list=DDEX_LIST_FIELDS) prefix = 'ernm:' if '