Scheduled service maintenance on November 22


On Friday, November 22, 2024, between 06:00 CET and 18:00 CET, GIN services will undergo planned maintenance. Extended service interruptions should be expected. We will try to keep downtimes to a minimum, but recommend that users avoid critical tasks, large data uploads, or DOI requests during this time.

We apologize for any inconvenience.

memorymapper.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. from collections import defaultdict
  2. from typing import Any
  3. from dataladmetadatamodel.mapper.mapper import Mapper
  4. from dataladmetadatamodel.mapper.reference import Reference
  5. class MemoryMapper(Mapper):
  6. instance = None
  7. def __init__(self):
  8. super().__init__("memory")
  9. self.objects = dict()
  10. self.index = 1000
  11. def __call__(self, *args, **kwargs):
  12. return self
  13. def map_impl(self, reference: Reference) -> Any:
  14. index = int(reference.location)
  15. print(f"mapper: loading reference {reference}: {self.objects[index]}")
  16. return self.objects[index]
  17. def unmap_impl(self, obj) -> Reference:
  18. location = str(self.index)
  19. print(f"mapper: saving object {obj}: {location}")
  20. self.objects[self.index] = obj
  21. self.index += 1
  22. return Reference("memory", "memory", type(obj).__name__, location)
  23. @classmethod
  24. def get_instance(cls):
  25. if MemoryMapper.instance is None:
  26. MemoryMapper.instance = MemoryMapper()
  27. return MemoryMapper.instance
  28. MEMORY_MAPPER_FAMILY = defaultdict(MemoryMapper)
  29. MEMORY_MAPPER_LOCATIONS = ("0", "1")