legalhold.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # -*- coding: utf-8 -*-
  2. # MinIO Python Library for Amazon S3 Compatible Cloud Storage, (C)
  3. # 2020 MinIO, Inc.
  4. #
  5. # Licensed under the Apache License, Version 2.0 (the "License");
  6. # you may not use this file except in compliance with the License.
  7. # You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16. """Request/response of PutObjectLegalHold and GetObjectLegalHold S3 APIs."""
  17. from __future__ import absolute_import, annotations
  18. from dataclasses import dataclass
  19. from typing import Optional, Type, TypeVar
  20. from xml.etree import ElementTree as ET
  21. from .xml import Element, SubElement, findtext
  22. A = TypeVar("A", bound="LegalHold")
  23. @dataclass(frozen=True)
  24. class LegalHold:
  25. """Legal hold configuration."""
  26. status: bool = False
  27. @classmethod
  28. def fromxml(cls: Type[A], element: ET.Element) -> A:
  29. """Create new object with values from XML element."""
  30. status = findtext(element, "Status")
  31. return cls(status=status == "ON")
  32. def toxml(self, element: Optional[ET.Element]) -> ET.Element:
  33. """Convert to XML."""
  34. element = Element("LegalHold")
  35. SubElement(element, "Status", "ON" if self.status is True else "OFF")
  36. return element