Skip to content
11 changes: 5 additions & 6 deletions browse.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
"""Functions for listing collection information."""

__copyright__ = 'Copyright (c) 2019-2025, Utrecht University'
__copyright__ = 'Copyright (c) 2019-2026, Utrecht University'
__license__ = 'GPLv3, see LICENSE'

import re
from collections import OrderedDict
from typing import Dict

import magic
from genquery import AS_DICT, Query
Expand Down Expand Up @@ -38,7 +37,7 @@ def api_browse_folder(ctx: rule.Context,

:returns: Dict with paginated collection contents
"""
def transform(row: Dict) -> Dict:
def transform(row: dict) -> dict:
# Remove ORDER_BY etc. wrappers from column names.
x = {re.sub(r'.*\((.*)\)', '\\1', k): v for k, v in row.items()}
if 'DATA_NAME' in x and 'META_DATA_ATTR_VALUE' in x:
Expand Down Expand Up @@ -128,7 +127,7 @@ def api_browse_collections(ctx: rule.Context,

:returns: Dict with paginated collection contents
"""
def transform(row: Dict) -> Dict:
def transform(row: dict) -> dict:
# Remove ORDER_BY etc. wrappers from column names.
x = {re.sub(r'.*\((.*)\)', '\\1', k): v for k, v in row.items()}

Expand Down Expand Up @@ -206,7 +205,7 @@ def api_search(ctx: rule.Context,

:returns: Dict with paginated search results
"""
def transform(row: Dict) -> Dict:
def transform(row: dict) -> dict:
# Remove ORDER_BY etc. wrappers from column names.
x = {re.sub(r'.*\((.*)\)', '\\1', k): v for k, v in row.items()}

Expand Down Expand Up @@ -295,7 +294,7 @@ def transform(row: Dict) -> Dict:
('items', datas)])


def _filter_vault_deposit_index(row: Dict) -> bool:
def _filter_vault_deposit_index(row: dict) -> bool:
"""This internal function filters out index collections in deposit vault collections.
These collections are used internally by Yoda for indexing data package metadata, and
should not be displayed.
Expand Down
5 changes: 2 additions & 3 deletions datacite.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
"""Functions for communicating with DataCite and some utilities."""

__copyright__ = 'Copyright (c) 2019-2024, Utrecht University'
__copyright__ = 'Copyright (c) 2019-2026, Utrecht University'
__license__ = 'GPLv3, see LICENSE'

import random
import string
from typing import Dict

import requests

from util import *


def metadata_post(payload: Dict) -> requests.Response:
def metadata_post(payload: dict) -> requests.Response:
"""Register DOI metadata with DataCite."""
url = "{}/dois".format(config.datacite_rest_api_url)
auth = (config.datacite_username, config.datacite_password)
Expand Down
50 changes: 25 additions & 25 deletions datarequest.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from collections import OrderedDict
from datetime import datetime
from enum import Enum
from typing import Dict, List, Optional
from typing import Optional

import jsonschema
from genquery import AS_DICT, AS_LIST, Query, row_iterator
Expand Down Expand Up @@ -283,7 +283,7 @@ def type_get(ctx: rule.Context, request_id: str) -> type:
return datarequest_type


def available_documents_get(ctx: rule.Context, request_id: str, datarequest_type: str, datarequest_status: str) -> List:
def available_documents_get(ctx: rule.Context, request_id: str, datarequest_type: str, datarequest_status: str) -> list:
# Construct list of existing documents
available_documents = []
if datarequest_type == type.REGULAR.value:
Expand Down Expand Up @@ -362,7 +362,7 @@ def generate_request_id(ctx: rule.Context) -> int:


@api.make()
def api_datarequest_action_permitted(ctx: rule.Context, request_id: str, roles: List, statuses: List) -> api.Result:
def api_datarequest_action_permitted(ctx: rule.Context, request_id: str, roles: list, statuses: Optional[list]) -> api.Result:
"""Wrapper around datarequest_action_permitted.

:param ctx: Combined type of a callback and rei struct
Expand All @@ -382,7 +382,7 @@ def get_status(stat: str) -> status:
return datarequest_action_permitted(ctx, request_id, roles, statuses)


def datarequest_action_permitted(ctx: rule.Context, request_id: str, roles: List, statuses: List | None) -> bool:
def datarequest_action_permitted(ctx: rule.Context, request_id: str, roles: list, statuses: Optional[list]) -> bool:
"""Check if current user and data request status meet specified restrictions.

:param ctx: Combined type of a callback and rei struct
Expand Down Expand Up @@ -425,7 +425,7 @@ def datarequest_action_permitted(ctx: rule.Context, request_id: str, roles: List


@api.make()
def api_datarequest_roles_get(ctx: rule.Context, request_id: str | None = None) -> api.Result:
def api_datarequest_roles_get(ctx: rule.Context, request_id: Optional[str] = None) -> api.Result:
"""Get roles of invoking user.

:param ctx: Combined type of a callback and rei struct
Expand All @@ -437,7 +437,7 @@ def api_datarequest_roles_get(ctx: rule.Context, request_id: str | None = None)
return datarequest_roles_get(ctx, request_id)


def datarequest_roles_get(ctx: rule.Context, request_id: str | None = None) -> List:
def datarequest_roles_get(ctx: rule.Context, request_id: Optional[str] = None) -> list:
"""Get roles of invoking user.

:param ctx: Combined type of a callback and rei struct
Expand Down Expand Up @@ -517,7 +517,7 @@ def datarequest_is_reviewer(ctx: rule.Context, request_id: str, pending: bool =
return is_reviewer


def datarequest_reviewers_get(ctx: rule.Context, request_id: str, pending: bool = False) -> List[str]:
def datarequest_reviewers_get(ctx: rule.Context, request_id: str, pending: bool = False) -> list[str]:
"""Return a list of users assigned as reviewers to a data request.

:param ctx: Combined type of a callback and rei struct
Expand Down Expand Up @@ -636,7 +636,7 @@ def datarequest_provenance_write(ctx: rule.Context, request_id: str, request_sta
return api.Error("write_error", "Could not write timestamp to provenance log: {}.".format(e))


def datarequest_data_valid(ctx: rule.Context, data: Dict, schema_name: str | None = None, schema: str | None = None) -> bool:
def datarequest_data_valid(ctx: rule.Context, data: dict, schema_name: str | None = None, schema: str | None = None) -> bool:
"""Check if form data contains no errors

Default mode of operation is to provide schema data and the schema name of the schema against
Expand Down Expand Up @@ -677,7 +677,7 @@ def datarequest_data_valid(ctx: rule.Context, data: Dict, schema_name: str | Non
return False


def cc_email_addresses_get(contact_object: Dict) -> str | None:
def cc_email_addresses_get(contact_object: dict) -> str | None:
try:
cc = contact_object['cc_email_addresses']
return cc.replace(' ', '')
Expand Down Expand Up @@ -765,7 +765,7 @@ def api_datarequest_browse(ctx: rule.Context,
dac_member = user.is_member_of(ctx, GROUP_DAC)
coll = "/{}/{}".format(user.zone(ctx), DRCOLLECTION)

def transform(row: Dict) -> Dict:
def transform(row: dict) -> dict:
# Remove ORDER_BY etc. wrappers from column names.
x = {re.sub(r'.*\((.*)\)', '\\1', k): v for k, v in row.items()}

Expand All @@ -774,14 +774,14 @@ def transform(row: Dict) -> Dict:
'create_time': int(x['COLL_CREATE_TIME']),
'status': x['META_DATA_ATTR_VALUE']}

def transform_title(row: Dict) -> Dict:
def transform_title(row: dict) -> dict:
# Remove ORDER_BY etc. wrappers from column names.
x = {re.sub(r'.*\((.*)\)', '\\1', k): v for k, v in row.items()}

return {'id': x['COLL_NAME'].split('/')[-1],
'title': x['META_DATA_ATTR_VALUE']}

def transform_status(row: Dict) -> Dict:
def transform_status(row: dict) -> dict:
# Remove ORDER_BY etc. wrappers from column names.
x = {re.sub(r'.*\((.*)\)', '\\1', k): v for k, v in row.items()}

Expand Down Expand Up @@ -853,7 +853,7 @@ def transform_status(row: Dict) -> Dict:
return OrderedDict([('total', qcoll.total_rows()), ('items', colls)])


def datarequest_process_expired_review_periods(ctx: rule.Context, request_ids: List) -> None:
def datarequest_process_expired_review_periods(ctx: rule.Context, request_ids: list) -> None:
"""Process expired review periods by setting their status to REVIEWED.

:param ctx: Combined type of a callback and rei struct
Expand All @@ -863,7 +863,7 @@ def datarequest_process_expired_review_periods(ctx: rule.Context, request_ids: L
status_set(ctx, request_id, status.REVIEWED)


def file_write(ctx: rule.Context, coll_path: str, filename: str, data: Dict, readers: List[str]) -> None:
def file_write(ctx: rule.Context, coll_path: str, filename: str, data: dict, readers: list[str]) -> None:
"""Grant temporary write permission and write file to disk.

:param ctx: Combined type of a callback and rei struct
Expand Down Expand Up @@ -897,7 +897,7 @@ def file_write(ctx: rule.Context, coll_path: str, filename: str, data: Dict, rea
msi.set_acl(ctx, "default", "own", "rods", file_path)


def file_lock(ctx: rule.Context, coll_path: str, filename: str, readers: List[str]) -> None:
def file_lock(ctx: rule.Context, coll_path: str, filename: str, readers: list[str]) -> None:
"""Revoke temporary write permission.

:param ctx: Combined type of a callback and rei struct
Expand All @@ -922,7 +922,7 @@ def file_lock(ctx: rule.Context, coll_path: str, filename: str, readers: List[st


@api.make()
def api_datarequest_submit(ctx: rule.Context, data: Dict, draft: bool, draft_request_id: str | None = None) -> api.Result:
def api_datarequest_submit(ctx: rule.Context, data: dict, draft: bool, draft_request_id: Optional[str] = None) -> api.Result:
"""Persist a data request to disk.

:param ctx: Combined type of a callback and rei struct
Expand Down Expand Up @@ -1056,7 +1056,7 @@ def api_datarequest_submit(ctx: rule.Context, data: Dict, draft: bool, draft_req


@api.make()
def api_datarequest_get(ctx: rule.Context, request_id: int) -> api.Result:
def api_datarequest_get(ctx: rule.Context, request_id: str) -> api.Result:
"""Retrieve a data request.

:param ctx: Combined type of a callback and rei struct
Expand Down Expand Up @@ -1195,7 +1195,7 @@ def api_datarequest_attachments_get(ctx: rule.Context, request_id: str) -> api.R
return attachments


def datarequest_attachments_get(ctx: rule.Context, request_id: str) -> Optional[List[str]]:
def datarequest_attachments_get(ctx: rule.Context, request_id: str) -> Optional[list[str]]:
"""Get all attachments of a given data request.

:param ctx: Combined type of a callback and rei struct
Expand Down Expand Up @@ -1245,7 +1245,7 @@ def api_datarequest_attachments_submit(ctx: rule.Context, request_id: str) -> ap


@api.make()
def api_datarequest_preliminary_review_submit(ctx: rule.Context, data: Dict, request_id: str) -> api.Result:
def api_datarequest_preliminary_review_submit(ctx: rule.Context, data: dict, request_id: str) -> api.Result:
"""Persist a preliminary review to disk.

:param ctx: Combined type of a callback and rei struct
Expand Down Expand Up @@ -1328,7 +1328,7 @@ def datarequest_preliminary_review_get(ctx: rule.Context, request_id: str) -> st


@api.make()
def api_datarequest_datamanager_review_submit(ctx: rule.Context, data: Dict, request_id: str) -> api.Result:
def api_datarequest_datamanager_review_submit(ctx: rule.Context, data: dict, request_id: str) -> api.Result:
"""Persist a datamanager review to disk.

:param ctx: Combined type of a callback and rei struct
Expand Down Expand Up @@ -1417,7 +1417,7 @@ def api_datarequest_dac_members_get(ctx: rule.Context, request_id: str) -> api.R
return datarequest_dac_members_get(ctx, request_id)


def datarequest_dac_members_get(ctx: rule.Context, request_id: str) -> List:
def datarequest_dac_members_get(ctx: rule.Context, request_id: str) -> list:
"""Get list of DAC members

:param ctx: Combined type of a callback and rei struct
Expand All @@ -1436,7 +1436,7 @@ def datarequest_dac_members_get(ctx: rule.Context, request_id: str) -> List:


@api.make()
def api_datarequest_assignment_submit(ctx: rule.Context, data: Dict, request_id: str) -> api.Result:
def api_datarequest_assignment_submit(ctx: rule.Context, data: dict, request_id: str) -> api.Result:
"""Persist an assignment to disk.

:param ctx: Combined type of a callback and rei struct
Expand Down Expand Up @@ -1578,7 +1578,7 @@ def datarequest_assignment_get(ctx: rule.Context, request_id: str) -> api.Result


@api.make()
def api_datarequest_review_submit(ctx: rule.Context, data: Dict, request_id: str) -> api.Result:
def api_datarequest_review_submit(ctx: rule.Context, data: dict, request_id: str) -> api.Result:
"""Persist a data request review to disk.

:param ctx: Combined type of a callback and rei struct
Expand Down Expand Up @@ -1676,7 +1676,7 @@ def api_datarequest_reviews_get(ctx: rule.Context, request_id: str) -> api.Resul


@api.make()
def api_datarequest_evaluation_submit(ctx: rule.Context, data: Dict, request_id: str) -> api.Result:
def api_datarequest_evaluation_submit(ctx: rule.Context, data: dict, request_id: str) -> api.Result:
"""Persist an evaluation to disk.

:param ctx: Combined type of a callback and rei struct
Expand Down Expand Up @@ -1868,7 +1868,7 @@ def api_datarequest_feedback_get(ctx: rule.Context, request_id: str) -> api.Resu


@api.make()
def api_datarequest_preregistration_submit(ctx: rule.Context, data: Dict, request_id: str) -> api.Result:
def api_datarequest_preregistration_submit(ctx: rule.Context, data: dict, request_id: str) -> api.Result:
"""Persist a preregistration to disk.

:param ctx: Combined type of a callback and rei struct
Expand Down
7 changes: 3 additions & 4 deletions deposit.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
"""Functions for deposit module."""
from __future__ import annotations

__copyright__ = 'Copyright (c) 2021-2025, Utrecht University'
__copyright__ = 'Copyright (c) 2021-2026, Utrecht University'
__license__ = 'GPLv3, see LICENSE'

import re
from collections import OrderedDict
from typing import Dict

import genquery
from genquery import AS_DICT, Query
Expand Down Expand Up @@ -100,7 +99,7 @@ def api_deposit_create(ctx: rule.Context, deposit_group: str) -> api.Result:
return {"deposit_path": result["deposit_path"]}


def deposit_create(ctx: rule.Context, deposit_group: str | None) -> Dict:
def deposit_create(ctx: rule.Context, deposit_group: str | None) -> dict:
"""Create deposit collection.

:param ctx: Combined type of a callback and rei struct
Expand Down Expand Up @@ -217,7 +216,7 @@ def api_deposit_overview(ctx: rule.Context,

:returns: Dict with paginated collection contents
"""
def transform(row: Dict) -> Dict:
def transform(row: dict) -> dict:
# Remove ORDER_BY etc. wrappers from column names.
x = {re.sub(r'.*\((.*)\)', '\\1', k): v for k, v in row.items()}

Expand Down
5 changes: 2 additions & 3 deletions epic.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
"""Functions for communicating with EPIC and some utilities."""

__copyright__ = 'Copyright (c) 2019-2024, Utrecht University'
__copyright__ = 'Copyright (c) 2019-2026, Utrecht University'
__license__ = 'GPLv3, see LICENSE'

import uuid
from typing import Dict

import publication
from util import *
Expand All @@ -21,7 +20,7 @@ def generate_uuid(ctx: rule.Context) -> str:
rule_generate_uuid = rule.make(inputs=[], outputs=[0])(generate_uuid)


def register_epic_pid(ctx: rule.Context, target: str) -> Dict:
def register_epic_pid(ctx: rule.Context, target: str) -> dict:
"""Create and try to register an EPIC PID.

:param ctx: Combined type of a callback and rei struct
Expand Down
Loading