Skip to content

Commit

Permalink
Improve code
Browse files Browse the repository at this point in the history
  • Loading branch information
micafer committed May 8, 2024
1 parent da9cdbb commit 129bacc
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions app/oaipmh/oai.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# specific language governing permissions and limitations
# under the License.
from lxml import etree # nosec
from datetime import datetime
from datetime import datetime, timezone
from urllib.parse import urlparse
from app.oaipmh.errors import Errors

Expand Down Expand Up @@ -69,7 +69,7 @@ def baseXMLTree():
root.set('xmlns', 'http://www.openarchives.org/OAI/2.0/')

responseDate = etree.SubElement(root, 'responseDate')
current_datetime = datetime.utcnow()
current_datetime = datetime.now(timezone.utc)
response_date = current_datetime.strftime("%Y-%m-%dT%H:%M:%SZ")
responseDate.text = response_date

Expand Down Expand Up @@ -116,7 +116,7 @@ def getRecord(self, root, metadata_dict, verb, identifier, metadata_prefix):
if metadata_prefix == 'oai_openaire':
metadata_xml = self.mapOAIRE(record_data)

metadata_element.append(etree.fromstring(metadata_xml)) # nosec
metadata_element.append(metadata_xml)

return etree.tostring(metadata_element, pretty_print=True, encoding='unicode')

Expand Down Expand Up @@ -296,7 +296,7 @@ def listRecords(self, root, metadata_dict, verb, metadata_prefix, from_date=None
metadata_xml = self.mapOAIRE(record_metadata)

# Append the generated XML to the metadata element
metadata_element.append(etree.fromstring(metadata_xml)) # nosec
metadata_element.append(metadata_xml)

header_element.append(identifier_element)
header_element.append(datestamp_element)
Expand Down Expand Up @@ -477,10 +477,7 @@ def mapOAIRE(self, metadata_dict):
format_element.text = value
root.append(format_element)

# Serialize the XML to a string
xml_string = etree.tostring(root, pretty_print=True, encoding='unicode')

return xml_string
return root

def mapDC(self, metadata_dict):
# Create an XML document
Expand Down Expand Up @@ -552,10 +549,7 @@ def mapDC(self, metadata_dict):
related_identifier_element.text = value
root.append(related_identifier_element)

# Serialize the XML to a string
xml_string = etree.tostring(root, pretty_print=True, encoding='unicode')

return xml_string
return root

def processRequest(self, request, metadata_dict):
root = self.baseXMLTree()
Expand Down

0 comments on commit 129bacc

Please sign in to comment.