Python cache.get() Examples
The following are 9
code examples of cache.get().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
cache
, or try the search function
.
Example #1
Source File: wttr_srv.py From wttr.in with Apache License 2.0 | 6 votes |
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
Example #2
Source File: wttr_srv.py From wttr.in with Apache License 2.0 | 5 votes |
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
Example #3
Source File: client.py From plugin.video.sparkle with GNU General Public License v3.0 | 5 votes |
def agent(): return cache.get(randomagent, 1)
Example #4
Source File: helper.py From plugin.video.xxx-o-dus with GNU General Public License v3.0 | 5 votes |
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)
Example #5
Source File: comments.py From cheat.sh with MIT License | 5 votes |
def _language_name(name): return VIM_NAME.get(name, name)
Example #6
Source File: comments.py From cheat.sh with MIT License | 5 votes |
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
Example #7
Source File: stateful_queries.py From cheat.sh with MIT License | 5 votes |
def last_query(client_id): """ Return the last query for the client `client_id` """ return cache.get("l:%s" % client_id)
Example #8
Source File: wttr_srv.py From wttr.in with Apache License 2.0 | 4 votes |
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)
Example #9
Source File: routing.py From cheat.sh with MIT License | 4 votes |
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