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

Commit

Permalink
correct errors from running mypy and black
Browse files Browse the repository at this point in the history
  • Loading branch information
Allie Crevier committed May 17, 2021
1 parent 8ba39f2 commit 610104d
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 15 deletions.
14 changes: 11 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ safety: ## Runs `safety check` to check python dependencies for vulnerabilities
done

.PHONY: lint
lint: isort black ## Run isort, black and flake8
lint: isort-check black-check ## Run isort, black and flake8
@flake8 securedrop_proxy tests

.PHONY: mypy
Expand All @@ -37,11 +37,19 @@ mypy: ## Run mypy static type checker

.PHONY: black
black: ## Run black for file formatting
@black --config ./blackconfig/pyproject.toml --check securedrop_proxy tests
@black securedrop_proxy tests

.PHONY: black-check
black-check: ## Check Python source code formatting with black
@black --check --diff securedrop_proxy tests

.PHONY: isort
isort: ## Run isort for file formatting
@isort -c -w 100 securedrop_proxy/*.py tests/*.py --diff
@isort securedrop_proxy/*.py tests/*.py

.PHONY: isort-check
isort-check: ## Check isort for file formatting
@isort --check-only --diff securedrop_proxy/*.py tests/*.py

.PHONY: update-pip-requirements
update-pip-requirements: ## Updates all Python requirements files via pip-compile.
Expand Down
2 changes: 0 additions & 2 deletions blackconfig/pyproject.toml

This file was deleted.

5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[tool.black]
line-length = 100

[tool.isort]
line_length = 100
23 changes: 13 additions & 10 deletions securedrop_proxy/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from tempfile import _TemporaryFileWrapper # type: ignore
from typing import Dict, Optional

import furl
import furl # type: ignore
import requests
import werkzeug
import yaml
Expand All @@ -32,14 +32,14 @@ def __init__(self) -> None:
self.method = ""
self.path_query = ""
self.body = ""
self.headers: Dict[str, str] = {}
self.headers = {} # type: Dict[str, str]


class Response:
def __init__(self, status: int) -> None:
self.status = status
self.body = ""
self.headers: Dict[str, str] = {}
self.headers = {} # type: Dict[str, str]
self.version = version.version


Expand All @@ -48,10 +48,10 @@ def __init__(self, conf_path: str, req: Req = Req(), timeout: float = 10.0) -> N
self.read_conf(conf_path)

self.req = req
self.res: Optional[Response] = None
self.res = None # type: Optional[Response]
self.timeout = float(timeout)

self._prepared_request: Optional[Req] = None
self._prepared_request = None # type: Optional[requests.PreparedRequest]

def on_done(self) -> None:
print(json.dumps(self.res.__dict__))
Expand Down Expand Up @@ -79,12 +79,14 @@ def read_conf(self, conf_path: str) -> None:
conf_in = yaml.safe_load(fh)
except yaml.YAMLError:
self.simple_error(
500, "YAML syntax error while reading configuration file {}".format(conf_path),
500,
"YAML syntax error while reading configuration file {}".format(conf_path),
)
self.err_on_done()
except Exception:
self.simple_error(
500, "Error while opening or reading configuration file {}".format(conf_path),
500,
"Error while opening or reading configuration file {}".format(conf_path),
)
self.err_on_done()

Expand Down Expand Up @@ -186,7 +188,7 @@ def handle_json_response(self) -> None:

res = Response(self._presp.status_code)

res.headers = self._presp.headers
res.headers = dict(self._presp.headers)
res.body = self._presp.content.decode()

self.res = res
Expand All @@ -204,7 +206,7 @@ def handle_non_json_response(self) -> None:

fh.close()

res.headers = self._presp.headers
res.headers = dict(self._presp.headers)

self.on_save(fh, res)

Expand Down Expand Up @@ -259,7 +261,8 @@ def proxy(self) -> None:
logger.error(e)
try:
self.simple_error(
e.response.status_code, http.HTTPStatus(e.response.status_code).phrase.lower(),
e.response.status_code,
http.HTTPStatus(e.response.status_code).phrase.lower(),
)
except ValueError:
# Return a generic error message when the response
Expand Down

0 comments on commit 610104d

Please sign in to comment.