py-euvd 0.2.0__tar.gz → 0.2.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. py_euvd-0.2.2/CHANGELOG.md +18 -0
  2. {py_euvd-0.2.0 → py_euvd-0.2.2}/PKG-INFO +1 -1
  3. py_euvd-0.2.2/pyeuvd/_version.py +1 -0
  4. {py_euvd-0.2.0 → py_euvd-0.2.2}/pyeuvd/response.py +5 -4
  5. {py_euvd-0.2.0 → py_euvd-0.2.2}/pyeuvd/transports/urllib_transport.py +67 -21
  6. {py_euvd-0.2.0 → py_euvd-0.2.2}/pyeuvd/utils.py +6 -1
  7. {py_euvd-0.2.0 → py_euvd-0.2.2}/pyproject.toml +1 -0
  8. {py_euvd-0.2.0 → py_euvd-0.2.2}/tests/server.py +3 -0
  9. {py_euvd-0.2.0 → py_euvd-0.2.2}/tests/test_response.py +8 -0
  10. {py_euvd-0.2.0 → py_euvd-0.2.2}/tests/test_urllib_transport.py +116 -3
  11. {py_euvd-0.2.0 → py_euvd-0.2.2}/tests/test_utils.py +1 -0
  12. py_euvd-0.2.0/CHANGELOG.md +0 -5
  13. py_euvd-0.2.0/pyeuvd/_version.py +0 -1
  14. {py_euvd-0.2.0 → py_euvd-0.2.2}/.gitignore +0 -0
  15. {py_euvd-0.2.0 → py_euvd-0.2.2}/LICENSE +0 -0
  16. {py_euvd-0.2.0 → py_euvd-0.2.2}/NOTICE +0 -0
  17. {py_euvd-0.2.0 → py_euvd-0.2.2}/README.md +0 -0
  18. {py_euvd-0.2.0 → py_euvd-0.2.2}/pyeuvd/__init__.py +0 -0
  19. {py_euvd-0.2.0 → py_euvd-0.2.2}/pyeuvd/async_client.py +0 -0
  20. {py_euvd-0.2.0 → py_euvd-0.2.2}/pyeuvd/base_client.py +0 -0
  21. {py_euvd-0.2.0 → py_euvd-0.2.2}/pyeuvd/client.py +0 -0
  22. {py_euvd-0.2.0 → py_euvd-0.2.2}/pyeuvd/constants.py +0 -0
  23. {py_euvd-0.2.0 → py_euvd-0.2.2}/pyeuvd/errors.py +0 -0
  24. {py_euvd-0.2.0 → py_euvd-0.2.2}/pyeuvd/filters.py +0 -0
  25. {py_euvd-0.2.0 → py_euvd-0.2.2}/pyeuvd/models/__init__.py +0 -0
  26. {py_euvd-0.2.0 → py_euvd-0.2.2}/pyeuvd/models/advisory.py +0 -0
  27. {py_euvd-0.2.0 → py_euvd-0.2.2}/pyeuvd/models/advisory_detail.py +0 -0
  28. {py_euvd-0.2.0 → py_euvd-0.2.2}/pyeuvd/models/kev_entry.py +0 -0
  29. {py_euvd-0.2.0 → py_euvd-0.2.2}/pyeuvd/models/model.py +0 -0
  30. {py_euvd-0.2.0 → py_euvd-0.2.2}/pyeuvd/models/page.py +0 -0
  31. {py_euvd-0.2.0 → py_euvd-0.2.2}/pyeuvd/models/product.py +0 -0
  32. {py_euvd-0.2.0 → py_euvd-0.2.2}/pyeuvd/models/record.py +0 -0
  33. {py_euvd-0.2.0 → py_euvd-0.2.2}/pyeuvd/models/source_record.py +0 -0
  34. {py_euvd-0.2.0 → py_euvd-0.2.2}/pyeuvd/models/vulnerability.py +0 -0
  35. {py_euvd-0.2.0 → py_euvd-0.2.2}/pyeuvd/models/vulnerability_detail.py +0 -0
  36. {py_euvd-0.2.0 → py_euvd-0.2.2}/pyeuvd/parsing.py +0 -0
  37. {py_euvd-0.2.0 → py_euvd-0.2.2}/pyeuvd/py.typed +0 -0
  38. {py_euvd-0.2.0 → py_euvd-0.2.2}/pyeuvd/transports/__init__.py +0 -0
  39. {py_euvd-0.2.0 → py_euvd-0.2.2}/pyeuvd/transports/async_transport.py +0 -0
  40. {py_euvd-0.2.0 → py_euvd-0.2.2}/pyeuvd/transports/threaded_transport.py +0 -0
  41. {py_euvd-0.2.0 → py_euvd-0.2.2}/pyeuvd/transports/transport.py +0 -0
  42. {py_euvd-0.2.0 → py_euvd-0.2.2}/tests/__init__.py +0 -0
  43. {py_euvd-0.2.0 → py_euvd-0.2.2}/tests/conftest.py +0 -0
  44. {py_euvd-0.2.0 → py_euvd-0.2.2}/tests/fakes.py +0 -0
  45. {py_euvd-0.2.0 → py_euvd-0.2.2}/tests/fixtures/advisory.json +0 -0
  46. {py_euvd-0.2.0 → py_euvd-0.2.2}/tests/fixtures/cve_mapping.csv +0 -0
  47. {py_euvd-0.2.0 → py_euvd-0.2.2}/tests/fixtures/exploited.json +0 -0
  48. {py_euvd-0.2.0 → py_euvd-0.2.2}/tests/fixtures/kev.json +0 -0
  49. {py_euvd-0.2.0 → py_euvd-0.2.2}/tests/fixtures/latest.json +0 -0
  50. {py_euvd-0.2.0 → py_euvd-0.2.2}/tests/fixtures/search.json +0 -0
  51. {py_euvd-0.2.0 → py_euvd-0.2.2}/tests/fixtures/vulnerability.json +0 -0
  52. {py_euvd-0.2.0 → py_euvd-0.2.2}/tests/test_async_client.py +0 -0
  53. {py_euvd-0.2.0 → py_euvd-0.2.2}/tests/test_client.py +0 -0
  54. {py_euvd-0.2.0 → py_euvd-0.2.2}/tests/test_live.py +0 -0
  55. {py_euvd-0.2.0 → py_euvd-0.2.2}/tests/test_models.py +0 -0
  56. {py_euvd-0.2.0 → py_euvd-0.2.2}/tests/test_parsing.py +0 -0
  57. {py_euvd-0.2.0 → py_euvd-0.2.2}/tests/test_transports.py +0 -0
