Skip to content
This repository has been archived by the owner on Jan 5, 2024. It is now read-only.

Commit

Permalink
Adds minimal type annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
kushaldas committed Jan 10, 2020
1 parent 51fd0cb commit c17bac9
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions securedrop_proxy/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,16 @@ def __init__(self, status: int) -> None:

class Proxy:
def __init__(
self, conf_path: str, req: Req = Req(), timeout: float = None,
self, conf_path: str, req: Req = Req(), timeout: float = 10.0
) -> None:
# The configuration path for Proxy is a must.
self.read_conf(conf_path)

self.req = req
self.res: Optional[Response] = None
self.timeout = float(timeout) if timeout else 10
self.timeout = float(timeout)

self._prepared_request = None
self._prepared_request: Optional[Req] = None

def on_done(self) -> None:
print(json.dumps(self.res.__dict__))
Expand Down Expand Up @@ -158,7 +158,7 @@ def on_save(self, fh: _TemporaryFileWrapper, res: Response) -> None:
res.headers["X-Origin-Content-Type"] = res.headers["Content-Type"]
res.body = json.dumps({"filename": fn})

def simple_error(self, status, err):
def simple_error(self, status: int, err: str) -> None:
res = Response(status)
res.body = json.dumps({"error": err})
res.headers = {"Content-Type": "application/json"}
Expand Down Expand Up @@ -203,7 +203,7 @@ def handle_json_response(self) -> None:

self.res = res

def handle_non_json_response(self):
def handle_non_json_response(self) -> None:

res = Response(self._presp.status_code)

Expand Down Expand Up @@ -242,13 +242,10 @@ def handle_response(self) -> None:
def proxy(self) -> None:

try:
if not self.on_save:
self.simple_error(
http.HTTPStatus.BAD_REQUEST, "Request on_save callback is not set."
)
raise ValueError("Request on_save callback is not set.")

self.prep_request()
# To confirm that we have a prepared request before the proxy call
assert self._prepared_request
logger.debug("Sending request")
s = requests.Session()
self._presp = s.send(self._prepared_request, timeout=self.timeout)
Expand Down

0 comments on commit c17bac9

Please sign in to comment.