def remote_loader(request): # tested ''' create a vlam page from a request to get a remote file ''' url = unquote_plus(request.args["url"]) extension = url.split('.')[-1] username = request.crunchy_username if extension in preprocessor: # TODO: preprocessor don't forward Accept-Language HTTP headers page = plugin['create_vlam_page'](preprocessor[extension](url, local=False), url, username=username, remote=True) else: accept_lang = None if config[username]["forward_accept_language"]: accept_lang = request.headers.get("Accept-Language") page = unicode_urlopen(url, accept_lang) page = plugin['create_vlam_page'](page, url, username=username, remote=True) request.send_response(200) request.send_header('Cache-Control', 'no-cache, must-revalidate, no-store') request.end_headers() # write() in python 3.0 returns an int instead of None; # this interferes with unit tests dummy = request.wfile.write(page.read().encode('utf8'))
def remote_loader(request): # tested ''' create a vlam page from a request to get a remote file ''' url = unquote_plus(request.args["url"]) extension = url.split('.')[-1] username = request.crunchy_username if extension in preprocessor: # TODO: preprocessor don't forward Accept-Language HTTP headers page = plugin['create_vlam_page']( preprocessor[extension](url, local=False), url, username=username, remote=True) else: accept_lang = None if config[username]["forward_accept_language"]: accept_lang = request.headers.get("Accept-Language") page = unicode_urlopen(url, accept_lang) page = plugin['create_vlam_page'](page, url, username=username, remote=True) request.send_response(200) request.send_header('Cache-Control', 'no-cache, must-revalidate, no-store') request.end_headers() # write() in python 3.0 returns an int instead of None; # this interferes with unit tests dummy = request.wfile.write(page.read().encode('utf8'))
def convert_rst(path, local=True): '''converts an rst file into a proper crunchy-ready html page''' if local: file_ = codecs.open(path, 'r', 'utf-8') else: file_ = unicode_urlopen(path) data = publish_string(file_.read(), writer_name="html").decode('utf-8') rst_file = ReST_file(data) return rst_file