@@ -0,0 +1,18 @@
1
+ # Changelog
2
+
3
+ ## 0.2.2 (2026-11-27)
4
+
5
+ - Security: the built-in transport no longer follows a redirect to an `ftp://` address. The request fails with an `APIError` instead.
6
+ - Security: `UrllibTransport` now raises `ValueError` for any address that is not `http://` or `https://`, such as `file:` or `data:`.
7
+ - Security: `UrllibTransport` refuses a response larger than 50 MB and raises `EUVDError`. The new `max_bytes` option changes the limit. For `cve_mapping()` the limit applies to each line.
8
+ - Security: control characters in text from the server are replaced with spaces in error messages.
9
+ - JSON that is nested too deeply now raises `EUVDError` instead of `RecursionError`.
10
+
11
+ ## 0.2.1 (2026-11-27)
12
+
13
+ - Security: headers set with `UrllibTransport(headers=...)` are no longer sent along when the server redirects a request. A replaced `User-Agent` or `Accept` still follows redirects.
14
+ - `UrllibTransport.headers` now holds only the headers you passed in, without the defaults.
15
+
16
+ ## 0.2.0 (2026-11-27)
17
+
18
+ First public release. Version 0.1.0 was never published.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: py-euvd
3
- Version: 0.2.0
3
+ Version: 0.2.2
4
4
  Summary: Dependency-free Python client for the EU Vulnerability Database (EUVD) API
