single_set_proxy.py 724 B

123456789101112131415161718192021222324
  1. from .proxy import proxy
  2. from .model import model
  3. class single_set_proxy(proxy):
  4. def set(self, target: str) -> None:
  5. self._target.content = target
  6. def get(self) -> str:
  7. return self._target.content
  8. def __init_subclass__(cls, target_model: type) -> None:
  9. super().__init_subclass__()
  10. if type(target_model) is not type:
  11. raise TypeError("Target must be an class.")
  12. if not issubclass(target_model, model):
  13. raise TypeError("Target must be subclass of single_set_model.")
  14. cls.__target_model = target_model
  15. @classmethod
  16. def create(cls, content: str) -> proxy:
  17. return cls(cls.__target_model(content = content))