Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@cachetools.cached(_profile_cache)
def get_profile(name):
return Profile.get_by_name(name)
def tdcache():
"""
Decorator to mark tensor description method as cached.
Returns:
Cache decorator set to use a particular cache.
"""
return cachetools.cached(cache=tdcache.tensor_description_cache)
@cached(cache={})
def get_boto_s3_resource():
session = get_boto_session()
return session.resource("s3")
@cachetools.cached(_target_cache, key=lambda x: str(x.id), lock=id_lock)
def get_target(self):
mo = ManagedObject.objects.filter(address=self.target)[:1]
if mo:
return mo[0]
return None
@cached(cache={})
def tags_database(self):
return self.client().get_collection_view(self.config.tags_database_url())
@cached(STATE_CACHE)
def _get_data(self):
payload = {'authuser': 0,
'hl': 'en',
'gl': 'us',
# pd holds the information about the rendering of the map and
# it is irrelevant with the location sharing capabilities.
# the below info points to google's headquarters.
'pb': ('!1m7!8m6!1m3!1i14!2i8413!3i5385!2i6!3x4095'
'!2m3!1e0!2sm!3i407105169!3m7!2sen!5e1105!12m4'
'!1e68!2m2!1sset!2sRoadmap!4e1!5m4!1e4!8m2!1e0!'
'1e1!6m9!1e12!2i2!26m1!4b1!30m1!'
'1f1.3953487873077393!39b1!44e1!50e0!23i4111425')}
url = 'https://www.google.com/maps/rpc/locationsharing/read'
response = self._session.get(url, params=payload, verify=True)
self._logger.debug(response.text)
if response.ok:
@cachetools.cached(self._clear_handlers_cache, key=lambda x: x.id, lock=handlers_lock)
def _get_handlers(alarm_class):
handlers = []
for hh in alarm_class.clear_handlers:
try:
h = get_handler(hh)
except ImportError:
h = None
if h:
handlers += [h]
return handlers
@cachetools.cached(cachetools.TTLCache(1, _NEWS_CACHE_TTL))
def _get_news_data(max_items=8):
""" Fetch news headline data from RÚV, preprocess it. """
res = query_json_api(_NEWS_API)
if not res or "nodes" not in res or not len(res["nodes"]):
return None
items = [
{"title": i["node"]["title"], "intro": i["node"]["intro"]} for i in res["nodes"]
]
return items[:max_items]
@cachetools.cached(cache, lock=cache_access_lock)
@functools.wraps(func)
def inner(*args, **kwargs):
return func(*args, **kwargs)