5
5
  Project-URL: Documentation, https://py-euvd.spoons.fyi
6
6
  Project-URL: Repository, https://github.com/dmuhs/py-euvd
@@ -0,0 +1 @@
1
+ __version__ = "0.2.2"
@@ -6,6 +6,7 @@ from http import HTTPStatus
6
6
  from typing import Any
7
7
 
8
8
  from .errors import APIError, EUVDError, NotFoundError
9
+ from .utils import printable
9
10
 
10
11
 
11
12
  @dataclass(frozen=True, slots=True)
@@ -23,7 +24,7 @@ class Response:
23
24
  """Decode the body as JSON. Raises ``EUVDError`` if it is not JSON."""
24
25
  try:
25
26
  return json.loads(self.body)
26
- except ValueError as exc:
27
+ except (ValueError, RecursionError) as exc:
27
28
  raise EUVDError("the API did not return JSON") from exc
28
29
 
29
30
  def raise_for_status(self) -> None:
@@ -35,10 +36,10 @@ class Response:
35
36
 
36
37
  def _error_message(self) -> str:
37
38
  try:
38
- return str(json.loads(self.body)["error"])
39
- except (ValueError, KeyError, TypeError):
39
+ return printable(str(json.loads(self.body)["error"]))
40
+ except (ValueError, KeyError, TypeError, RecursionError):
40
41
  pass
41
- text = self.body.decode("utf-8", "replace").strip()[:200]
42
+ text = printable(self.body.decode("utf-8", "replace").strip()[:200])
42
43
  if text:
43
44
  return text
44
45
  try:
@@ -3,13 +3,14 @@ from __future__ import annotations
3
3
  import logging
4
4
  import time
5
5
  import urllib.error
6
+ import urllib.parse
6
7
  import urllib.request
7
8
  from collections.abc import Generator, Mapping
8
- from http.client import HTTPException
9
- from typing import Any
9
+ from http.client import HTTPException, HTTPMessage
10
+ from typing import IO, Any
10
11
 
11
12
  from ..constants import DEFAULT_TIMEOUT, USER_AGENT
12
- from ..errors import APIError, TransportError
13
+ from ..errors import APIError, EUVDError, TransportError
13
14
  from ..response import Response
14
15
  from ..utils import describe_error, is_certificate_error
15
16
  from .transport import Transport
@@ -19,6 +20,27 @@ logger = logging.getLogger(__name__)
19
20
  # Statuses that mean "try again later".
20
21
  RETRY_STATUSES = frozenset({429, 502, 503, 504})
21
22
 
23
+ DEFAULT_HEADERS = {"User-Agent": USER_AGENT, "Accept": "application/json, text/csv"}
24
+
25
+ SCHEMES = ("http", "https")
26
+
27
+
28
+ class _RedirectHandler(urllib.request.HTTPRedirectHandler):
29
+ """Leaves a redirect to anything but http or https unfollowed. urllib allows ftp."""
30
+
31
+ def redirect_request(
32
+ self,
33
+ req: urllib.request.Request,
34
+ fp: IO[bytes],
35
+ code: int,
36
+ msg: str,
37
+ headers: HTTPMessage,
38
+ newurl: str,
39
+ ) -> urllib.request.Request | None:
40
+ if urllib.parse.urlsplit(newurl).scheme not in SCHEMES:
41
+ return None
42
+ return super().redirect_request(req, fp, code, msg, headers, newurl)
43
+
22
44
 
23
45
  class UrllibTransport(Transport):
