CacheControl 0.14.3__tar.gz → 0.14.4__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.
- {cachecontrol-0.14.3 → cachecontrol-0.14.4}/PKG-INFO +23 -24
- {cachecontrol-0.14.3 → cachecontrol-0.14.4}/cachecontrol/__init__.py +5 -3
- {cachecontrol-0.14.3 → cachecontrol-0.14.4}/cachecontrol/adapter.py +0 -1
- {cachecontrol-0.14.3 → cachecontrol-0.14.4}/cachecontrol/controller.py +1 -1
- {cachecontrol-0.14.3 → cachecontrol-0.14.4}/cachecontrol/filewrapper.py +3 -1
- {cachecontrol-0.14.3 → cachecontrol-0.14.4}/pyproject.toml +13 -12
- cachecontrol-0.14.3/tests/__init__.py +0 -1
- cachecontrol-0.14.3/tests/conftest.py +0 -164
- cachecontrol-0.14.3/tests/issue_263.py +0 -47
- cachecontrol-0.14.3/tests/test_adapter.py +0 -96
- cachecontrol-0.14.3/tests/test_cache_control.py +0 -307
- cachecontrol-0.14.3/tests/test_chunked_response.py +0 -56
- cachecontrol-0.14.3/tests/test_etag.py +0 -177
- cachecontrol-0.14.3/tests/test_expires_heuristics.py +0 -205
- cachecontrol-0.14.3/tests/test_max_age.py +0 -57
- cachecontrol-0.14.3/tests/test_redirects.py +0 -55
- cachecontrol-0.14.3/tests/test_regressions.py +0 -33
- cachecontrol-0.14.3/tests/test_serialization.py +0 -116
- cachecontrol-0.14.3/tests/test_server_http_version.py +0 -12
- cachecontrol-0.14.3/tests/test_storage_filecache.py +0 -173
- cachecontrol-0.14.3/tests/test_storage_redis.py +0 -26
- cachecontrol-0.14.3/tests/test_vary.py +0 -84
- cachecontrol-0.14.3/tests/utils.py +0 -38
- {cachecontrol-0.14.3 → cachecontrol-0.14.4}/LICENSE.txt +0 -0
- {cachecontrol-0.14.3 → cachecontrol-0.14.4}/README.rst +0 -0
- {cachecontrol-0.14.3 → cachecontrol-0.14.4}/cachecontrol/_cmd.py +0 -0
- {cachecontrol-0.14.3 → cachecontrol-0.14.4}/cachecontrol/cache.py +0 -0
- {cachecontrol-0.14.3 → cachecontrol-0.14.4}/cachecontrol/caches/__init__.py +0 -0
- {cachecontrol-0.14.3 → cachecontrol-0.14.4}/cachecontrol/caches/file_cache.py +0 -0
- {cachecontrol-0.14.3 → cachecontrol-0.14.4}/cachecontrol/caches/redis_cache.py +0 -0
- {cachecontrol-0.14.3 → cachecontrol-0.14.4}/cachecontrol/heuristics.py +0 -0
- {cachecontrol-0.14.3 → cachecontrol-0.14.4}/cachecontrol/py.typed +0 -0
- {cachecontrol-0.14.3 → cachecontrol-0.14.4}/cachecontrol/serialize.py +0 -0
- {cachecontrol-0.14.3 → cachecontrol-0.14.4}/cachecontrol/wrapper.py +0 -0
|
@@ -1,46 +1,46 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: CacheControl
|
|
3
|
-
Version: 0.14.
|
|
3
|
+
Version: 0.14.4
|
|
4
4
|
Summary: httplib2 caching for requests
|
|
5
5
|
Keywords: requests,http,caching,web
|
|
6
|
+
Author: Eric Larson, Frost Ming, William Woodruff
|
|
6
7
|
Author-email: Eric Larson <ericlarson@ionrock.com>, Frost Ming <me@frostming.com>, William Woodruff <william@yossarian.net>
|
|
7
|
-
Requires-Python: >=3.9
|
|
8
|
-
Description-Content-Type: text/x-rst
|
|
9
8
|
License-Expression: Apache-2.0
|
|
9
|
+
License-File: LICENSE.txt
|
|
10
10
|
Classifier: Development Status :: 4 - Beta
|
|
11
11
|
Classifier: Environment :: Web Environment
|
|
12
12
|
Classifier: Operating System :: OS Independent
|
|
13
|
-
Classifier: Programming Language :: Python :: 3.9
|
|
14
13
|
Classifier: Programming Language :: Python :: 3.10
|
|
15
14
|
Classifier: Programming Language :: Python :: 3.11
|
|
16
15
|
Classifier: Programming Language :: Python :: 3.12
|
|
17
16
|
Classifier: Programming Language :: Python :: 3.13
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
18
18
|
Classifier: Topic :: Internet :: WWW/HTTP
|
|
19
|
-
|
|
20
|
-
Requires-Dist:
|
|
21
|
-
Requires-Dist:
|
|
22
|
-
Requires-Dist:
|
|
23
|
-
Requires-Dist:
|
|
24
|
-
Requires-Dist:
|
|
25
|
-
Requires-Dist:
|
|
26
|
-
Requires-Dist:
|
|
27
|
-
Requires-Dist:
|
|
28
|
-
Requires-Dist: pytest ; extra ==
|
|
29
|
-
Requires-Dist:
|
|
30
|
-
Requires-Dist:
|
|
31
|
-
Requires-Dist: sphinx ; extra ==
|
|
32
|
-
Requires-Dist:
|
|
33
|
-
Requires-Dist:
|
|
34
|
-
Requires-Dist:
|
|
35
|
-
Requires-Dist:
|
|
36
|
-
Requires-
|
|
37
|
-
Requires-Dist: redis>=2.10.5 ; extra == "redis"
|
|
19
|
+
Requires-Dist: requests>=2.16.0
|
|
20
|
+
Requires-Dist: msgpack>=0.5.2,<2.0.0
|
|
21
|
+
Requires-Dist: cachecontrol[filecache,redis] ; extra == 'dev'
|
|
22
|
+
Requires-Dist: cherrypy ; extra == 'dev'
|
|
23
|
+
Requires-Dist: cheroot>=11.1.2 ; extra == 'dev'
|
|
24
|
+
Requires-Dist: codespell ; extra == 'dev'
|
|
25
|
+
Requires-Dist: furo ; extra == 'dev'
|
|
26
|
+
Requires-Dist: mypy ; extra == 'dev'
|
|
27
|
+
Requires-Dist: pytest ; extra == 'dev'
|
|
28
|
+
Requires-Dist: pytest-cov ; extra == 'dev'
|
|
29
|
+
Requires-Dist: ruff ; extra == 'dev'
|
|
30
|
+
Requires-Dist: sphinx ; extra == 'dev'
|
|
31
|
+
Requires-Dist: sphinx-copybutton ; extra == 'dev'
|
|
32
|
+
Requires-Dist: types-redis ; extra == 'dev'
|
|
33
|
+
Requires-Dist: types-requests ; extra == 'dev'
|
|
34
|
+
Requires-Dist: filelock>=3.8.0 ; extra == 'filecache'
|
|
35
|
+
Requires-Dist: redis>=2.10.5 ; extra == 'redis'
|
|
36
|
+
Requires-Python: >=3.10
|
|
38
37
|
Project-URL: Homepage, https://pypi.org/project/CacheControl/
|
|
39
38
|
Project-URL: Issues, https://github.com/psf/cachecontrol/issues
|
|
40
39
|
Project-URL: Source, https://github.com/psf/cachecontrol
|
|
41
40
|
Provides-Extra: dev
|
|
42
41
|
Provides-Extra: filecache
|
|
43
42
|
Provides-Extra: redis
|
|
43
|
+
Description-Content-Type: text/x-rst
|
|
44
44
|
|
|
45
45
|
..
|
|
46
46
|
SPDX-FileCopyrightText: SPDX-FileCopyrightText: 2015 Eric Larson
|
|
@@ -89,4 +89,3 @@ For more info, check out the docs_
|
|
|
89
89
|
.. _docs: http://cachecontrol.readthedocs.org/en/latest/
|
|
90
90
|
.. _httplib2: https://github.com/httplib2/httplib2
|
|
91
91
|
.. _requests: http://docs.python-requests.org/
|
|
92
|
-
|
|
@@ -7,14 +7,16 @@
|
|
|
7
7
|
Make it easy to import from cachecontrol without long namespaces.
|
|
8
8
|
"""
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
__email__ = "eric@ionrock.org"
|
|
12
|
-
__version__ = "0.14.3"
|
|
10
|
+
import importlib.metadata
|
|
13
11
|
|
|
14
12
|
from cachecontrol.adapter import CacheControlAdapter
|
|
15
13
|
from cachecontrol.controller import CacheController
|
|
16
14
|
from cachecontrol.wrapper import CacheControl
|
|
17
15
|
|
|
16
|
+
__author__ = "Eric Larson"
|
|
17
|
+
__email__ = "eric@ionrock.org"
|
|
18
|
+
__version__ = importlib.metadata.version("cachecontrol")
|
|
19
|
+
|
|
18
20
|
__all__ = [
|
|
19
21
|
"__author__",
|
|
20
22
|
"__email__",
|
|
@@ -490,7 +490,7 @@ class CacheController:
|
|
|
490
490
|
#
|
|
491
491
|
# The server isn't supposed to send headers that would make
|
|
492
492
|
# the cached body invalid. But... just in case, we'll be sure
|
|
493
|
-
# to strip out ones we know that might be
|
|
493
|
+
# to strip out ones we know that might be problematic due to
|
|
494
494
|
# typical assumptions.
|
|
495
495
|
excluded_headers = ["content-length"]
|
|
496
496
|
|
|
@@ -8,6 +8,7 @@ from tempfile import NamedTemporaryFile
|
|
|
8
8
|
from typing import TYPE_CHECKING, Any, Callable
|
|
9
9
|
|
|
10
10
|
if TYPE_CHECKING:
|
|
11
|
+
from collections.abc import Buffer
|
|
11
12
|
from http.client import HTTPResponse
|
|
12
13
|
|
|
13
14
|
|
|
@@ -31,7 +32,7 @@ class CallbackFileWrapper:
|
|
|
31
32
|
"""
|
|
32
33
|
|
|
33
34
|
def __init__(
|
|
34
|
-
self, fp: HTTPResponse, callback: Callable[[
|
|
35
|
+
self, fp: HTTPResponse, callback: Callable[[Buffer], None] | None
|
|
35
36
|
) -> None:
|
|
36
37
|
self.__buf = NamedTemporaryFile("rb+", delete=True)
|
|
37
38
|
self.__fp = fp
|
|
@@ -68,6 +69,7 @@ class CallbackFileWrapper:
|
|
|
68
69
|
return False
|
|
69
70
|
|
|
70
71
|
def _close(self) -> None:
|
|
72
|
+
result: Buffer
|
|
71
73
|
if self.__callback:
|
|
72
74
|
if self.__buf.tell() == 0:
|
|
73
75
|
# Empty file:
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
[build-system]
|
|
2
|
-
requires = ["
|
|
3
|
-
build-backend = "
|
|
2
|
+
requires = ["uv_build>=0.9.6,<0.10.0"]
|
|
3
|
+
build-backend = "uv_build"
|
|
4
4
|
|
|
5
|
-
[tool.
|
|
6
|
-
|
|
5
|
+
[tool.uv.build-backend]
|
|
6
|
+
source-include = ["tests/"]
|
|
7
|
+
module-name = "cachecontrol"
|
|
8
|
+
module-root = ""
|
|
7
9
|
|
|
8
|
-
[tool.flit.sdist]
|
|
9
|
-
include = ["tests/"]
|
|
10
10
|
|
|
11
11
|
[project]
|
|
12
12
|
name = "CacheControl"
|
|
13
|
-
|
|
13
|
+
version = "0.14.4"
|
|
14
14
|
description = "httplib2 caching for requests"
|
|
15
15
|
readme = "README.rst"
|
|
16
16
|
license = "Apache-2.0"
|
|
@@ -24,16 +24,16 @@ classifiers = [
|
|
|
24
24
|
"Development Status :: 4 - Beta",
|
|
25
25
|
"Environment :: Web Environment",
|
|
26
26
|
"Operating System :: OS Independent",
|
|
27
|
-
"Programming Language :: Python :: 3.9",
|
|
28
27
|
"Programming Language :: Python :: 3.10",
|
|
29
28
|
"Programming Language :: Python :: 3.11",
|
|
30
29
|
"Programming Language :: Python :: 3.12",
|
|
31
30
|
"Programming Language :: Python :: 3.13",
|
|
31
|
+
"Programming Language :: Python :: 3.14",
|
|
32
32
|
"Topic :: Internet :: WWW/HTTP",
|
|
33
33
|
]
|
|
34
34
|
keywords = ["requests", "http", "caching", "web"]
|
|
35
35
|
dependencies = ["requests >= 2.16.0", "msgpack >= 0.5.2, < 2.0.0"]
|
|
36
|
-
requires-python = ">=3.
|
|
36
|
+
requires-python = ">=3.10"
|
|
37
37
|
|
|
38
38
|
[project.urls]
|
|
39
39
|
Homepage = "https://pypi.org/project/CacheControl/"
|
|
@@ -48,9 +48,11 @@ redis = ["redis>=2.10.5"]
|
|
|
48
48
|
# Development extras.
|
|
49
49
|
dev = [
|
|
50
50
|
"CacheControl[filecache,redis]",
|
|
51
|
-
"build",
|
|
52
51
|
"cherrypy",
|
|
53
|
-
|
|
52
|
+
# See: https://github.com/cherrypy/cherrypy/issues/2070
|
|
53
|
+
# See: https://github.com/cherrypy/cheroot/issues/769
|
|
54
|
+
"cheroot >= 11.1.2",
|
|
55
|
+
"codespell",
|
|
54
56
|
"furo",
|
|
55
57
|
"mypy",
|
|
56
58
|
"pytest",
|
|
@@ -58,7 +60,6 @@ dev = [
|
|
|
58
60
|
"ruff",
|
|
59
61
|
"sphinx",
|
|
60
62
|
"sphinx-copybutton",
|
|
61
|
-
"tox",
|
|
62
63
|
"types-redis",
|
|
63
64
|
"types-requests",
|
|
64
65
|
]
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"""Tests for CacheControl."""
|
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
# SPDX-FileCopyrightText: 2015 Eric Larson
|
|
2
|
-
#
|
|
3
|
-
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
-
|
|
5
|
-
from pprint import pformat
|
|
6
|
-
|
|
7
|
-
import os
|
|
8
|
-
import socket
|
|
9
|
-
|
|
10
|
-
import pytest
|
|
11
|
-
|
|
12
|
-
import cherrypy
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
class SimpleApp:
|
|
16
|
-
def __init__(self):
|
|
17
|
-
self.etag_count = 0
|
|
18
|
-
self.update_etag_string()
|
|
19
|
-
|
|
20
|
-
def dispatch(self, env):
|
|
21
|
-
path = env["PATH_INFO"][1:].split("/")
|
|
22
|
-
segment = path.pop(0)
|
|
23
|
-
if segment and hasattr(self, segment):
|
|
24
|
-
return getattr(self, segment)
|
|
25
|
-
|
|
26
|
-
return None
|
|
27
|
-
|
|
28
|
-
def optional_cacheable_request(self, env, start_response):
|
|
29
|
-
"""A request with no hints as to whether it should be
|
|
30
|
-
cached. Yet, we might still choose to cache it via a
|
|
31
|
-
heuristic."""
|
|
32
|
-
|
|
33
|
-
headers = [
|
|
34
|
-
("server", "nginx/1.2.6 (Ubuntu)"),
|
|
35
|
-
("last-modified", "Mon, 21 Jul 2014 17:45:39 GMT"),
|
|
36
|
-
("content-type", "text/html"),
|
|
37
|
-
]
|
|
38
|
-
|
|
39
|
-
start_response("200 OK", headers)
|
|
40
|
-
return [pformat(env).encode("utf8")]
|
|
41
|
-
|
|
42
|
-
def vary_accept(self, env, start_response):
|
|
43
|
-
response = pformat(env).encode("utf8")
|
|
44
|
-
|
|
45
|
-
headers = [
|
|
46
|
-
("Cache-Control", "max-age=5000"),
|
|
47
|
-
("Content-Type", "text/plain"),
|
|
48
|
-
("Vary", "Accept-Encoding, Accept"),
|
|
49
|
-
]
|
|
50
|
-
start_response("200 OK", headers)
|
|
51
|
-
return [response]
|
|
52
|
-
|
|
53
|
-
def update_etag_string(self):
|
|
54
|
-
self.etag_count += 1
|
|
55
|
-
self.etag_string = f'"ETAG-{self.etag_count}"'
|
|
56
|
-
|
|
57
|
-
def update_etag(self, env, start_response):
|
|
58
|
-
self.update_etag_string()
|
|
59
|
-
headers = [("Cache-Control", "max-age=5000"), ("Content-Type", "text/plain")]
|
|
60
|
-
start_response("200 OK", headers)
|
|
61
|
-
return [pformat(env).encode("utf8")]
|
|
62
|
-
|
|
63
|
-
def conditional_get(self, env, start_response):
|
|
64
|
-
return start_response("304 Not Modified", [])
|
|
65
|
-
|
|
66
|
-
def etag(self, env, start_response):
|
|
67
|
-
headers = [("Etag", self.etag_string)]
|
|
68
|
-
if env.get("HTTP_IF_NONE_MATCH") == self.etag_string:
|
|
69
|
-
start_response("304 Not Modified", headers)
|
|
70
|
-
return []
|
|
71
|
-
else:
|
|
72
|
-
start_response("200 OK", headers)
|
|
73
|
-
return [pformat(env).encode("utf8")]
|
|
74
|
-
|
|
75
|
-
def cache_60(self, env, start_response):
|
|
76
|
-
headers = [("Cache-Control", "public, max-age=60")]
|
|
77
|
-
start_response("200 OK", headers)
|
|
78
|
-
return [pformat(env).encode("utf8")]
|
|
79
|
-
|
|
80
|
-
def no_cache(self, env, start_response):
|
|
81
|
-
headers = [("Cache-Control", "no-cache")]
|
|
82
|
-
start_response("200 OK", headers)
|
|
83
|
-
return [pformat(env).encode("utf8")]
|
|
84
|
-
|
|
85
|
-
def permanent_redirect(self, env, start_response):
|
|
86
|
-
headers = [("Location", "/permalink")]
|
|
87
|
-
start_response("301 Moved Permanently", headers)
|
|
88
|
-
return [b"See: /permalink"]
|
|
89
|
-
|
|
90
|
-
def permalink(self, env, start_response):
|
|
91
|
-
start_response("200 OK", [("Content-Type", "text/plain")])
|
|
92
|
-
return [b"The permanent resource"]
|
|
93
|
-
|
|
94
|
-
def multiple_choices(self, env, start_response):
|
|
95
|
-
headers = [("Link", "/permalink")]
|
|
96
|
-
start_response("300 Multiple Choices", headers)
|
|
97
|
-
return [b"See: /permalink"]
|
|
98
|
-
|
|
99
|
-
def stream(self, env, start_response):
|
|
100
|
-
headers = [("Content-Type", "text/plain"), ("Cache-Control", "max-age=5000")]
|
|
101
|
-
start_response("200 OK", headers)
|
|
102
|
-
|
|
103
|
-
for i in range(10):
|
|
104
|
-
yield pformat(i).encode("utf8")
|
|
105
|
-
|
|
106
|
-
def fixed_length(self, env, start_response):
|
|
107
|
-
body = b"0123456789"
|
|
108
|
-
headers = [
|
|
109
|
-
("Content-Type", "text/plain"),
|
|
110
|
-
("Cache-Control", "max-age=5000"),
|
|
111
|
-
("Content-Length", str(len(body))),
|
|
112
|
-
]
|
|
113
|
-
start_response("200 OK", headers)
|
|
114
|
-
return [body]
|
|
115
|
-
|
|
116
|
-
def __call__(self, env, start_response):
|
|
117
|
-
func = self.dispatch(env)
|
|
118
|
-
|
|
119
|
-
if func:
|
|
120
|
-
return func(env, start_response)
|
|
121
|
-
|
|
122
|
-
headers = [("Cache-Control", "max-age=5000"), ("Content-Type", "text/plain")]
|
|
123
|
-
start_response("200 OK", headers)
|
|
124
|
-
return [pformat(env).encode("utf8")]
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
@pytest.fixture(scope="session")
|
|
128
|
-
def server():
|
|
129
|
-
return cherrypy.server
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
@pytest.fixture()
|
|
133
|
-
def url(server):
|
|
134
|
-
return "http://%s:%s/" % server.bind_addr
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
def get_free_port():
|
|
138
|
-
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
139
|
-
s.bind(("", 0))
|
|
140
|
-
ip, port = s.getsockname()
|
|
141
|
-
s.close()
|
|
142
|
-
ip = os.environ.get("WEBTEST_SERVER_BIND", "127.0.0.1")
|
|
143
|
-
return ip, port
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
def pytest_configure(config):
|
|
147
|
-
cherrypy.tree.graft(SimpleApp(), "/")
|
|
148
|
-
|
|
149
|
-
ip, port = get_free_port()
|
|
150
|
-
|
|
151
|
-
cherrypy.config.update({"server.socket_host": ip, "server.socket_port": port})
|
|
152
|
-
|
|
153
|
-
# turn off logging
|
|
154
|
-
logger = cherrypy.log.access_log
|
|
155
|
-
logger.removeHandler(logger.handlers[0])
|
|
156
|
-
|
|
157
|
-
cherrypy.server.start()
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
def pytest_unconfigure(config):
|
|
161
|
-
try:
|
|
162
|
-
cherrypy.server.stop()
|
|
163
|
-
except: # noqa: E722
|
|
164
|
-
pass
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
import sys
|
|
3
|
-
|
|
4
|
-
import cachecontrol
|
|
5
|
-
import requests
|
|
6
|
-
from cachecontrol.cache import DictCache
|
|
7
|
-
from cachecontrol.heuristics import BaseHeuristic
|
|
8
|
-
|
|
9
|
-
import logging
|
|
10
|
-
|
|
11
|
-
clogger = logging.getLogger("cachecontrol")
|
|
12
|
-
clogger.addHandler(logging.StreamHandler())
|
|
13
|
-
clogger.setLevel(logging.DEBUG)
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
class NoAgeHeuristic(BaseHeuristic):
|
|
17
|
-
def update_headers(self, response):
|
|
18
|
-
if "cache-control" in response.headers:
|
|
19
|
-
del response.headers["cache-control"]
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
cache_adapter = cachecontrol.CacheControlAdapter(
|
|
23
|
-
DictCache(), cache_etags=True, heuristic=NoAgeHeuristic()
|
|
24
|
-
)
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
session = requests.Session()
|
|
28
|
-
session.mount("https://", cache_adapter)
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
def log_resp(resp):
|
|
32
|
-
return
|
|
33
|
-
|
|
34
|
-
print(f"{resp.status_code} {resp.request.method}")
|
|
35
|
-
for k, v in response.headers.items():
|
|
36
|
-
print(f"{k}: {v}")
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
for i in range(2):
|
|
40
|
-
response = session.get(
|
|
41
|
-
"https://api.github.com/repos/sigmavirus24/github3.py/pulls/1033"
|
|
42
|
-
)
|
|
43
|
-
log_resp(response)
|
|
44
|
-
print(f"Content length: {len(response.content)}")
|
|
45
|
-
print(response.from_cache)
|
|
46
|
-
if len(response.content) == 0:
|
|
47
|
-
sys.exit(1)
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
# SPDX-FileCopyrightText: 2015 Eric Larson
|
|
2
|
-
#
|
|
3
|
-
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
-
|
|
5
|
-
import gc
|
|
6
|
-
import platform
|
|
7
|
-
import weakref
|
|
8
|
-
from unittest import mock
|
|
9
|
-
|
|
10
|
-
import pytest
|
|
11
|
-
from requests import Session
|
|
12
|
-
|
|
13
|
-
from cachecontrol.adapter import CacheControlAdapter
|
|
14
|
-
from cachecontrol.cache import DictCache
|
|
15
|
-
from cachecontrol.wrapper import CacheControl
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
def use_wrapper():
|
|
19
|
-
print("Using helper")
|
|
20
|
-
sess = CacheControl(Session())
|
|
21
|
-
return sess
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
def use_adapter():
|
|
25
|
-
print("Using adapter")
|
|
26
|
-
sess = Session()
|
|
27
|
-
sess.mount("http://", CacheControlAdapter())
|
|
28
|
-
return sess
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
@pytest.fixture(params=[use_adapter, use_wrapper])
|
|
32
|
-
def sess(url, request):
|
|
33
|
-
sess = request.param()
|
|
34
|
-
sess.get(url)
|
|
35
|
-
yield sess
|
|
36
|
-
|
|
37
|
-
# closing session object
|
|
38
|
-
sess.close()
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
class TestSessionActions:
|
|
42
|
-
def test_get_caches(self, url, sess):
|
|
43
|
-
r2 = sess.get(url)
|
|
44
|
-
assert r2.from_cache is True
|
|
45
|
-
|
|
46
|
-
def test_get_with_no_cache_does_not_cache(self, url, sess):
|
|
47
|
-
r2 = sess.get(url, headers={"Cache-Control": "no-cache"})
|
|
48
|
-
assert not r2.from_cache
|
|
49
|
-
|
|
50
|
-
def test_put_invalidates_cache(self, url, sess):
|
|
51
|
-
r2 = sess.put(url, data={"foo": "bar"})
|
|
52
|
-
sess.get(url)
|
|
53
|
-
assert not r2.from_cache
|
|
54
|
-
|
|
55
|
-
def test_patch_invalidates_cache(self, url, sess):
|
|
56
|
-
r2 = sess.patch(url, data={"foo": "bar"})
|
|
57
|
-
sess.get(url)
|
|
58
|
-
assert not r2.from_cache
|
|
59
|
-
|
|
60
|
-
def test_delete_invalidates_cache(self, url, sess):
|
|
61
|
-
r2 = sess.delete(url)
|
|
62
|
-
sess.get(url)
|
|
63
|
-
assert not r2.from_cache
|
|
64
|
-
|
|
65
|
-
def test_close(self):
|
|
66
|
-
cache = mock.Mock(spec=DictCache)
|
|
67
|
-
sess = Session()
|
|
68
|
-
sess.mount("http://", CacheControlAdapter(cache))
|
|
69
|
-
|
|
70
|
-
sess.close()
|
|
71
|
-
assert cache.close.called
|
|
72
|
-
|
|
73
|
-
def test_do_not_leak_response(self, url, sess):
|
|
74
|
-
resp = sess.get(url + "stream", stream=True)
|
|
75
|
-
resp.raise_for_status()
|
|
76
|
-
r1_weak = weakref.ref(resp.raw)
|
|
77
|
-
|
|
78
|
-
# This is a mis-use of requests, becase we should either consume
|
|
79
|
-
# the body, or call .close().
|
|
80
|
-
# But requests without cachecontrol handle this anyway, because
|
|
81
|
-
# urllib3.response.HTTPResponse has a __del__ finalizer on it that closes it
|
|
82
|
-
# once there are no more references to it.
|
|
83
|
-
# We should not break this.
|
|
84
|
-
|
|
85
|
-
resp = None
|
|
86
|
-
if platform.python_implementation() == "PyPy":
|
|
87
|
-
# NOTE: Need to explicitly tell PyPy to collect at this point.
|
|
88
|
-
# See: https://github.com/psf/cachecontrol/issues/351
|
|
89
|
-
# See: https://doc.pypy.org/en/latest/cpython_differences.html#differences-related-to-garbage-collection-strategies
|
|
90
|
-
gc.collect()
|
|
91
|
-
|
|
92
|
-
# Below this point, it should be closed because there are no more references
|
|
93
|
-
# to the session response.
|
|
94
|
-
|
|
95
|
-
r1 = r1_weak()
|
|
96
|
-
assert r1 is None or r1.closed
|