Skip to content

Commit 7b6a4d4

Browse files
committed
Reformat HTTP package and tests
1 parent 59d9b23 commit 7b6a4d4

File tree

13 files changed

+284
-190
lines changed

13 files changed

+284
-190
lines changed

gvm/http/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
# SPDX-FileCopyrightText: 2025 Greenbone AG
22
#
33
# SPDX-License-Identifier: GPL-3.0-or-later
4+
45
"""
56
Package for supported Greenbone HTTP APIs.
67
78
Currently only `openvasd version 1`_ is supported.
89
910
.. _openvasd version 1:
1011
https://greenbone.github.io/scanner-api/#/
11-
"""
12+
"""

gvm/http/core/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44

55
"""
66
HTTP core classes
7-
"""
7+
"""

gvm/http/core/_api.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ class GvmHttpApi:
1616
Base class for HTTP-based GVM APIs.
1717
"""
1818

19-
def __init__(self, connector: HttpApiConnector, *, api_key: Optional[str] = None):
19+
def __init__(
20+
self, connector: HttpApiConnector, *, api_key: Optional[str] = None
21+
):
2022
"""
2123
Create a new generic GVM HTTP API instance.
2224

gvm/http/core/connector.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
from gvm.http.core.response import HttpResponse
1515

16+
1617
class HttpApiConnector:
1718
"""
1819
Class for connecting to HTTP based API servers, sending requests and receiving the responses.
@@ -39,11 +40,11 @@ def url_join(cls, base: str, rel_path: str) -> str:
3940
return urllib.parse.urljoin(base + "/", rel_path)
4041

4142
def __init__(
42-
self,
43-
base_url: str,
44-
*,
45-
server_ca_path: Optional[str] = None,
46-
client_cert_paths: Optional[str | Tuple[str]] = None,
43+
self,
44+
base_url: str,
45+
*,
46+
server_ca_path: Optional[str] = None,
47+
client_cert_paths: Optional[str | Tuple[str]] = None,
4748
):
4849
"""
4950
Create a new HTTP API Connector.
@@ -81,8 +82,8 @@ def delete(
8182
rel_path: str,
8283
*,
8384
raise_for_status: bool = True,
84-
params: Optional[Dict[str,str]] = None,
85-
headers: Optional[Dict[str,str]] = None,
85+
params: Optional[Dict[str, str]] = None,
86+
headers: Optional[Dict[str, str]] = None,
8687
) -> HttpResponse:
8788
"""
8889
Sends a ``DELETE`` request and returns the response.
@@ -107,8 +108,8 @@ def get(
107108
rel_path: str,
108109
*,
109110
raise_for_status: bool = True,
110-
params: Optional[Dict[str,str]] = None,
111-
headers: Optional[Dict[str,str]] = None,
111+
params: Optional[Dict[str, str]] = None,
112+
headers: Optional[Dict[str, str]] = None,
112113
) -> HttpResponse:
113114
"""
114115
Sends a ``GET`` request and returns the response.

gvm/http/core/headers.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ class ContentType:
1717
"""
1818

1919
media_type: str
20-
"The MIME media type, e.g. \"application/json\""
20+
'The MIME media type, e.g. "application/json"'
2121

22-
params: Dict[str,str]
22+
params: Dict[str, str]
2323
"Dictionary of parameters in the content type header"
2424

2525
charset: Optional[str]
@@ -29,7 +29,7 @@ class ContentType:
2929
def from_string(
3030
cls,
3131
header_string: str,
32-
fallback_media_type: Optional[str] = "application/octet-stream"
32+
fallback_media_type: Optional[str] = "application/octet-stream",
3333
) -> Self:
3434
"""
3535
Parse the content of content type header into a ContentType object.
@@ -50,9 +50,11 @@ def from_string(
5050
if "=" in param:
5151
key, value = map(lambda x: x.strip(), param.split("=", 1))
5252
params[key] = value
53-
if key == 'charset':
53+
if key == "charset":
5454
charset = value
5555
else:
5656
params[param] = True
5757

58-
return ContentType(media_type=media_type, params=params, charset=charset)
58+
return ContentType(
59+
media_type=media_type, params=params, charset=charset
60+
)

gvm/http/core/response.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class HttpResponse:
1818
"""
1919
Class representing an HTTP response.
2020
"""
21+
2122
body: Any
2223
"The body of the response"
2324

@@ -45,13 +46,13 @@ def from_requests_lib(cls, r: Response) -> Self:
4546
If the content-type header in the response is set to 'application/json'.
4647
A non-empty body will be parsed accordingly.
4748
"""
48-
ct = ContentType.from_string(r.headers.get('content-type'))
49+
ct = ContentType.from_string(r.headers.get("content-type"))
4950
body = r.content
5051

51-
if r.content == b'':
52+
if r.content == b"":
5253
body = None
5354
elif ct is not None:
54-
if ct.media_type.lower() == 'application/json':
55+
if ct.media_type.lower() == "application/json":
5556
body = r.json()
5657

5758
return HttpResponse(body, r.status_code, r.headers, ct)

gvm/http/openvasd/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# SPDX-FileCopyrightText: 2025 Greenbone AG
22
#
33
# SPDX-License-Identifier: GPL-3.0-or-later
4+
45
"""
56
Package for sending openvasd and handling the responses of HTTP API requests.
67
78
* :class:`OpenvasdHttpApiV1` - openvasd version 1
8-
"""
9+
"""

0 commit comments

Comments
 (0)