24
46
  """The default transport. Uses only the Python standard library.
@@ -30,7 +52,18 @@ class UrllibTransport(Transport):
30
52
 
31
53
  Proxies set in the environment (``HTTPS_PROXY``) are used automatically.
32
54
  Pass your own ``urllib.request`` opener for other connection settings,
33
- and ``headers`` to send extra headers with every request.
55
+ and ``headers`` to send extra headers with every request. Extra headers
56
+ are not sent along when the server redirects the request, except a
57
+ replaced ``User-Agent`` or ``Accept``.
58
+
59
+ Only ``http`` and ``https`` addresses are fetched. Any other address
60
+ raises ``ValueError``, and a redirect to one is not followed. Your own
61
+ opener follows redirects by its own rules.
62
+
63
+ A response larger than ``max_bytes`` raises ``EUVDError``. For
64
+ ``stream_lines`` the limit applies to each line.
65
+
66
+ ``timeout`` limits each wait for data, not the whole request.
34
67
  """
35
68
 
36
69
  def __init__(
@@ -41,16 +74,14 @@ class UrllibTransport(Transport):
41
74
  backoff: float = 0.5,
42
75
  opener: urllib.request.OpenerDirector | None = None,
43
76
  headers: Mapping[str, str] | None = None,
77
+ max_bytes: int = 50_000_000,
44
78
  ) -> None:
45
79
  self.timeout = timeout
46
80
  self.retries = retries
47
81
  self.backoff = backoff
48
- self.opener = opener or urllib.request.build_opener()
49
- self.headers = {
50
- "User-Agent": USER_AGENT,
51
- "Accept": "application/json, text/csv",
52
- **(headers or {}),
53
- }
82
+ self.opener = opener or urllib.request.build_opener(_RedirectHandler)
83
+ self.headers = dict(headers or {})
84
+ self.max_bytes = max_bytes
54
85
 
55
86
  def get(self, url: str) -> Response:
56
87
  attempt = 0
@@ -92,7 +123,9 @@ class UrllibTransport(Transport):
92
123
  def _get_once(self, url: str) -> Response:
93
124
  try:
94
125
  with self._open(url) as reply:
95
- return Response(reply.status, reply.read())
126
+ body = self._limited(reply.read(self.max_bytes + 1))
127
+ self._check_complete(reply, len(body))
128
+ return Response(reply.status, body)
96
129
  except urllib.error.HTTPError as exc:
97
130
  return self._error_response(exc)
98
131
  except (OSError, HTTPException) as exc:
@@ -101,34 +134,47 @@ class UrllibTransport(Transport):
101
134
  def _stream_once(self, url: str) -> Generator[str, None, None]:
102
135
  try:
103
136
  with self._open(url) as reply:
104
- expected = reply.headers.get("Content-Length")
105
137
  received = 0
106
- for line in reply:
138
+ while line := self._limited(reply.readline(self.max_bytes + 1)):
107
139
  received += len(line)
108
140
  yield line.decode("utf-8", "replace").rstrip("\r\n")
109
- if expected is not None and received != int(expected):
110
- raise TransportError(
111
- f"download ended early: got {received} of {expected} bytes"
112
- )
141
+ self._check_complete(reply, received)
113
142
  except urllib.error.HTTPError as exc:
114
143
  self._error_response(exc).raise_for_status()
115
144
  except (OSError, HTTPException) as exc:
116
145
  raise TransportError(describe_error(exc)) from exc
117
146
 
147
+ def _limited(self, data: bytes) -> bytes:
148
+ if len(data) > self.max_bytes:
149
+ raise EUVDError(f"the response is larger than {self.max_bytes} bytes")
150
+ return data
151
+
152
+ @staticmethod
153
+ def _check_complete(reply: Any, received: int) -> None:
154
+ expected = reply.headers.get("Content-Length", "")
155
+ if expected.isdecimal() and received < int(expected):
156
+ raise TransportError(f"download ended early: got {received} of {expected} bytes")
157
+
118
158
  def _wait(self, attempt: int, url: str, problem: str) -> None:
119
159
  delay = self.backoff * 2**attempt
120
160
  logger.debug("GET %s failed (%s), retrying in %.1f s", url, problem, delay)
121
161
  time.sleep(delay)
122
162
 
123
163
  def _open(self, url: str) -> Any:
