Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@retry(tvrage_error)
def _loadUrl(self, url, params=None):
try:
log().debug("Retrieving URL %s" % url)
# get response from TVRage
if self.config['cache_enabled']:
session = CacheControl(sess=self.config['session'], cache=caches.FileCache(self.config['cache_location']), cache_etags=False)
if self.config['proxy']:
log().debug("Using proxy for URL: %s" % url)
session.proxies = {
"http": self.config['proxy'],
"https": self.config['proxy'],
}
resp = session.get(url.strip(), params=params)
else:
resp = requests.get(url.strip(), params=params)
resp.raise_for_status()
except requests.exceptions.HTTPError, e:
raise tvrage_error("HTTP error " + str(e.errno) + " while loading URL " + str(url))
except requests.exceptions.ConnectionError, e:
raise tvrage_error("Connection error " + str(e.message) + " while loading URL " + str(url))
def get_session(output_dir, verbose=True):
session = requests.Session()
try:
import cachecontrol
import cachecontrol.caches
except ImportError:
if verbose:
print("Tip: install CacheControl (conda package) to cache the CRAN metadata")
else:
session = cachecontrol.CacheControl(session,
cache=cachecontrol.caches.FileCache(join(output_dir,
'.web_cache')))
return session
def __init__(self):
self._session = cachecontrol.CacheControl(
requests.session(),
cache=cachecontrol.caches.FileCache(
join(cache_dir(), __name__ + ".ImageEmbedder.httpcache")
),
def get_session(output_dir, verbose=True, cache=[]):
if cache:
return cache[0]
session = requests.Session()
try:
import cachecontrol
import cachecontrol.caches
except ImportError:
if verbose:
print("Tip: install CacheControl to cache the CRAN metadata")
else:
session = cachecontrol.CacheControl(session,
cache=cachecontrol.caches.FileCache(join(output_dir,
'.web_cache')))
cache.append(session)
return session
def __init__(self, model, model_settings):
self.model = model
self._load_model()
self._target_image_size = model_settings["target_image_size"]
self._session = cachecontrol.CacheControl(
requests.session(),
cache=cachecontrol.caches.FileCache(
join(cache_dir(), __name__ + ".ImageEmbedder.httpcache")
),
)
self._cancelled = False
self._image_loader = ImageLoader()
self._cache = EmbedderCache(model)