Created
February 20, 2020 10:49
-
-
Save prostomarkeloff/54c858e287e92f84a86eb5d1a130d4ef to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
import typing | |
def true_or_false() -> bool: | |
return random.choice([True, False]) | |
class TimeoutError(Exception): | |
pass | |
def random_result() -> typing.Union[dict, Exception]: | |
if true_or_false(): | |
return {"response": random.randint(100, 500)} | |
else: | |
try: | |
raise TimeoutError() | |
except TimeoutError as err: | |
return err | |
class RequestContext: | |
def __init__(self, **data): | |
self._data = data | |
self._result: typing.Optional[typing.Union[dict, Exception]] = None | |
@property | |
def result(self) -> typing.Optional[typing.Union[dict, Exception]]: | |
return self._result | |
def send(self) -> None: | |
self._result = random_result() | |
class Client: | |
def request(self, **data) -> RequestContext: | |
return RequestContext(**data) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment