Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/cachecontrol.vendor
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Update CacheControl to 0.12.5
1 change: 1 addition & 0 deletions news/certifi.vendor
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Update certifi to 2018.4.16
1 change: 1 addition & 0 deletions news/distro.vendor
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Update distro to 1.3.0
1 change: 1 addition & 0 deletions news/idna.vendor
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Update idna to 2.7
1 change: 1 addition & 0 deletions news/ipaddress.vendor
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Update ipaddress to 1.0.22
1 change: 1 addition & 0 deletions news/pkg_resources.vendor
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Update pkg_resources to 39.2.0 (via setuptools)
1 change: 1 addition & 0 deletions news/progress.vendor
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Update progress to 1.4
1 change: 1 addition & 0 deletions news/pytoml.vendor
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Update pytoml to 0.1.16
1 change: 1 addition & 0 deletions news/requests.vendor
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Update requests to 2.19.1
1 change: 1 addition & 0 deletions news/urllib3.vendor
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Update urllib3 to 1.23
6 changes: 3 additions & 3 deletions src/pip/_vendor/cachecontrol/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

Make it easy to import from cachecontrol without long namespaces.
"""
__author__ = 'Eric Larson'
__email__ = 'eric@ionrock.org'
__version__ = '0.12.4'
__author__ = "Eric Larson"
__email__ = "eric@ionrock.org"
__version__ = "0.12.5"

from .wrapper import CacheControl
from .adapter import CacheControlAdapter
Expand Down
17 changes: 7 additions & 10 deletions src/pip/_vendor/cachecontrol/_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,19 @@ def setup_logging():

def get_session():
adapter = CacheControlAdapter(
DictCache(),
cache_etags=True,
serializer=None,
heuristic=None,
DictCache(), cache_etags=True, serializer=None, heuristic=None
)
sess = requests.Session()
sess.mount('http://', adapter)
sess.mount('https://', adapter)
sess.mount("http://", adapter)
sess.mount("https://", adapter)

sess.cache_controller = adapter.controller
return sess


def get_args():
parser = ArgumentParser()
parser.add_argument('url', help='The URL to try and cache')
parser.add_argument("url", help="The URL to try and cache")
return parser.parse_args()


Expand All @@ -51,10 +48,10 @@ def main(args=None):

# Now try to get it
if sess.cache_controller.cached_request(resp.request):
print('Cached!')
print("Cached!")
else:
print('Not cached :(')
print("Not cached :(")


if __name__ == '__main__':
if __name__ == "__main__":
main()
55 changes: 27 additions & 28 deletions src/pip/_vendor/cachecontrol/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,27 @@


class CacheControlAdapter(HTTPAdapter):
invalidating_methods = set(['PUT', 'DELETE'])

def __init__(self, cache=None,
cache_etags=True,
controller_class=None,
serializer=None,
heuristic=None,
cacheable_methods=None,
*args, **kw):
invalidating_methods = {"PUT", "DELETE"}

def __init__(
self,
cache=None,
cache_etags=True,
controller_class=None,
serializer=None,
heuristic=None,
cacheable_methods=None,
*args,
**kw
):
super(CacheControlAdapter, self).__init__(*args, **kw)
self.cache = cache or DictCache()
self.heuristic = heuristic
self.cacheable_methods = cacheable_methods or ('GET',)
self.cacheable_methods = cacheable_methods or ("GET",)

controller_factory = controller_class or CacheController
self.controller = controller_factory(
self.cache,
cache_etags=cache_etags,
serializer=serializer,
self.cache, cache_etags=cache_etags, serializer=serializer
)

def send(self, request, cacheable_methods=None, **kw):
Expand All @@ -43,20 +45,18 @@ def send(self, request, cacheable_methods=None, **kw):
except zlib.error:
cached_response = None
if cached_response:
return self.build_response(request, cached_response,
from_cache=True)
return self.build_response(request, cached_response, from_cache=True)

# check for etags and add headers if appropriate
request.headers.update(
self.controller.conditional_headers(request)
)
request.headers.update(self.controller.conditional_headers(request))

resp = super(CacheControlAdapter, self).send(request, **kw)

return resp

def build_response(self, request, response, from_cache=False,
cacheable_methods=None):
def build_response(
self, request, response, from_cache=False, cacheable_methods=None
):
"""
Build a response by making a request or using the cache.

