File: helpers.py

package info (click to toggle)
python-wsproto 1.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 436 kB
  • sloc: python: 4,195; makefile: 17; sh: 6
file content (29 lines) | stat: -rw-r--r-- 854 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from typing import Optional, Union

from wsproto.extensions import Extension


class FakeExtension(Extension):
    name = "fake"

    def __init__(
        self,
        offer_response: Optional[Union[bool, str]] = None,
        accept_response: Optional[Union[bool, str]] = None,
    ) -> None:
        self.offer_response = offer_response
        self.accepted_offer: Optional[str] = None
        self.offered: Optional[str] = None
        self.accept_response = accept_response

    def offer(self) -> Union[bool, str]:
        assert self.offer_response is not None
        return self.offer_response

    def finalize(self, offer: str) -> None:
        self.accepted_offer = offer

    def accept(self, offer: str) -> Union[bool, str]:
        assert self.accept_response is not None
        self.offered = offer
        return self.accept_response