Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_simple_lockfile_arg(self, tmpdir, value, expected):
if value is not None:
cache = FileCache(str(tmpdir), use_dir_lock=value)
else:
cache = FileCache(str(tmpdir))
assert issubclass(cache.lock_class, expected)
cache.close()
session = CacheControl(
requests.Session(),
cache=FileCache(
os.path.join(os.environ["HOME"], ".cache", "salad")
),
)
elif "TMPDIR" in os.environ:
session = CacheControl(
requests.Session(),
cache=FileCache(
os.path.join(os.environ["TMPDIR"], ".cache", "salad")
),
)
else:
session = CacheControl(
requests.Session(), cache=FileCache("/tmp", ".cache", "salad")
)
self.fetcher = DefaultFetcher({}, session) # type: Fetcher
else:
self.fetcher = fetcher
self.vocab = _vocab
self.rvocab = _rvocab
if namespaces is not None:
self.vocab = self.vocab.copy()
self.rvocab = self.rvocab.copy()
for k, v in namespaces.items():
self.vocab[k] = v
self.rvocab[v] = k
from cachecontrol import CacheControl
from cachecontrol.caches import FileCache
from elex.cachecontrol_heuristics import EtagOnlyCache
__version__ = '2.4.3'
_DEFAULT_CACHE_DIRECTORY = os.path.join(tempfile.gettempdir(), 'elex-cache')
API_KEY = os.environ.get('AP_API_KEY', None)
API_VERSION = os.environ.get('AP_API_VERSION', 'v2')
BASE_URL = os.environ.get('AP_API_BASE_URL', 'http://api.ap.org/{0}'.format(API_VERSION))
CACHE_DIRECTORY = os.environ.get('ELEX_CACHE_DIRECTORY', _DEFAULT_CACHE_DIRECTORY)
session = requests.session()
session.headers.update({'Accept-Encoding': 'gzip'})
cache = CacheControl(session,
cache=FileCache(CACHE_DIRECTORY),
heuristic=EtagOnlyCache())
if cache is not None:
self.cache = cache
else:
self.cache = {}
if skip_schemas is not None:
self.skip_schemas = skip_schemas
else:
self.skip_schemas = False
if session is None:
if "HOME" in os.environ:
self.session = CacheControl(
requests.Session(),
cache=FileCache(
os.path.join(os.environ["HOME"], ".cache", "salad")
),
)
elif "TMP" in os.environ:
self.session = CacheControl(
requests.Session(),
cache=FileCache(os.path.join(os.environ["TMP"], ".cache", "salad")),
)
else:
self.session = CacheControl(
requests.Session(),
cache=FileCache(os.path.join("/tmp", ".cache", "salad")),
)
else:
self.session = session
def downloadHttpFile(httpurl):
# type: (str) -> str
cache_session = None
if "XDG_CACHE_HOME" in os.environ:
directory = os.environ["XDG_CACHE_HOME"]
elif "HOME" in os.environ:
directory = os.environ["HOME"]
else:
directory = os.path.expanduser("~")
cache_session = CacheControl(
requests.Session(),
cache=FileCache(os.path.join(directory, ".cache", "cwltool")),
)
r = cache_session.get(httpurl, stream=True)
with NamedTemporaryFile(mode="wb", delete=False) as f:
for chunk in r.iter_content(chunk_size=16384):
if chunk: # filter out keep-alive new chunks
f.write(chunk)
r.close()
return str(f.name)
fetcher = copyfrom.fetcher
if fileuri is None:
fileuri = copyfrom.fileuri
else:
self.idx = {}
if fetcher is None:
import os
import requests
from cachecontrol.wrapper import CacheControl
from cachecontrol.caches import FileCache
from schema_salad.ref_resolver import DefaultFetcher
if "HOME" in os.environ:
session = CacheControl(
requests.Session(),
cache=FileCache(os.path.join(os.environ["HOME"], ".cache", "salad")))
elif "TMP" in os.environ:
session = CacheControl(
requests.Session(),
cache=FileCache(os.path.join(os.environ["TMP"], ".cache", "salad")))
else:
session = CacheControl(
requests.Session(),
cache=FileCache("/tmp", ".cache", "salad"))
self.fetcher = DefaultFetcher({}, session)
else:
self.fetcher = fetcher
self.fileuri = fileuri
self.vocab = _vocab
self.rvocab = _rvocab
def main(argv):
sess = CacheControl(requests.Session(),
cache=FileCache('.web_cache'))
requests.get = sess.get
schema = tools.load('schema.json')
schema['definitions']['Parameter']['properties'] = parse_parameters()
tools.write(schema, 'schema.json')