本文整理汇总了Python中cache.get方法的典型用法代码示例。如果您正苦于以下问题:Python cache.get方法的具体用法?Python cache.get怎么用?Python cache.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cache
的用法示例。
在下文中一共展示了cache.get方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_answer_language_and_view
# 需要导入模块: import cache [as 别名]
# 或者: from cache import get [as 别名]
def get_answer_language_and_view(request):
"""
Return preferred answer language based on
domain name, query arguments and headers
"""
lang = None
view_name = None
hostname = request.headers['Host']
if hostname != 'wttr.in' and hostname.endswith('.wttr.in'):
lang = hostname[:-8]
if lang.startswith("v2"):
view_name = lang
lang = None
if 'lang' in request.args:
lang = request.args.get('lang')
if lang.lower() == 'none':
lang = None
header_accept_language = request.headers.get('Accept-Language', '')
if lang is None and header_accept_language:
lang = _parse_language_header(header_accept_language)
return lang, view_name
示例2: get_output_format
# 需要导入模块: import cache [as 别名]
# 或者: from cache import get [as 别名]
def get_output_format(query, parsed_query):
"""
Return preferred output format: ansi, text, html or png
based on arguments and headers in `request`.
Return new location (can be rewritten)
"""
if ('view' in query and not query["view"].startswith("v2")) \
or parsed_query.get("png_filename") \
or query.get('force-ansi'):
return False
user_agent = parsed_query.get("user_agent", "").lower()
html_output = not any(agent in user_agent for agent in PLAIN_TEXT_AGENTS)
return html_output
示例3: agent
# 需要导入模块: import cache [as 别名]
# 或者: from cache import get [as 别名]
def agent():
return cache.get(randomagent, 1)
示例4: get_list
# 需要导入模块: import cache [as 别名]
# 或者: from cache import get [as 别名]
def get_list(self, mode, type, url, title_pattern, url_pattern, icon_pattern=None, site=None, d_p1=None, d_p2=None, d_p3=None, parse=None, cache_time=None,searched=False,stopend=False, isVideo=False, isDownloadable = False):
if cache_time: r = cache.get(client.request,cache_time,url)
else: r = client.request(url)
if 're|' in d_p3:
d_p3 = d_p3.replace('re|','')
r = dom_parser2.parse_dom(r, d_p1, {d_p2: re.compile('%s' % d_p3)})
else: r = dom_parser2.parse_dom(r, d_p1, {d_p2: d_p3})
if r:
dirlst = []
for i in r:
name = re.findall(r'%s' % title_pattern,i.content)[0]
name = kodi.sortX(i[1].encode('utf-8'))
url = re.findall(r'%s' % url_pattern,i.content)[0]
if icon_pattern:
iconimage = re.findall(r'%s' % icon_pattern,i.content)[0]
elif site: iconimage = xbmc.translatePath(os.path.join('special://home/addons/script.xxxodus.artwork', 'resources/art/%s/icon.png' % site))
else: iconimage = xbmc.translatePath(os.path.join('special://home/addons/' + kodi.get_id(), 'icon.png'))
fanarts = xbmc.translatePath(os.path.join('special://home/addons/script.xxxodus.artwork', 'resources/art/%s/fanart.jpg' % site))
if parse:
link,tag = parse.split('|SPLIT|')
if tag == 'url':
url = urlparse.urljoin(link,url)
elif tag == 'icon':
iconimage = urlparse.urljoin(link,iconimage)
else:
url = urlparse.urljoin(link,url)
iconimage = urlparse.urljoin(link,iconimage)
if site: url += '|SPLIT|' + site
if type == 'dir': dirlst.append({'name': kodi.giveColor(name,'white'), 'url': url, 'mode': mode, 'icon': iconimage, 'fanart': fanarts, 'description': name, 'folder': True})
else: dirlst.append({'name': kodi.giveColor(name,'white'), 'url': url, 'mode': mode, 'icon': iconimage, 'fanart': fanarts, 'description': name, 'folder': False})
if dirlst:
if stopend: buildDirectory(dirlst, stopend=True, isVideo=isVideo, isDownloadable=isDownloadable)
else: buildDirectory(dirlst, isVideo=isVideo, isDownloadable=isDownloadable)
示例5: _language_name
# 需要导入模块: import cache [as 别名]
# 或者: from cache import get [as 别名]
def _language_name(name):
return VIM_NAME.get(name, name)
示例6: beautify
# 需要导入模块: import cache [as 别名]
# 或者: from cache import get [as 别名]
def beautify(text, lang, options):
"""
Process input `text` according to the specified `mode`.
Adds comments if needed, according to the `lang` rules.
Caches the results.
The whole work (except caching) is done by _beautify().
"""
options = options or {}
beauty_options = dict((k, v) for k, v in options.items() if k in
['add_comments', 'remove_text'])
mode = ''
if beauty_options.get('add_comments'):
mode += 'c'
if beauty_options.get('remove_text'):
mode += 'q'
if beauty_options == {}:
# if mode is unknown, just don't transform the text at all
return text
text = text.encode('utf-8')
digest = "t:%s:%s:%s" % (hashlib.md5(text).hexdigest(), lang, mode)
# temporary added line that removes invalid cache entries
# that used wrong commenting methods
if lang in ["git", "django", "flask", "cmake"]:
cache.delete(digest)
answer = cache.get(digest)
if answer:
return answer
answer = _beautify(text, lang, **beauty_options)
cache.put(digest, answer)
return answer
示例7: last_query
# 需要导入模块: import cache [as 别名]
# 或者: from cache import get [as 别名]
def last_query(client_id):
"""
Return the last query for the client `client_id`
"""
return cache.get("l:%s" % client_id)
示例8: _response
# 需要导入模块: import cache [as 别名]
# 或者: from cache import get [as 别名]
def _response(parsed_query, query, fast_mode=False):
"""Create response text based on `parsed_query` and `query` data.
If `fast_mode` is True, process only requests that can
be handled very fast (cached and static files).
"""
answer = None
cache_signature = cache.get_signature(
parsed_query["user_agent"],
parsed_query["request_url"],
parsed_query["ip_addr"],
parsed_query["lang"])
answer = cache.get(cache_signature)
if parsed_query['orig_location'] in PLAIN_TEXT_PAGES:
answer = show_text_file(parsed_query['orig_location'], parsed_query['lang'])
if parsed_query['html_output']:
answer = render_template('index.html', body=answer)
if answer or fast_mode:
return answer
# at this point, we could not handle the query fast,
# so we handle it with all available logic
loc = (parsed_query['orig_location'] or "").lower()
if parsed_query.get("view"):
output = wttr_line(query, parsed_query)
elif loc == 'moon' or loc.startswith('moon@'):
output = get_moon(parsed_query)
else:
output = get_wetter(parsed_query)
if parsed_query.get('png_filename'):
# originally it was just a usual function call,
# but it was a blocking call, so it was moved
# to separate threads:
#
# output = fmt.png.render_ansi(
# output, options=parsed_query)
result = TASKS.spawn(fmt.png.render_ansi, cache._update_answer(output), options=parsed_query)
output = result.get()
else:
if query.get('days', '3') != '0' \
and not query.get('no-follow-line') \
and ((parsed_query.get("view") or "v2")[:2] in ["v2"]):
if parsed_query['html_output']:
output = add_buttons(output)
else:
message = get_message('FOLLOW_ME', parsed_query['lang'])
if parsed_query.get('no-terminal', False):
message = remove_ansi(message)
output += '\n' + message + '\n'
return cache.store(cache_signature, output)
示例9: get_answer_dict
# 需要导入模块: import cache [as 别名]
# 或者: from cache import get [as 别名]
def get_answer_dict(self, topic, request_options=None):
"""
Find cheat sheet for the topic.
Args:
`topic` (str): the name of the topic of the cheat sheet
Returns:
answer_dict: the answer dictionary
"""
topic_type = self.get_topic_type(topic)
# 'question' queries are pretty expensive, that's why they should be handled
# in a special way:
# we do not drop the old style cache entries and try to reuse them if possible
if topic_type == 'question':
answer = cache.get('q:' + topic)
if answer:
if isinstance(answer, dict):
return answer
return {
'topic': topic,
'topic_type': 'question',
'answer': answer,
'format': 'text+code',
}
answer = self._get_page_dict(topic, topic_type, request_options=request_options)
cache.put('q:' + topic, answer)
return answer
# Try to find cacheable queries in the cache.
# If answer was not found in the cache, resolve it in a normal way and save in the cache
cache_needed = self._adapter[topic_type].is_cache_needed()
if cache_needed:
answer = cache.get(topic)
if not isinstance(answer, dict):
answer = None
if answer:
return answer
answer = self._get_page_dict(topic, topic_type, request_options=request_options)
if isinstance(answer, dict):
if "cache" in answer:
cache_needed = answer["cache"]
if cache_needed and answer:
cache.put(topic, answer)
return answer
# pylint: disable=invalid-name