-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcds.py
29 lines (21 loc) · 1.06 KB
/
cds.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from typing import Any
from cads_adaptors import constraints, costing
from cads_adaptors.adaptors import AbstractAdaptor, Request
class AbstractCdsAdaptor(AbstractAdaptor):
resources = {"CADS_ADAPTORS": 1}
def __init__(self, form: dict[str, Any], **config: Any):
self.form = form
self.collection_id = config.get("collection_id", "unknown-collection")
self.constraints = config.pop("constraints", [])
self.mapping = config.pop("mapping", {})
self.licences: list[tuple[str, int]] = config.pop("licences", [])
self.config = config
def validate(self, request: Request) -> bool:
return True
def apply_constraints(self, request: Request) -> dict[str, Any]:
return constraints.validate_constraints(self.form, request, self.constraints)
def estimate_costs(self, request: Request) -> dict[str, int]:
costs = {"size": costing.estimate_size(self.form, request, self.constraints)}
return costs
def get_licences(self, request: Request) -> list[tuple[str, int]]:
return self.licences