summaryrefslogtreecommitdiff
path: root/venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_vendor/cachecontrol/caches
diff options
context:
space:
mode:
Diffstat (limited to 'venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_vendor/cachecontrol/caches')
-rw-r--r--venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_vendor/cachecontrol/caches/__init__.py2
-rw-r--r--venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_vendor/cachecontrol/caches/file_cache.py133
-rw-r--r--venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_vendor/cachecontrol/caches/redis_cache.py43
3 files changed, 0 insertions, 178 deletions
diff --git a/venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_vendor/cachecontrol/caches/__init__.py b/venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_vendor/cachecontrol/caches/__init__.py
deleted file mode 100644
index 1193f26..0000000
--- a/venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_vendor/cachecontrol/caches/__init__.py
+++ /dev/null
@@ -1,2 +0,0 @@
1from .file_cache import FileCache # noqa
2from .redis_cache import RedisCache # noqa
diff --git a/venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_vendor/cachecontrol/caches/file_cache.py b/venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_vendor/cachecontrol/caches/file_cache.py
deleted file mode 100644
index f7eb890..0000000
--- a/venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_vendor/cachecontrol/caches/file_cache.py
+++ /dev/null
@@ -1,133 +0,0 @@
1import hashlib
2import os
3from textwrap import dedent
4
5from ..cache import BaseCache
6from ..controller import CacheController
7
8try:
9 FileNotFoundError
10except NameError:
11 # py2.X
12 FileNotFoundError = OSError
13
14
15def _secure_open_write(filename, fmode):
16 # We only want to write to this file, so open it in write only mode
17 flags = os.O_WRONLY
18
19 # os.O_CREAT | os.O_EXCL will fail if the file already exists, so we only
20 # will open *new* files.
21 # We specify this because we want to ensure that the mode we pass is the
22 # mode of the file.
23 flags |= os.O_CREAT | os.O_EXCL
24
25 # Do not follow symlinks to prevent someone from making a symlink that
26 # we follow and insecurely open a cache file.
27 if hasattr(os, "O_NOFOLLOW"):
28 flags |= os.O_NOFOLLOW
29
30 # On Windows we'll mark this file as binary
31 if hasattr(os, "O_BINARY"):
32 flags |= os.O_BINARY
33
34 # Before we open our file, we want to delete any existing file that is
35 # there
36 try:
37 os.remove(filename)
38 except (IOError, OSError):
39 # The file must not exist already, so we can just skip ahead to opening
40 pass
41
42 # Open our file, the use of os.O_CREAT | os.O_EXCL will ensure that if a
43 # race condition happens between the os.remove and this line, that an
44 # error will be raised. Because we utilize a lockfile this should only
45 # happen if someone is attempting to attack us.
46 fd = os.open(filename, flags, fmode)
47 try:
48 return os.fdopen(fd, "wb")
49 except:
50 # An error occurred wrapping our FD in a file object
51 os.close(fd)
52 raise
53
54
55class FileCache(BaseCache):
56 def __init__(self, directory, forever=False, filemode=0o0600,
57 dirmode=0o0700, use_dir_lock=None, lock_class=None):
58
59 if use_dir_lock is not None and lock_class is not None:
60 raise ValueError("Cannot use use_dir_lock and lock_class together")
61
62 try:
63 from pip._vendor.lockfile import LockFile
64 from pip._vendor.lockfile.mkdirlockfile import MkdirLockFile
65 except ImportError:
66 notice = dedent("""
67 NOTE: In order to use the FileCache you must have
68 lockfile installed. You can install it via pip:
69 pip install lockfile
70 """)
71 raise ImportError(notice)
72 else:
73 if use_dir_lock:
74 lock_class = MkdirLockFile
75
76 elif lock_class is None:
77 lock_class = LockFile
78
79 self.directory = directory
80 self.forever = forever
81 self.filemode = filemode
82 self.dirmode = dirmode
83 self.lock_class = lock_class
84
85 @staticmethod
86 def encode(x):
87 return hashlib.sha224(x.encode()).hexdigest()
88
89 def _fn(self, name):
90 # NOTE: This method should not change as some may depend on it.
91 # See: https://github.com/ionrock/cachecontrol/issues/63
92 hashed = self.encode(name)
93 parts = list(hashed[:5]) + [hashed]
94 return os.path.join(self.directory, *parts)
95
96 def get(self, key):
97 name = self._fn(key)
98 if not os.path.exists(name):
99 return None
100
101 with open(name, 'rb') as fh:
102 return fh.read()
103
104 def set(self, key, value):
105 name = self._fn(key)
106
107 # Make sure the directory exists
108 try:
109 os.makedirs(os.path.dirname(name), self.dirmode)
110 except (IOError, OSError):
111 pass
112
113 with self.lock_class(name) as lock:
114 # Write our actual file
115 with _secure_open_write(lock.path, self.filemode) as fh:
116 fh.write(value)
117
118 def delete(self, key):
119 name = self._fn(key)
120 if not self.forever:
121 try:
122 os.remove(name)
123 except FileNotFoundError:
124 pass
125
126
127def url_to_file_path(url, filecache):
128 """Return the file cache path based on the URL.
129
130 This does not ensure the file exists!
131 """
132 key = CacheController.cache_url(url)
133 return filecache._fn(key)
diff --git a/venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_vendor/cachecontrol/caches/redis_cache.py b/venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_vendor/cachecontrol/caches/redis_cache.py
deleted file mode 100644
index db1e09d..0000000
--- a/venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_vendor/cachecontrol/caches/redis_cache.py
+++ /dev/null
@@ -1,43 +0,0 @@
1from __future__ import division
2
3from datetime import datetime
4from pip._vendor.cachecontrol.cache import BaseCache
5
6
7def total_seconds(td):
8 """Python 2.6 compatability"""
9 if hasattr(td, 'total_seconds'):
10 return int(td.total_seconds())
11
12 ms = td.microseconds
13 secs = (td.seconds + td.days * 24 * 3600)
14 return int((ms + secs * 10**6) / 10**6)
15
16
17class RedisCache(BaseCache):
18
19 def __init__(self, conn):
20 self.conn = conn
21
22 def get(self, key):
23 return self.conn.get(key)
24
25 def set(self, key, value, expires=None):
26 if not expires:
27 self.conn.set(key, value)
28 else:
29 expires = expires - datetime.utcnow()
30 self.conn.setex(key, total_seconds(expires), value)
31
32 def delete(self, key):
33 self.conn.delete(key)
34
35 def clear(self):
36 """Helper for clearing all the keys in a database. Use with
37 caution!"""
38 for key in self.conn.keys():
39 self.conn.delete(key)
40
41 def close(self):
42 """Redis uses connection pooling, no need to close the connection."""
43 pass