Funktionierender Prototyp des Serious Games zur Vermittlung von Wissen zu Software-Engineering-Arbeitsmodellen.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1 year ago
123456789101112131415161718192021222324252627282930313233343536373839404142
  1. from __future__ import annotations
  2. import typing
  3. from types import TracebackType
  4. def to_bytes(
  5. x: str | bytes, encoding: str | None = None, errors: str | None = None
  6. ) -> bytes:
  7. if isinstance(x, bytes):
  8. return x
  9. elif not isinstance(x, str):
  10. raise TypeError(f"not expecting type {type(x).__name__}")
  11. if encoding or errors:
  12. return x.encode(encoding or "utf-8", errors=errors or "strict")
  13. return x.encode()
  14. def to_str(
  15. x: str | bytes, encoding: str | None = None, errors: str | None = None
  16. ) -> str:
  17. if isinstance(x, str):
  18. return x
  19. elif not isinstance(x, bytes):
  20. raise TypeError(f"not expecting type {type(x).__name__}")
  21. if encoding or errors:
  22. return x.decode(encoding or "utf-8", errors=errors or "strict")
  23. return x.decode()
  24. def reraise(
  25. tp: type[BaseException] | None,
  26. value: BaseException,
  27. tb: TracebackType | None = None,
  28. ) -> typing.NoReturn:
  29. try:
  30. if value.__traceback__ is not tb:
  31. raise value.with_traceback(tb)
  32. raise value
  33. finally:
  34. value = None # type: ignore[assignment]
  35. tb = None