124
- request = urllib.request.Request(url, headers=self.headers)
164
+ request = urllib.request.Request(url, headers=DEFAULT_HEADERS)
165
+ if request.type not in SCHEMES:
166
+ raise ValueError("url must start with http:// or https://")
167
+ for name, value in self.headers.items():
168
+ if request.has_header(name.capitalize()):
169
+ request.add_header(name, value)
170
+ else:
171
+ request.add_unredirected_header(name, value)
125
172
  return self.opener.open(request, timeout=self.timeout)
126
173
 
127
- @staticmethod
128
- def _error_response(error: urllib.error.HTTPError) -> Response:
174
+ def _error_response(self, error: urllib.error.HTTPError) -> Response:
129
175
  """Turn the exception urllib raises for error statuses into a response."""
130
176
  try:
131
- body = error.read()
177
+ body = error.read(self.max_bytes)
132
178
  except (OSError, HTTPException):
133
179
  body = b""
134
180
  finally:
@@ -88,4 +88,9 @@ def is_certificate_error(error: BaseException | None) -> bool:
88
88
  def describe_error(error: BaseException) -> str:
89
89
  """Return a short reason for a network error."""
90
90
  reason = getattr(error, "reason", None)
91
- return str(reason or error) or type(error).__name__
91
+ return printable(str(reason or error)) or type(error).__name__
92
+
93
+
94
+ def printable(text: str) -> str:
95
+ """Replace control characters with spaces, so text from a server is safe to log."""
96
+ return "".join(char if char.isprintable() else " " for char in text)
@@ -34,6 +34,7 @@ Changelog = "https://github.com/dmuhs/py-euvd/blob/main/CHANGELOG.md"
34
34
  [dependency-groups]
35
35
  dev = ["mypy>=1.13", "pytest>=8", "pytest-cov>=6", "ruff>=0.8"]
36
36
  docs = ["mkdocstrings-python>=2", "zensical>=0.1.3"]
37
+ build = ["hatch-vcs>=0.4", "hatchling>=1.27"]
37
38
 
38
39
  [build-system]
39
40
  requires = ["hatchling>=1.27", "hatch-vcs>=0.4"]
@@ -22,6 +22,7 @@ class Reply:
22
22
  body: bytes = b""
23
23
  declared_length: int | None = None # set higher than the body to cut the response short
24
24
  delay: float = 0.0
25
+ location: str | None = None
25
26
 
26
27
 
27
28
  @dataclass
@@ -50,6 +51,8 @@ class Handler(BaseHTTPRequestHandler):
50
51
  try:
51
52
  self.send_response(reply.status)
52
53
  self.send_header("Content-Length", str(length))
54
+ if reply.location:
55
+ self.send_header("Location", reply.location)
53
56
  self.end_headers()
54
57
  self.wfile.write(reply.body)
55
58
  except OSError:
@@ -22,6 +22,11 @@ def test_json_rejects_other_content():
22
22
  Response(200, b"<html>maintenance</html>").json()
23
23
 
24
24
 
25
+ def test_json_rejects_deep_nesting():
26
+ with pytest.raises(EUVDError, match="did not return JSON"):
27
+ Response(200, b"[" * 100_000).json()
28
+
29
+
25
30
  def test_raise_for_status_passes_on_success():
26
31
  Response(200, b"[]").raise_for_status()
27
32
 
@@ -52,6 +57,9 @@ def test_other_errors_are_api_errors():
52
57
  (500, b"x" * 500, "x" * 200), # long bodies are cut
53
58
  (502, b"", "Bad Gateway"), # no body: use the standard status text
54
59
  (599, b"", "HTTP error"), # no body and an unknown status
60
+ (500, b"[" * 100_000, "[" * 200), # nested too deeply to parse
61
+ (400, b'{"error": "bad\\n\\u001b[31mid"}', "bad [31mid"), # control characters
62
+ (500, b"down\r\n\x1b[2Jnow", "down [2Jnow"),
55
63
  ],
