CacheControl 0.12.12__py2.py3-none-any.whl → 0.12.14__py2.py3-none-any.whl
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.12.12.dist-info → CacheControl-0.12.14.dist-info}/METADATA +2 -6
- CacheControl-0.12.14.dist-info/RECORD +19 -0
- {CacheControl-0.12.12.dist-info → CacheControl-0.12.14.dist-info}/WHEEL +1 -1
- {CacheControl-0.12.12.dist-info → CacheControl-0.12.14.dist-info}/entry_points.txt +0 -1
- {CacheControl-0.12.12.dist-info → CacheControl-0.12.14.dist-info}/top_level.txt +0 -1
- cachecontrol/__init__.py +1 -1
- cachecontrol/caches/file_cache.py +17 -7
- cachecontrol/serialize.py +4 -1
- CacheControl-0.12.12.dist-info/RECORD +0 -36
- tests/__init__.py +0 -1
- tests/conftest.py +0 -155
- tests/issue_263.py +0 -50
- tests/test_adapter.py +0 -68
- tests/test_cache_control.py +0 -294
- tests/test_chunked_response.py +0 -58
- tests/test_etag.py +0 -144
- tests/test_expires_heuristics.py +0 -209
- tests/test_max_age.py +0 -59
- tests/test_redirects.py +0 -56
- tests/test_regressions.py +0 -38
- tests/test_serialization.py +0 -137
- tests/test_server_http_version.py +0 -12
- tests/test_storage_filecache.py +0 -173
- tests/test_storage_redis.py +0 -23
- tests/test_vary.py +0 -86
- tests/utils.py +0 -36
- {CacheControl-0.12.12.dist-info → CacheControl-0.12.14.dist-info}/LICENSE.txt +0 -0
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: CacheControl
|
|
3
|
-
Version: 0.12.
|
|
3
|
+
Version: 0.12.14
|
|
4
4
|
Summary: httplib2 caching for requests
|
|
5
5
|
Home-page: https://github.com/ionrock/cachecontrol
|
|
6
6
|
Author: Eric Larson
|
|
7
7
|
Author-email: eric@ionrock.org
|
|
8
|
-
License: UNKNOWN
|
|
9
8
|
Keywords: requests http caching web
|
|
10
|
-
Platform: UNKNOWN
|
|
11
9
|
Classifier: Development Status :: 4 - Beta
|
|
12
10
|
Classifier: Environment :: Web Environment
|
|
13
11
|
Classifier: License :: OSI Approved :: Apache Software License
|
|
@@ -23,7 +21,7 @@ License-File: LICENSE.txt
|
|
|
23
21
|
Requires-Dist: requests
|
|
24
22
|
Requires-Dist: msgpack (>=0.5.2)
|
|
25
23
|
Provides-Extra: filecache
|
|
26
|
-
Requires-Dist:
|
|
24
|
+
Requires-Dist: lockfile (>=0.9) ; extra == 'filecache'
|
|
27
25
|
Provides-Extra: redis
|
|
28
26
|
Requires-Dist: redis (>=2.10.5) ; extra == 'redis'
|
|
29
27
|
|
|
@@ -74,5 +72,3 @@ For more info, check out the docs_
|
|
|
74
72
|
.. _docs: http://cachecontrol.readthedocs.org/en/latest/
|
|
75
73
|
.. _httplib2: https://github.com/httplib2/httplib2
|
|
76
74
|
.. _requests: http://docs.python-requests.org/
|
|
77
|
-
|
|
78
|
-
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
cachecontrol/__init__.py,sha256=Ay1JZbjaWZfkKNVpxrIpBmisYdP-mw-UnuUq6W39XlA,465
|
|
2
|
+
cachecontrol/_cmd.py,sha256=HjFJdGgPOLsvS_5e8BvqYrweXJj1gR7dSsqCB1X24uw,1326
|
|
3
|
+
cachecontrol/adapter.py,sha256=du8CsHKttAWL9-pWmSvyNDVzHrH-qfiSOgo6fcanM-0,5021
|
|
4
|
+
cachecontrol/cache.py,sha256=Tty45fOjH40fColTGkqKQvQQmbYsMpk-nCyfLcv2vG4,1535
|
|
5
|
+
cachecontrol/compat.py,sha256=JOVKyIibp8nNq3jAbv7nXBsNOtXHVEKPh5u8r2qLGVo,730
|
|
6
|
+
cachecontrol/controller.py,sha256=rc1HPSBPSC-dpr5_p7IAq1U-mI0AZx9WGb9_d51WkNE,16684
|
|
7
|
+
cachecontrol/filewrapper.py,sha256=X4BAQOO26GNOR7nH_fhTzAfeuct2rBQcx_15MyFBpcs,3946
|
|
8
|
+
cachecontrol/heuristics.py,sha256=8kAyuZLSCyEIgQr6vbUwfhpqg9ows4mM0IV6DWazevI,4154
|
|
9
|
+
cachecontrol/serialize.py,sha256=2alQaLbA33qLRW8PQSJzQ3uDik1vVMf8gfnoIzw8eB8,7216
|
|
10
|
+
cachecontrol/wrapper.py,sha256=X3-KMZ20Ho3VtqyVaXclpeQpFzokR5NE8tZSfvKVaB8,774
|
|
11
|
+
cachecontrol/caches/__init__.py,sha256=h-1cUmOz6mhLsjTjOrJ8iPejpGdLCyG4lzTftfGZvLg,242
|
|
12
|
+
cachecontrol/caches/file_cache.py,sha256=GpexcE29LoY4MaZwPUTcUBZaDdcsjqyLxZFznk8Hbr4,5271
|
|
13
|
+
cachecontrol/caches/redis_cache.py,sha256=bGKAU0IOcJUFmU_blBI3w6zKj1L4IyfDPmLNyzjp_y4,1021
|
|
14
|
+
CacheControl-0.12.14.dist-info/LICENSE.txt,sha256=hu7uh74qQ_P_H1ZJb0UfaSQ5JvAl_tuwM2ZsMExMFhs,558
|
|
15
|
+
CacheControl-0.12.14.dist-info/METADATA,sha256=Zx4oWUReiKdwP2bjB200yn_DIdkYF7utCxHYyD-Laec,2181
|
|
16
|
+
CacheControl-0.12.14.dist-info/WHEEL,sha256=a-zpFRIJzOq5QfuhBzbhiA1eHTzNCJn8OdRvhdNX0Rk,110
|
|
17
|
+
CacheControl-0.12.14.dist-info/entry_points.txt,sha256=SyncUQvsSkNqcQOu8uE2_D8K5d7_2fR2cV7tSJaMrhc,55
|
|
18
|
+
CacheControl-0.12.14.dist-info/top_level.txt,sha256=vGYWzpbe3h6gkakV4f7iCK2x3KyK3oMkV5pe5v25-d4,13
|
|
19
|
+
CacheControl-0.12.14.dist-info/RECORD,,
|
cachecontrol/__init__.py
CHANGED
|
@@ -8,7 +8,7 @@ Make it easy to import from cachecontrol without long namespaces.
|
|
|
8
8
|
"""
|
|
9
9
|
__author__ = "Eric Larson"
|
|
10
10
|
__email__ = "eric@ionrock.org"
|
|
11
|
-
__version__ = "0.12.
|
|
11
|
+
__version__ = "0.12.14"
|
|
12
12
|
|
|
13
13
|
from .wrapper import CacheControl
|
|
14
14
|
from .adapter import CacheControlAdapter
|
|
@@ -66,23 +66,33 @@ class _FileCacheMixin:
|
|
|
66
66
|
forever=False,
|
|
67
67
|
filemode=0o0600,
|
|
68
68
|
dirmode=0o0700,
|
|
69
|
+
use_dir_lock=None,
|
|
69
70
|
lock_class=None,
|
|
70
71
|
):
|
|
71
72
|
|
|
73
|
+
if use_dir_lock is not None and lock_class is not None:
|
|
74
|
+
raise ValueError("Cannot use use_dir_lock and lock_class together")
|
|
75
|
+
|
|
72
76
|
try:
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
lock_class = FileLock
|
|
77
|
+
from lockfile import LockFile
|
|
78
|
+
from lockfile.mkdirlockfile import MkdirLockFile
|
|
76
79
|
except ImportError:
|
|
77
80
|
notice = dedent(
|
|
78
81
|
"""
|
|
79
82
|
NOTE: In order to use the FileCache you must have
|
|
80
|
-
|
|
81
|
-
pip install
|
|
83
|
+
lockfile installed. You can install it via pip:
|
|
84
|
+
pip install lockfile
|
|
82
85
|
"""
|
|
83
86
|
)
|
|
84
87
|
raise ImportError(notice)
|
|
85
88
|
|
|
89
|
+
else:
|
|
90
|
+
if use_dir_lock:
|
|
91
|
+
lock_class = MkdirLockFile
|
|
92
|
+
|
|
93
|
+
elif lock_class is None:
|
|
94
|
+
lock_class = LockFile
|
|
95
|
+
|
|
86
96
|
self.directory = directory
|
|
87
97
|
self.forever = forever
|
|
88
98
|
self.filemode = filemode
|
|
@@ -123,9 +133,9 @@ class _FileCacheMixin:
|
|
|
123
133
|
except (IOError, OSError):
|
|
124
134
|
pass
|
|
125
135
|
|
|
126
|
-
with self.lock_class(path
|
|
136
|
+
with self.lock_class(path) as lock:
|
|
127
137
|
# Write our actual file
|
|
128
|
-
with _secure_open_write(path, self.filemode) as fh:
|
|
138
|
+
with _secure_open_write(lock.path, self.filemode) as fh:
|
|
129
139
|
fh.write(data)
|
|
130
140
|
|
|
131
141
|
def _delete(self, key, suffix):
|
cachecontrol/serialize.py
CHANGED
|
@@ -34,6 +34,7 @@ class Serializer(object):
|
|
|
34
34
|
# sure it acts as though it was never read.
|
|
35
35
|
body = response.read(decode_content=False)
|
|
36
36
|
response._fp = io.BytesIO(body)
|
|
37
|
+
response.length_remaining = len(body)
|
|
37
38
|
|
|
38
39
|
# NOTE: This is all a bit weird, but it's really important that on
|
|
39
40
|
# Python 2.x these objects are unicode and not str, even when
|
|
@@ -51,7 +52,6 @@ class Serializer(object):
|
|
|
51
52
|
u"status": response.status,
|
|
52
53
|
u"version": response.version,
|
|
53
54
|
u"reason": text_type(response.reason),
|
|
54
|
-
u"strict": response.strict,
|
|
55
55
|
u"decode_content": response.decode_content,
|
|
56
56
|
}
|
|
57
57
|
}
|
|
@@ -138,6 +138,9 @@ class Serializer(object):
|
|
|
138
138
|
# TypeError: 'str' does not support the buffer interface
|
|
139
139
|
body = io.BytesIO(body_raw.encode("utf8"))
|
|
140
140
|
|
|
141
|
+
# Discard any `strict` parameter serialized by older version of cachecontrol.
|
|
142
|
+
cached["response"].pop("strict", None)
|
|
143
|
+
|
|
141
144
|
return HTTPResponse(body=body, preload_content=False, **cached["response"])
|
|
142
145
|
|
|
143
146
|
def _loads_v0(self, request, data, body_file=None):
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
cachecontrol/__init__.py,sha256=dpjHEk73pF5f_lVBVdokZifDWxQHaPg_LISg-YyLuu8,465
|
|
2
|
-
cachecontrol/_cmd.py,sha256=HjFJdGgPOLsvS_5e8BvqYrweXJj1gR7dSsqCB1X24uw,1326
|
|
3
|
-
cachecontrol/adapter.py,sha256=du8CsHKttAWL9-pWmSvyNDVzHrH-qfiSOgo6fcanM-0,5021
|
|
4
|
-
cachecontrol/cache.py,sha256=Tty45fOjH40fColTGkqKQvQQmbYsMpk-nCyfLcv2vG4,1535
|
|
5
|
-
cachecontrol/compat.py,sha256=JOVKyIibp8nNq3jAbv7nXBsNOtXHVEKPh5u8r2qLGVo,730
|
|
6
|
-
cachecontrol/controller.py,sha256=rc1HPSBPSC-dpr5_p7IAq1U-mI0AZx9WGb9_d51WkNE,16684
|
|
7
|
-
cachecontrol/filewrapper.py,sha256=X4BAQOO26GNOR7nH_fhTzAfeuct2rBQcx_15MyFBpcs,3946
|
|
8
|
-
cachecontrol/heuristics.py,sha256=8kAyuZLSCyEIgQr6vbUwfhpqg9ows4mM0IV6DWazevI,4154
|
|
9
|
-
cachecontrol/serialize.py,sha256=qbMVbnUSDuQRlJWTn6-CKrXYShaUn9dSigtvtAaI3xA,7076
|
|
10
|
-
cachecontrol/wrapper.py,sha256=X3-KMZ20Ho3VtqyVaXclpeQpFzokR5NE8tZSfvKVaB8,774
|
|
11
|
-
cachecontrol/caches/__init__.py,sha256=h-1cUmOz6mhLsjTjOrJ8iPejpGdLCyG4lzTftfGZvLg,242
|
|
12
|
-
cachecontrol/caches/file_cache.py,sha256=sEykjs7hBwD0ssLcZtCSDxzQbkhJa1a-EEMu8MF5FWc,4949
|
|
13
|
-
cachecontrol/caches/redis_cache.py,sha256=bGKAU0IOcJUFmU_blBI3w6zKj1L4IyfDPmLNyzjp_y4,1021
|
|
14
|
-
tests/__init__.py,sha256=BIgHwMHSWhBDFdsqMNUzS_5TP_2_ZO4DEcae0VpWuww,30
|
|
15
|
-
tests/conftest.py,sha256=uqCYjSvkdzHeZM1Rt9ky8ndVDYVj6a_zr2n1UTDqIcw,4475
|
|
16
|
-
tests/issue_263.py,sha256=skAzSka7zbMkR3oHnXbU4DojdrgeDChtiQPieG59LyY,1142
|
|
17
|
-
tests/test_adapter.py,sha256=JvXc6I2j86N050FlHHQbvE284B8it2mZXuu3oxn6xL8,1671
|
|
18
|
-
tests/test_cache_control.py,sha256=v3V-4WSCqu-zovSUQiBwbDi5uVC-DqmVXyYtEW7F9N8,10682
|
|
19
|
-
tests/test_chunked_response.py,sha256=Bt7n_ni3YWAM0muApTDH3F9cupqV110haTbetOIKwBI,1522
|
|
20
|
-
tests/test_etag.py,sha256=Eo_-Ri4-u7dvoan9Iv3bo_5geWjsGJLM1PgTb7UqIOY,5154
|
|
21
|
-
tests/test_expires_heuristics.py,sha256=RvZwLQJJwueyMxUWZL-tdSapkFOR7ejzHklHJcxDyyw,6606
|
|
22
|
-
tests/test_max_age.py,sha256=a-2sykRkViT0lMO_77SKTy42OUA066_fbXLa3NvXx2A,1805
|
|
23
|
-
tests/test_redirects.py,sha256=ovoST2jUBTRZRvRWNwoNXyQ7MqC8VkKLsh4DDYmednw,1588
|
|
24
|
-
tests/test_regressions.py,sha256=visYG6XM9YnL3C09lnW74PTNBu2PLHKIsuAfFC9JKRM,959
|
|
25
|
-
tests/test_serialization.py,sha256=MDTe7U7VC8lqvOGYbu2C8fqmJDST136hTIgYYz0xVEs,5416
|
|
26
|
-
tests/test_server_http_version.py,sha256=NwdTt2uQI489Jy6lW1BmJNJiTh9Hoazo26SdsrzvV_c,242
|
|
27
|
-
tests/test_storage_filecache.py,sha256=dM7K_L7eVChHUAj6PRxJXO3TqZL3nT6SkXCLhNm5TOM,5643
|
|
28
|
-
tests/test_storage_redis.py,sha256=85KRcj7vvZJkbuXP-lrEgQbPzGV-zVfrrWJQ8cRlKJ4,582
|
|
29
|
-
tests/test_vary.py,sha256=9_atX8Ke6mnUJY55951Jm_OwE0iGTG2bE8SMYLcN3A4,3010
|
|
30
|
-
tests/utils.py,sha256=moJFC6c1DoBE3g2RXiTMpkx9s7kAHPyuecFNL9-E5Ts,800
|
|
31
|
-
CacheControl-0.12.12.dist-info/LICENSE.txt,sha256=hu7uh74qQ_P_H1ZJb0UfaSQ5JvAl_tuwM2ZsMExMFhs,558
|
|
32
|
-
CacheControl-0.12.12.dist-info/METADATA,sha256=HyUOWdTjS_lttql8pn7IR-mCkekHRknEFEJ-XGjHdM0,2220
|
|
33
|
-
CacheControl-0.12.12.dist-info/WHEEL,sha256=WzZ8cwjh8l0jtULNjYq1Hpr-WCqCRgPr--TX4P5I1Wo,110
|
|
34
|
-
CacheControl-0.12.12.dist-info/entry_points.txt,sha256=HjCekaRCv8kfNqP5WehMR29IWxIA5VrhoOeKrCykCLc,56
|
|
35
|
-
CacheControl-0.12.12.dist-info/top_level.txt,sha256=oS14uDLs5PLbW4rppF8Rbs5UGe3AO5_yIaB9PEkN_4U,19
|
|
36
|
-
CacheControl-0.12.12.dist-info/RECORD,,
|
tests/__init__.py
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"""Tests for CacheControl."""
|
tests/conftest.py
DELETED
|
@@ -1,155 +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(object):
|
|
16
|
-
|
|
17
|
-
def __init__(self):
|
|
18
|
-
self.etag_count = 0
|
|
19
|
-
self.update_etag_string()
|
|
20
|
-
|
|
21
|
-
def dispatch(self, env):
|
|
22
|
-
path = env["PATH_INFO"][1:].split("/")
|
|
23
|
-
segment = path.pop(0)
|
|
24
|
-
if segment and hasattr(self, segment):
|
|
25
|
-
return getattr(self, segment)
|
|
26
|
-
|
|
27
|
-
return None
|
|
28
|
-
|
|
29
|
-
def optional_cacheable_request(self, env, start_response):
|
|
30
|
-
"""A request with no hints as to whether it should be
|
|
31
|
-
cached. Yet, we might still choose to cache it via a
|
|
32
|
-
heuristic."""
|
|
33
|
-
|
|
34
|
-
headers = [
|
|
35
|
-
("server", "nginx/1.2.6 (Ubuntu)"),
|
|
36
|
-
("last-modified", "Mon, 21 Jul 2014 17:45:39 GMT"),
|
|
37
|
-
("content-type", "text/html"),
|
|
38
|
-
]
|
|
39
|
-
|
|
40
|
-
start_response("200 OK", headers)
|
|
41
|
-
return [pformat(env).encode("utf8")]
|
|
42
|
-
|
|
43
|
-
def vary_accept(self, env, start_response):
|
|
44
|
-
response = pformat(env).encode("utf8")
|
|
45
|
-
|
|
46
|
-
headers = [
|
|
47
|
-
("Cache-Control", "max-age=5000"),
|
|
48
|
-
("Content-Type", "text/plain"),
|
|
49
|
-
("Vary", "Accept-Encoding, Accept"),
|
|
50
|
-
]
|
|
51
|
-
start_response("200 OK", headers)
|
|
52
|
-
return [response]
|
|
53
|
-
|
|
54
|
-
def update_etag_string(self):
|
|
55
|
-
self.etag_count += 1
|
|
56
|
-
self.etag_string = '"ETAG-{}"'.format(self.etag_count)
|
|
57
|
-
|
|
58
|
-
def update_etag(self, env, start_response):
|
|
59
|
-
self.update_etag_string()
|
|
60
|
-
headers = [("Cache-Control", "max-age=5000"), ("Content-Type", "text/plain")]
|
|
61
|
-
start_response("200 OK", headers)
|
|
62
|
-
return [pformat(env).encode("utf8")]
|
|
63
|
-
|
|
64
|
-
def conditional_get(self, env, start_response):
|
|
65
|
-
return start_response("304 Not Modified", [])
|
|
66
|
-
|
|
67
|
-
def etag(self, env, start_response):
|
|
68
|
-
headers = [("Etag", self.etag_string)]
|
|
69
|
-
if env.get("HTTP_IF_NONE_MATCH") == self.etag_string:
|
|
70
|
-
start_response("304 Not Modified", headers)
|
|
71
|
-
return []
|
|
72
|
-
else:
|
|
73
|
-
start_response("200 OK", headers)
|
|
74
|
-
return [pformat(env).encode("utf8")]
|
|
75
|
-
|
|
76
|
-
def cache_60(self, env, start_response):
|
|
77
|
-
headers = [("Cache-Control", "public, max-age=60")]
|
|
78
|
-
start_response("200 OK", headers)
|
|
79
|
-
return [pformat(env).encode("utf8")]
|
|
80
|
-
|
|
81
|
-
def no_cache(self, env, start_response):
|
|
82
|
-
headers = [("Cache-Control", "no-cache")]
|
|
83
|
-
start_response("200 OK", headers)
|
|
84
|
-
return [pformat(env).encode("utf8")]
|
|
85
|
-
|
|
86
|
-
def permanent_redirect(self, env, start_response):
|
|
87
|
-
headers = [("Location", "/permalink")]
|
|
88
|
-
start_response("301 Moved Permanently", headers)
|
|
89
|
-
return ["See: /permalink".encode("utf-8")]
|
|
90
|
-
|
|
91
|
-
def permalink(self, env, start_response):
|
|
92
|
-
start_response("200 OK", [("Content-Type", "text/plain")])
|
|
93
|
-
return ["The permanent resource".encode("utf-8")]
|
|
94
|
-
|
|
95
|
-
def multiple_choices(self, env, start_response):
|
|
96
|
-
headers = [("Link", "/permalink")]
|
|
97
|
-
start_response("300 Multiple Choices", headers)
|
|
98
|
-
return ["See: /permalink".encode("utf-8")]
|
|
99
|
-
|
|
100
|
-
def stream(self, env, start_response):
|
|
101
|
-
headers = [("Content-Type", "text/plain"), ("Cache-Control", "max-age=5000")]
|
|
102
|
-
start_response("200 OK", headers)
|
|
103
|
-
|
|
104
|
-
for i in range(10):
|
|
105
|
-
yield pformat(i).encode("utf8")
|
|
106
|
-
|
|
107
|
-
def __call__(self, env, start_response):
|
|
108
|
-
func = self.dispatch(env)
|
|
109
|
-
|
|
110
|
-
if func:
|
|
111
|
-
return func(env, start_response)
|
|
112
|
-
|
|
113
|
-
headers = [("Cache-Control", "max-age=5000"), ("Content-Type", "text/plain")]
|
|
114
|
-
start_response("200 OK", headers)
|
|
115
|
-
return [pformat(env).encode("utf8")]
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
@pytest.fixture(scope="session")
|
|
119
|
-
def server():
|
|
120
|
-
return cherrypy.server
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
@pytest.fixture()
|
|
124
|
-
def url(server):
|
|
125
|
-
return "http://%s:%s/" % server.bind_addr
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
def get_free_port():
|
|
129
|
-
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
130
|
-
s.bind(("", 0))
|
|
131
|
-
ip, port = s.getsockname()
|
|
132
|
-
s.close()
|
|
133
|
-
ip = os.environ.get("WEBTEST_SERVER_BIND", "127.0.0.1")
|
|
134
|
-
return ip, port
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
def pytest_configure(config):
|
|
138
|
-
cherrypy.tree.graft(SimpleApp(), "/")
|
|
139
|
-
|
|
140
|
-
ip, port = get_free_port()
|
|
141
|
-
|
|
142
|
-
cherrypy.config.update({"server.socket_host": ip, "server.socket_port": port})
|
|
143
|
-
|
|
144
|
-
# turn off logging
|
|
145
|
-
logger = cherrypy.log.access_log
|
|
146
|
-
logger.removeHandler(logger.handlers[0])
|
|
147
|
-
|
|
148
|
-
cherrypy.server.start()
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
def pytest_unconfigure(config):
|
|
152
|
-
try:
|
|
153
|
-
cherrypy.server.stop()
|
|
154
|
-
except:
|
|
155
|
-
pass
|
tests/issue_263.py
DELETED
|
@@ -1,50 +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
|
-
from pprint import pprint
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
class NoAgeHeuristic(BaseHeuristic):
|
|
20
|
-
def update_headers(self, response):
|
|
21
|
-
if "cache-control" in response.headers:
|
|
22
|
-
del response.headers["cache-control"]
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
cache_adapter = cachecontrol.CacheControlAdapter(
|
|
26
|
-
DictCache(), cache_etags=True, heuristic=NoAgeHeuristic()
|
|
27
|
-
)
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
session = requests.Session()
|
|
31
|
-
session.mount("https://", cache_adapter)
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
def log_resp(resp):
|
|
35
|
-
return
|
|
36
|
-
|
|
37
|
-
print(f"{resp.status_code} {resp.request.method}")
|
|
38
|
-
for k, v in response.headers.items():
|
|
39
|
-
print(f"{k}: {v}")
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
for i in range(2):
|
|
43
|
-
response = session.get(
|
|
44
|
-
"https://api.github.com/repos/sigmavirus24/github3.py/pulls/1033"
|
|
45
|
-
)
|
|
46
|
-
log_resp(response)
|
|
47
|
-
print(f"Content length: {len(response.content)}")
|
|
48
|
-
print(response.from_cache)
|
|
49
|
-
if len(response.content) == 0:
|
|
50
|
-
sys.exit(1)
|
tests/test_adapter.py
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
# SPDX-FileCopyrightText: 2015 Eric Larson
|
|
2
|
-
#
|
|
3
|
-
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
-
|
|
5
|
-
import mock
|
|
6
|
-
import pytest
|
|
7
|
-
|
|
8
|
-
from requests import Session
|
|
9
|
-
from cachecontrol.adapter import CacheControlAdapter
|
|
10
|
-
from cachecontrol.cache import DictCache
|
|
11
|
-
from cachecontrol.wrapper import CacheControl
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
def use_wrapper():
|
|
15
|
-
print("Using helper")
|
|
16
|
-
sess = CacheControl(Session())
|
|
17
|
-
return sess
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
def use_adapter():
|
|
21
|
-
print("Using adapter")
|
|
22
|
-
sess = Session()
|
|
23
|
-
sess.mount("http://", CacheControlAdapter())
|
|
24
|
-
return sess
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
@pytest.fixture(params=[use_adapter, use_wrapper])
|
|
28
|
-
def sess(url, request):
|
|
29
|
-
sess = request.param()
|
|
30
|
-
sess.get(url)
|
|
31
|
-
yield sess
|
|
32
|
-
|
|
33
|
-
# closing session object
|
|
34
|
-
sess.close()
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
class TestSessionActions(object):
|
|
38
|
-
|
|
39
|
-
def test_get_caches(self, url, sess):
|
|
40
|
-
r2 = sess.get(url)
|
|
41
|
-
assert r2.from_cache is True
|
|
42
|
-
|
|
43
|
-
def test_get_with_no_cache_does_not_cache(self, url, sess):
|
|
44
|
-
r2 = sess.get(url, headers={"Cache-Control": "no-cache"})
|
|
45
|
-
assert not r2.from_cache
|
|
46
|
-
|
|
47
|
-
def test_put_invalidates_cache(self, url, sess):
|
|
48
|
-
r2 = sess.put(url, data={"foo": "bar"})
|
|
49
|
-
sess.get(url)
|
|
50
|
-
assert not r2.from_cache
|
|
51
|
-
|
|
52
|
-
def test_patch_invalidates_cache(self, url, sess):
|
|
53
|
-
r2 = sess.patch(url, data={"foo": "bar"})
|
|
54
|
-
sess.get(url)
|
|
55
|
-
assert not r2.from_cache
|
|
56
|
-
|
|
57
|
-
def test_delete_invalidates_cache(self, url, sess):
|
|
58
|
-
r2 = sess.delete(url)
|
|
59
|
-
sess.get(url)
|
|
60
|
-
assert not r2.from_cache
|
|
61
|
-
|
|
62
|
-
def test_close(self):
|
|
63
|
-
cache = mock.Mock(spec=DictCache)
|
|
64
|
-
sess = Session()
|
|
65
|
-
sess.mount("http://", CacheControlAdapter(cache))
|
|
66
|
-
|
|
67
|
-
sess.close()
|
|
68
|
-
assert cache.close.called
|