From 81ee88fd4d795cecb0361115d7a7b4a4b0e00f82 Mon Sep 17 00:00:00 2001 From: William Woodruff Date: Wed, 5 Oct 2022 17:12:35 -0400 Subject: [PATCH] pyproject, abi3audit: use requests-cache instead of cachecontrol Less configuration, doesn't use multiple open files. Signed-off-by: William Woodruff --- abi3audit/_cache.py | 22 +++++----------------- pyproject.toml | 2 +- 2 files changed, 6 insertions(+), 18 deletions(-) diff --git a/abi3audit/_cache.py b/abi3audit/_cache.py index c2f8860..f7c31db 100644 --- a/abi3audit/_cache.py +++ b/abi3audit/_cache.py @@ -2,26 +2,14 @@ Caching middleware for `abi3audit`. """ -from pathlib import Path +from requests_cache import CachedSession -import requests -from cachecontrol import CacheControl -from cachecontrol.caches import FileCache -_ABI3AUDIT_INTERNAL_CACHE = Path.home() / ".cache" / "abi3audit" - - -def caching_session() -> CacheControl: +def caching_session() -> CachedSession: """ Return a `requests` style session, with suitable caching middleware. """ - # We limit the number of redirects to 5, since the services we connect to - # should really never redirect more than once or twice. - inner_session = requests.Session() - inner_session.max_redirects = 5 - - return CacheControl( - inner_session, - cache=FileCache(_ABI3AUDIT_INTERNAL_CACHE), - ) + session = CachedSession("abi3audit", use_cache_dir=True) + session.max_redirects = 5 + return session diff --git a/pyproject.toml b/pyproject.toml index 0cd77b6..6afdb60 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -22,12 +22,12 @@ classifiers = [ ] dependencies = [ "abi3info >= 0.0.5", - "CacheControl[filecache]>=0.12.10", "kaitaistruct ~= 0.10", "packaging ~= 21.3", "pefile >= 2022.5.30", "pyelftools >= 0.29", "requests ~= 2.28.1", + "requests-cache ~= 0.9.6", "rich ~= 12.5.1", ] requires-python = ">=3.10"