56
64
  )
57
65
  def test_error_message_fallbacks(status, body, message):
@@ -3,19 +3,29 @@
3
3
  from __future__ import annotations
4
4
 
5
5
  import asyncio
6
+ import io
6
7
  import socket
7
8
  import ssl
8
9
  import urllib.request
10
+ from email.message import Message
9
11
  from types import SimpleNamespace
10
- from urllib.error import URLError
12
+ from urllib.error import HTTPError, URLError
11
13
 
12
14
  import pytest
13
15
 
14
- from pyeuvd import EUVD, APIError, AsyncEUVD, TransportError, UrllibTransport, __version__
16
+ from pyeuvd import (
17
+ EUVD,
18
+ APIError,
19
+ AsyncEUVD,
20
+ EUVDError,
21
+ TransportError,
22
+ UrllibTransport,
23
+ __version__,
24
+ )
15
25
  from pyeuvd.transports import urllib_transport
16
26
 
17
27
  from .fakes import load_json, load_text
18
- from .server import Reply
28
+ from .server import Reply, run_local_api
19
29
 
20
30
  BUSY = Reply(status=503, body=b'{"error": "busy"}')
21
31
  CUT_OFF = Reply(body=b"[", declared_length=100)
@@ -269,6 +279,19 @@ def test_certificate_failures_are_not_retried():
269
279
  assert opener.calls == 2
270
280
 
271
281
 
282
+ def test_get_keeps_the_status_when_the_error_body_cannot_be_read():
283
+ class BrokenBody(io.BytesIO):
284
+ def read(self, *args):
285
+ raise ConnectionResetError
286
+
287
+ error = HTTPError("https://x.test/api/kev/dump", 500, "boom", Message(), BrokenBody())
288
+ transport = UrllibTransport(opener=FailingOpener(error), retries=0)
289
+
290
+ response = transport.get("https://x.test/api/kev/dump")
291
+
292
+ assert (response.status, response.body) == (500, b"")
293
+
294
+
272
295
  def test_other_connection_failures_are_retried():
273
296
  opener = FailingOpener(URLError(ConnectionRefusedError("refused")))
274
297
  transport = UrllibTransport(opener=opener, retries=2, backoff=0)
@@ -293,3 +316,93 @@ def test_proxy_from_the_environment_is_used(api, monkeypatch):
293
316
 
294
317
  assert response.json() == load_json("kev.json")
295
318
  assert api.headers[0]["host"] == "euvd.invalid"