Expand Down Expand Up @@ -101,10 +101,8 @@ def build_response(self, request, response, from_cache=False,
response._fp = CallbackFileWrapper(
response._fp,
functools.partial(
self.controller.cache_response,
request,
response,
)
self.controller.cache_response, request, response
),
)
if response.chunked:
super_update_chunk_length = response._update_chunk_length
Expand All @@ -113,11 +111,12 @@ def _update_chunk_length(self):
super_update_chunk_length()
if self.chunk_left == 0:
self._fp._close()
response._update_chunk_length = types.MethodType(_update_chunk_length, response)

resp = super(CacheControlAdapter, self).build_response(
request, response
)
response._update_chunk_length = types.MethodType(
_update_chunk_length, response
)

resp = super(CacheControlAdapter, self).build_response(request, response)

# See if we should invalidate the cache.
if request.method in self.invalidating_methods and resp.ok:
Expand Down
6 changes: 3 additions & 3 deletions src/pip/_vendor/cachecontrol/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
class BaseCache(object):

def get(self, key):
raise NotImplemented()
raise NotImplementedError()

def set(self, key, value):
raise NotImplemented()
raise NotImplementedError()

def delete(self, key):
raise NotImplemented()
raise NotImplementedError()

def close(self):
pass
Expand Down
31 changes: 22 additions & 9 deletions src/pip/_vendor/cachecontrol/caches/file_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
FileNotFoundError
except NameError:
# py2.X
FileNotFoundError = OSError
FileNotFoundError = (IOError, OSError)


def _secure_open_write(filename, fmode):
Expand Down Expand Up @@ -46,15 +46,24 @@ def _secure_open_write(filename, fmode):
fd = os.open(filename, flags, fmode)
try:
return os.fdopen(fd, "wb")

except:
# An error occurred wrapping our FD in a file object
os.close(fd)
raise


class FileCache(BaseCache):
def __init__(self, directory, forever=False, filemode=0o0600,
dirmode=0o0700, use_dir_lock=None, lock_class=None):

def __init__(
self,
directory,
forever=False,
filemode=0o0600,
dirmode=0o0700,
use_dir_lock=None,
lock_class=None,
):

if use_dir_lock is not None and lock_class is not None:
raise ValueError("Cannot use use_dir_lock and lock_class together")
Expand All @@ -63,12 +72,15 @@ def __init__(self, directory, forever=False, filemode=0o0600,
from pip._vendor.lockfile import LockFile
from pip._vendor.lockfile.mkdirlockfile import MkdirLockFile
except ImportError:
notice = dedent("""
notice = dedent(
"""
NOTE: In order to use the FileCache you must have
lockfile installed. You can install it via pip:
pip install lockfile
""")
"""
)
raise ImportError(notice)

else:
if use_dir_lock:
lock_class = MkdirLockFile
Expand All @@ -95,11 +107,12 @@ def _fn(self, name):

def get(self, key):
name = self._fn(key)
if not os.path.exists(name):
return None
try:
with open(name, "rb") as fh:
return fh.read()

with open(name, 'rb') as fh:
return fh.read()
except FileNotFoundError:
return None

def set(self, key, value):
name = self._fn(key)
Expand Down
12 changes: 1 addition & 11 deletions src/pip/_vendor/cachecontrol/caches/redis_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,6 @@
from pip._vendor.cachecontrol.cache import BaseCache


def total_seconds(td):
"""Python 2.6 compatability"""
if hasattr(td, 'total_seconds'):
return int(td.total_seconds())

ms = td.microseconds
secs = (td.seconds + td.days * 24 * 3600)
return int((ms + secs * 10**6) / 10**6)


class RedisCache(BaseCache):

def __init__(self, conn):
Expand All @@ -27,7 +17,7 @@ def set(self, key, value, expires=None):
self.conn.set(key, value)
else:
expires = expires - datetime.utcnow()
self.conn.setex(key, total_seconds(expires), value)
self.conn.setex(key, int(expires.total_seconds()), value)

def delete(self, key):
self.conn.delete(key)
Expand Down
Loading