Skip to content

Instantly share code, notes, and snippets.

@prostomarkeloff
Created February 20, 2020 10:49
Show Gist options
  • Save prostomarkeloff/54c858e287e92f84a86eb5d1a130d4ef to your computer and use it in GitHub Desktop.
Save prostomarkeloff/54c858e287e92f84a86eb5d1a130d4ef to your computer and use it in GitHub Desktop.
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