| |
@@ -0,0 +1,260 @@
|
| |
+ From 0767a6ed56decfc3edc9e003d253efc7b7f8ab56 Mon Sep 17 00:00:00 2001
|
| |
+ From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= <mgorny@gentoo.org>
|
| |
+ Date: Fri, 14 Oct 2022 21:34:05 +0200
|
| |
+ Subject: [PATCH] Use tomli/tomli-w instead of unmaintained toml (#596)
|
| |
+
|
| |
+ Replace the `toml` dependency that is unmaintained (last release
|
| |
+ in 2020) and does not implement TOML 1.0 with more modern `tomli`
|
| |
+ and `tomli-w` packages.
|
| |
+
|
| |
+ Co-authored-by: Maksim Beliaev <beliaev.m.s@gmail.com>
|
| |
+ ---
|
| |
+ responses/__init__.py | 4 ++--
|
| |
+ responses/_recorder.py | 18 +++++++++++++-----
|
| |
+ responses/tests/test_recorder.py | 11 ++++++-----
|
| |
+ setup.py | 4 ++--
|
| |
+ 4 files changed, 23 insertions(+), 14 deletions(-)
|
| |
+
|
| |
+ diff --git a/responses/__init__.py b/responses/__init__.py
|
| |
+ index 2a2c083..094c0e9 100644
|
| |
+ --- a/responses/__init__.py
|
| |
+ +++ b/responses/__init__.py
|
| |
+ @@ -25,7 +25,7 @@ from typing import Union
|
| |
+ from typing import overload
|
| |
+ from warnings import warn
|
| |
+
|
| |
+ -import toml as _toml
|
| |
+ +import tomli as _toml
|
| |
+ from requests.adapters import HTTPAdapter
|
| |
+ from requests.adapters import MaxRetryError
|
| |
+ from requests.exceptions import ConnectionError
|
| |
+ @@ -770,7 +770,7 @@ class RequestsMock(object):
|
| |
+ put = partialmethod(add, PUT)
|
| |
+
|
| |
+ def _add_from_file(self, file_path: "Union[str, bytes, os.PathLike[Any]]") -> None:
|
| |
+ - with open(file_path) as file:
|
| |
+ + with open(file_path, "rb") as file:
|
| |
+ data = _toml.load(file)
|
| |
+
|
| |
+ for rsp in data["responses"]:
|
| |
+ diff --git a/responses/_recorder.py b/responses/_recorder.py
|
| |
+ index 21f8317..b871f03 100644
|
| |
+ --- a/responses/_recorder.py
|
| |
+ +++ b/responses/_recorder.py
|
| |
+ @@ -2,10 +2,10 @@ from functools import wraps
|
| |
+ from typing import TYPE_CHECKING
|
| |
+
|
| |
+ if TYPE_CHECKING: # pragma: no cover
|
| |
+ - import io
|
| |
+ import os
|
| |
+
|
| |
+ from typing import Any
|
| |
+ + from typing import BinaryIO
|
| |
+ from typing import Callable
|
| |
+ from typing import Dict
|
| |
+ from typing import List
|
| |
+ @@ -18,7 +18,7 @@ if TYPE_CHECKING: # pragma: no cover
|
| |
+ from responses import _F
|
| |
+ from responses import BaseResponse
|
| |
+
|
| |
+ -import toml as _toml
|
| |
+ +import tomli_w as _toml
|
| |
+
|
| |
+ from responses import RequestsMock
|
| |
+ from responses import Response
|
| |
+ @@ -26,7 +26,15 @@ from responses import _real_send
|
| |
+ from responses.registries import OrderedRegistry
|
| |
+
|
| |
+
|
| |
+ -def _dump(registered: "List[BaseResponse]", destination: "io.IOBase") -> None:
|
| |
+ +def _remove_nones(d: "Any") -> "Any":
|
| |
+ + if isinstance(d, dict):
|
| |
+ + return {k: _remove_nones(v) for k, v in d.items() if v is not None}
|
| |
+ + if isinstance(d, list):
|
| |
+ + return [_remove_nones(i) for i in d]
|
| |
+ + return d
|
| |
+ +
|
| |
+ +
|
| |
+ +def _dump(registered: "List[BaseResponse]", destination: "BinaryIO") -> None:
|
| |
+ data: Dict[str, Any] = {"responses": []}
|
| |
+ for rsp in registered:
|
| |
+ try:
|
| |
+ @@ -49,7 +57,7 @@ def _dump(registered: "List[BaseResponse]", destination: "io.IOBase") -> None:
|
| |
+ "Cannot dump response object."
|
| |
+ "Probably you use custom Response object that is missing required attributes"
|
| |
+ ) from exc
|
| |
+ - _toml.dump(data, destination)
|
| |
+ + _toml.dump(_remove_nones(data), destination)
|
| |
+
|
| |
+
|
| |
+ class Recorder(RequestsMock):
|
| |
+ @@ -71,7 +79,7 @@ class Recorder(RequestsMock):
|
| |
+ def wrapper(*args: "Any", **kwargs: "Any") -> "Any": # type: ignore[misc]
|
| |
+ with self:
|
| |
+ ret = function(*args, **kwargs)
|
| |
+ - with open(file_path, "w") as file:
|
| |
+ + with open(file_path, "wb") as file:
|
| |
+ _dump(self.get_registry().registered, file)
|
| |
+
|
| |
+ return ret
|
| |
+ diff --git a/responses/tests/test_recorder.py b/responses/tests/test_recorder.py
|
| |
+ index d70d60f..d7c4008 100644
|
| |
+ --- a/responses/tests/test_recorder.py
|
| |
+ +++ b/responses/tests/test_recorder.py
|
| |
+ @@ -1,7 +1,8 @@
|
| |
+ from pathlib import Path
|
| |
+
|
| |
+ import requests
|
| |
+ -import toml
|
| |
+ +import tomli as _toml
|
| |
+ +import tomli_w
|
| |
+
|
| |
+ import responses
|
| |
+ from responses import _recorder
|
| |
+ @@ -94,8 +95,8 @@ class TestRecord:
|
| |
+
|
| |
+ run()
|
| |
+
|
| |
+ - with open(self.out_file) as file:
|
| |
+ - data = toml.load(file)
|
| |
+ + with open(self.out_file, "rb") as file:
|
| |
+ + data = _toml.load(file)
|
| |
+
|
| |
+ assert data == get_data(httpserver.host, httpserver.port)
|
| |
+
|
| |
+ @@ -109,8 +110,8 @@ class TestReplay:
|
| |
+ assert not out_file.exists()
|
| |
+
|
| |
+ def test_add_from_file(self):
|
| |
+ - with open("out.toml", "w") as file:
|
| |
+ - toml.dump(get_data("example.com", "8080"), file)
|
| |
+ + with open("out.toml", "wb") as file:
|
| |
+ + tomli_w.dump(get_data("example.com", "8080"), file)
|
| |
+
|
| |
+ @responses.activate
|
| |
+ def run():
|
| |
+ diff --git a/setup.py b/setup.py
|
| |
+ index 450b65a..f4447b5 100644
|
| |
+ --- a/setup.py
|
| |
+ +++ b/setup.py
|
| |
+ @@ -19,8 +19,8 @@ setup_requires = []
|
| |
+ install_requires = [
|
| |
+ "requests>=2.22.0,<3.0",
|
| |
+ "urllib3>=1.25.10",
|
| |
+ - "toml",
|
| |
+ - "types-toml",
|
| |
+ + "tomli",
|
| |
+ + "tomli-w",
|
| |
+ "typing_extensions; python_version < '3.8'",
|
| |
+ ]
|
| |
+
|
| |
+ --
|
| |
+ 2.38.1
|
| |
+
|
| |
+ From e11584a338fe83bc2b33eb1b4b8a353b813185eb Mon Sep 17 00:00:00 2001
|
| |
+ From: Maksim Beliaev <beliaev.m.s@gmail.com>
|
| |
+ Date: Mon, 21 Nov 2022 15:41:13 +0100
|
| |
+ Subject: [PATCH] added Python 3.11 support (#607)
|
| |
+
|
| |
+ * added Python 3.11 support
|
| |
+ * mypy
|
| |
+ ---
|
| |
+ responses/__init__.py | 7 ++++++-
|
| |
+ responses/_recorder.py | 4 ++--
|
| |
+ responses/tests/test_recorder.py | 2 +-
|
| |
+ setup.py | 3 ++-
|
| |
+ tox.ini | 2 +-
|
| |
+ 5 files changed, 12 insertions(+), 6 deletions(-)
|
| |
+
|
| |
+ diff --git a/responses/__init__.py b/responses/__init__.py
|
| |
+ index 094c0e9..fc6e675 100644
|
| |
+ --- a/responses/__init__.py
|
| |
+ +++ b/responses/__init__.py
|
| |
+ @@ -25,7 +25,12 @@ from typing import Union
|
| |
+ from typing import overload
|
| |
+ from warnings import warn
|
| |
+
|
| |
+ -import tomli as _toml
|
| |
+ +try:
|
| |
+ + import tomli as _toml
|
| |
+ +except ImportError:
|
| |
+ + # python 3.11
|
| |
+ + import tomllib as _toml # type: ignore[no-redef]
|
| |
+ +
|
| |
+ from requests.adapters import HTTPAdapter
|
| |
+ from requests.adapters import MaxRetryError
|
| |
+ from requests.exceptions import ConnectionError
|
| |
+ diff --git a/responses/_recorder.py b/responses/_recorder.py
|
| |
+ index b871f03..7142691 100644
|
| |
+ --- a/responses/_recorder.py
|
| |
+ +++ b/responses/_recorder.py
|
| |
+ @@ -18,7 +18,7 @@ if TYPE_CHECKING: # pragma: no cover
|
| |
+ from responses import _F
|
| |
+ from responses import BaseResponse
|
| |
+
|
| |
+ -import tomli_w as _toml
|
| |
+ +import tomli_w as _toml_w
|
| |
+
|
| |
+ from responses import RequestsMock
|
| |
+ from responses import Response
|
| |
+ @@ -57,7 +57,7 @@ def _dump(registered: "List[BaseResponse]", destination: "BinaryIO") -> None:
|
| |
+ "Cannot dump response object."
|
| |
+ "Probably you use custom Response object that is missing required attributes"
|
| |
+ ) from exc
|
| |
+ - _toml.dump(_remove_nones(data), destination)
|
| |
+ + _toml_w.dump(_remove_nones(data), destination)
|
| |
+
|
| |
+
|
| |
+ class Recorder(RequestsMock):
|
| |
+ diff --git a/responses/tests/test_recorder.py b/responses/tests/test_recorder.py
|
| |
+ index d7c4008..30134d7 100644
|
| |
+ --- a/responses/tests/test_recorder.py
|
| |
+ +++ b/responses/tests/test_recorder.py
|
| |
+ @@ -1,11 +1,11 @@
|
| |
+ from pathlib import Path
|
| |
+
|
| |
+ import requests
|
| |
+ -import tomli as _toml
|
| |
+ import tomli_w
|
| |
+
|
| |
+ import responses
|
| |
+ from responses import _recorder
|
| |
+ +from responses import _toml
|
| |
+
|
| |
+
|
| |
+ def get_data(host, port):
|
| |
+ diff --git a/setup.py b/setup.py
|
| |
+ index f4447b5..07a3714 100644
|
| |
+ --- a/setup.py
|
| |
+ +++ b/setup.py
|
| |
+ @@ -19,7 +19,7 @@ setup_requires = []
|
| |
+ install_requires = [
|
| |
+ "requests>=2.22.0,<3.0",
|
| |
+ "urllib3>=1.25.10",
|
| |
+ - "tomli",
|
| |
+ + "tomli; python_version < '3.11'",
|
| |
+ "tomli-w",
|
| |
+ "typing_extensions; python_version < '3.8'",
|
| |
+ ]
|
| |
+ @@ -91,6 +91,7 @@ setup(
|
| |
+ "Programming Language :: Python :: 3.8",
|
| |
+ "Programming Language :: Python :: 3.9",
|
| |
+ "Programming Language :: Python :: 3.10",
|
| |
+ + "Programming Language :: Python :: 3.11",
|
| |
+ "Topic :: Software Development",
|
| |
+ ],
|
| |
+ )
|
| |
+ diff --git a/tox.ini b/tox.ini
|
| |
+ index 294bbad..3455b60 100644
|
| |
+ --- a/tox.ini
|
| |
+ +++ b/tox.ini
|
| |
+ @@ -1,5 +1,5 @@
|
| |
+ [tox]
|
| |
+ -envlist = py37,py38,py39,py310,mypy,precom
|
| |
+ +envlist = py37,py38,py39,py310,py311,mypy,precom
|
| |
+
|
| |
+ [testenv]
|
| |
+ extras = tests
|
| |
+ --
|
| |
+ 2.38.1
|
| |
+
|
| |
https://fedoraproject.org/wiki/Changes/DeprecatePythonToml