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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. from __future__ import annotations
  2. from typing import List, Optional, Sequence, Tuple
  3. from .. import frames
  4. from ..typing import ExtensionName, ExtensionParameter
  5. __all__ = ["Extension", "ClientExtensionFactory", "ServerExtensionFactory"]
  6. class Extension:
  7. """
  8. Base class for extensions.
  9. """
  10. name: ExtensionName
  11. """Extension identifier."""
  12. def decode(
  13. self,
  14. frame: frames.Frame,
  15. *,
  16. max_size: Optional[int] = None,
  17. ) -> frames.Frame:
  18. """
  19. Decode an incoming frame.
  20. Args:
  21. frame (Frame): incoming frame.
  22. max_size: maximum payload size in bytes.
  23. Returns:
  24. Frame: Decoded frame.
  25. Raises:
  26. PayloadTooBig: if decoding the payload exceeds ``max_size``.
  27. """
  28. raise NotImplementedError
  29. def encode(self, frame: frames.Frame) -> frames.Frame:
  30. """
  31. Encode an outgoing frame.
  32. Args:
  33. frame (Frame): outgoing frame.
  34. Returns:
  35. Frame: Encoded frame.
  36. """
  37. raise NotImplementedError
  38. class ClientExtensionFactory:
  39. """
  40. Base class for client-side extension factories.
  41. """
  42. name: ExtensionName
  43. """Extension identifier."""
  44. def get_request_params(self) -> List[ExtensionParameter]:
  45. """
  46. Build parameters to send to the server for this extension.
  47. Returns:
  48. List[ExtensionParameter]: Parameters to send to the server.
  49. """
  50. raise NotImplementedError
  51. def process_response_params(
  52. self,
  53. params: Sequence[ExtensionParameter],
  54. accepted_extensions: Sequence[Extension],
  55. ) -> Extension:
  56. """
  57. Process parameters received from the server.
  58. Args:
  59. params (Sequence[ExtensionParameter]): parameters received from
  60. the server for this extension.
  61. accepted_extensions (Sequence[Extension]): list of previously
  62. accepted extensions.
  63. Returns:
  64. Extension: An extension instance.
  65. Raises:
  66. NegotiationError: if parameters aren't acceptable.
  67. """
  68. raise NotImplementedError
  69. class ServerExtensionFactory:
  70. """
  71. Base class for server-side extension factories.
  72. """
  73. name: ExtensionName
  74. """Extension identifier."""
  75. def process_request_params(
  76. self,
  77. params: Sequence[ExtensionParameter],
  78. accepted_extensions: Sequence[Extension],
  79. ) -> Tuple[List[ExtensionParameter], Extension]:
  80. """
  81. Process parameters received from the client.
  82. Args:
  83. params (Sequence[ExtensionParameter]): parameters received from
  84. the client for this extension.
  85. accepted_extensions (Sequence[Extension]): list of previously
  86. accepted extensions.
  87. Returns:
  88. Tuple[List[ExtensionParameter], Extension]: To accept the offer,
  89. parameters to send to the client for this extension and an
  90. extension instance.
  91. Raises:
  92. NegotiationError: to reject the offer, if parameters received from
  93. the client aren't acceptable.
  94. """
  95. raise NotImplementedError