319
+
320
+
321
+ SECRETS = {"Authorization": "Bearer secret", "Cookie": "session=abc", "X-Api-Key": "k"}
322
+
323
+
324
+ def test_extra_headers_are_not_sent_to_another_host(api):
325
+ with run_local_api() as other:
326
+ api.replies["/kev/dump"] = Reply(status=302, location=other.url + "/kev/dump")
327
+ transport = UrllibTransport(retries=0, headers={**SECRETS, "User-Agent": "my-app/1.0"})
328
+
329
+ response = transport.get(api.url + "/kev/dump")
330
+
331
+ assert response.json() == load_json("kev.json")
332
+ first, redirected = api.headers[0], other.headers[0]
333
+ assert {name.lower(): first[name.lower()] for name in SECRETS} == {
334
+ name.lower(): value for name, value in SECRETS.items()
335
+ }
336
+ assert first["user-agent"] == "my-app/1.0"
337
+ assert not {name.lower() for name in SECRETS} & redirected.keys()
338
+ assert redirected["user-agent"] == "my-app/1.0"
339
+ assert "application/json" in redirected["accept"]
340
+
341
+
342
+ def test_extra_headers_are_not_sent_on_a_redirect_to_the_same_host(api):
343
+ api.replies["/old"] = Reply(status=301, location=api.url + "/kev/dump")
344
+
345
+ UrllibTransport(retries=0, headers=SECRETS).get(api.url + "/old")
346
+
347
+ assert "authorization" in api.headers[0]
348
+ assert not {name.lower() for name in SECRETS} & api.headers[1].keys()
349
+
350
+
351
+ def test_extra_headers_are_not_sent_along_when_a_download_is_redirected(api):
352
+ with run_local_api() as other:
353
+ api.replies["/dump/cve-euvd-mapping"] = Reply(
354
+ status=302, location=other.url + "/dump/cve-euvd-mapping"
355
+ )
356
+ transport = UrllibTransport(retries=0, headers=SECRETS)
357
+
358
+ lines = list(transport.stream_lines(api.url + "/dump/cve-euvd-mapping"))
359
+
360
+ assert lines[0] == "euvd_id,cve_id"
361
+ assert "authorization" in api.headers[0]
362
+ assert not {name.lower() for name in SECRETS} & other.headers[0].keys()
363
+
364
+
365
+ def test_a_redirect_to_ftp_is_not_followed(transport, api, unused_url):
366
+ api.replies["/kev/dump"] = Reply(status=302, location=unused_url.replace("http", "ftp", 1))
367
+
368
+ assert transport.get(api.url + "/kev/dump").status == 302
369
+ with pytest.raises(APIError, match="302"):
370
+ EUVD(base_url=api.url).kev()
371
+
372
+
373
+ @pytest.mark.parametrize("url", ["file:///etc/hostname", "data:,hello", "ftp://x.test/file"])
374
+ def test_only_http_addresses_are_fetched(transport, url):
375
+ with pytest.raises(ValueError, match="http://"):
376
+ transport.get(url)
377
+ with pytest.raises(ValueError, match="http://"):
378
+ list(transport.stream_lines(url))
379
+
380
+
381
+ def test_a_response_over_the_size_limit_is_refused(api):
382
+ transport = UrllibTransport(retries=2, backoff=0, max_bytes=10)
383
+ api.replies["/kev/dump"] = Reply(body=b"x" * 11)
384
+ api.replies["/advisory"] = Reply(body=b"x" * 10)
385
+
386
+ with pytest.raises(EUVDError, match="larger than 10 bytes"):
387
+ transport.get(api.url + "/kev/dump")
388
+ assert len(api.headers) == 1
389
+ assert transport.get(api.url + "/advisory").body == b"x" * 10
390
+
391
+
392
+ def test_stream_lines_refuses_a_line_over_the_size_limit(api):
393
+ api.replies["/dump/cve-euvd-mapping"] = Reply(body=b"a,b\n" + b"x" * 11)
394
+ lines = UrllibTransport(retries=2, backoff=0, max_bytes=10).stream_lines(
395
+ api.url + "/dump/cve-euvd-mapping"
396
+ )
397
+
398
+ assert next(lines) == "a,b"
399
+ with pytest.raises(EUVDError, match="larger than 10 bytes"):
400
+ next(lines)
401
+
402
+
403
+ def test_an_error_body_over_the_size_limit_is_cut(api):
404
+ api.replies["/kev/dump"] = Reply(status=500, body=b"x" * 50)
405
+
406
+ response = UrllibTransport(retries=0, max_bytes=10).get(api.url + "/kev/dump")
407
+
408
+ assert (response.status, response.body) == (500, b"x" * 10)
@@ -111,6 +111,7 @@ def test_describe_error():
111
111
  assert utils.describe_error(TimeoutError("timed out")) == "timed out"
112
112
  assert utils.describe_error(URLError("no route to host")) == "no route to host"
113
113
  assert utils.describe_error(ConnectionResetError()) == "ConnectionResetError"
114
+ assert utils.describe_error(URLError("bad\x1b[31m\nline")) == "bad [31m line"
114
115
 
115
116
 
116
117
  @pytest.mark.parametrize(
@@ -1,5 +0,0 @@
1
- # Changelog
2
-
3
- ## 0.2.0 (2026-11-27)
4
-
5
- First public release. Version 0.1.0 was never published.
@@ -1 +0,0 @@
1
- __version__ = "0.2.0"
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes