Python bottle.request.environ() Examples
The following are 30
code examples of bottle.request.environ().
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
bottle.request
, or try the search function
.
Example #1
Source File: browsermanager.py From conifer with Apache License 2.0 | 6 votes |
def __init__(self, config, browser_redis, user_manager): self.browser_redis = browser_redis self.browser_req_url = config['browser_req_url'] self.browser_info_url = config['browser_info_url'] self.browser_list_url = config['browser_list_url'] self.browsers = {} self.default_reqid = os.environ.get('BROWSER_ID') if not get_bool(os.environ.get('NO_REMOTE_BROWSERS')): self.load_all_browsers() gevent.spawn(self.browser_load_loop) self.user_manager = user_manager self.inactive_time = os.environ.get('INACTIVE_TIME', 60)
Example #2
Source File: usermanager.py From conifer with Apache License 2.0 | 6 votes |
def __init__(self, redis_url=None): config = load_wr_config() self.base_access = BaseAccess() # Init Redis if not redis_url: redis_url = os.environ['REDIS_BASE_URL'] r = redis.StrictRedis.from_url(redis_url, decode_responses=True) # Init Cork cork = WebRecCork.create_cork(r, config) super(CLIUserManager, self).__init__( redis=r, cork=cork, config=config)
Example #3
Source File: websockcontroller.py From conifer with Apache License 2.0 | 6 votes |
def init_routes(self): @self.app.get('/_client_ws') def client_ws(): try: return self.client_ws() except OSError: request.environ['webrec.ws_closed'] = True return @self.app.get('/_client_ws_cont') def client_ws_cont(): try: return self.client_ws_cont() except OSError: request.environ['webrec.ws_closed'] = True return
Example #4
Source File: bottle3.py From pyFileFixity with MIT License | 6 votes |
def path_shift(self, count=1): ''' Shift some levels of PATH_INFO into SCRIPT_NAME and return the moved part. count defaults to 1''' #/a/b/ /c/d --> 'a','b' 'c','d' if count == 0: return '' pathlist = self.path.strip('/').split('/') scriptlist = self.environ.get('SCRIPT_NAME','/').strip('/').split('/') if pathlist and pathlist[0] == '': pathlist = [] if scriptlist and scriptlist[0] == '': scriptlist = [] if count > 0 and count <= len(pathlist): moved = pathlist[:count] scriptlist = scriptlist + moved pathlist = pathlist[count:] elif count < 0 and count >= -len(scriptlist): moved = scriptlist[count:] pathlist = moved + pathlist scriptlist = scriptlist[:count] else: empty = 'SCRIPT_NAME' if count < 0 else 'PATH_INFO' raise AssertionError("Cannot shift. Nothing left from %s" % empty) self['PATH_INFO'] = self.path = '/' + '/'.join(pathlist) \ + ('/' if self.path.endswith('/') and pathlist else '') self['SCRIPT_NAME'] = '/' + '/'.join(scriptlist) return '/'.join(moved)
Example #5
Source File: bottle3.py From pyFileFixity with MIT License | 6 votes |
def bind(self, environ, app=None): """ Bind a new WSGI enviroment and clear out all previously computed attributes. This is done automatically for the global `bottle.request` instance on every request. """ if isinstance(environ, Request): # Recycle already parsed content for key in self.__dict__: #TODO: Test this setattr(self, key, getattr(environ, key)) self.app = app return self._GET = self._POST = self._GETPOST = self._COOKIES = None self._body = self._header = None self.environ = environ self.app = app # These attributes are used anyway, so it is ok to compute them here self.path = '/' + environ.get('PATH_INFO', '/').lstrip('/') self.method = environ.get('REQUEST_METHOD', 'GET').upper()
Example #6
Source File: basecontroller.py From conifer with Apache License 2.0 | 6 votes |
def __init__(self, *args, **kwargs): self.app = kwargs['app'] self.jinja_env = kwargs['jinja_env'] self.user_manager = kwargs['user_manager'] self.config = kwargs['config'] self.redis = kwargs['redis'] self.cork = kwargs['cork'] self.api = api_decorator self.app_host = os.environ.get('APP_HOST', '') self.content_host = os.environ.get('CONTENT_HOST', '') self.cache_template = self.config.get('cache_template') self.anon_disabled = get_bool(os.environ.get('ANON_DISABLED')) self.allow_beta_features_role = os.environ.get('ALLOW_BETA_FEATURES_ROLE', 'beta-archivist') self.init_routes()
Example #7
Source File: bottle3.py From pyFileFixity with MIT License | 6 votes |
def POST(self): """ The HTTP POST body parsed into a MultiDict. This supports urlencoded and multipart POST requests. Multipart is commonly used for file uploads and may result in some of the values beeing cgi.FieldStorage objects instead of strings. Multiple values per key are possible. See MultiDict for details. """ if self._POST is None: save_env = dict() # Build a save environment for cgi for key in ('REQUEST_METHOD', 'CONTENT_TYPE', 'CONTENT_LENGTH'): if key in self.environ: save_env[key] = self.environ[key] save_env['QUERY_STRING'] = '' # Without this, sys.argv is called! if TextIOWrapper: fb = TextIOWrapper(self.body, encoding='ISO-8859-1') else: fb = self.body data = cgi.FieldStorage(fp=fb, environ=save_env) self._POST = MultiDict() for item in data.list: self._POST[item.name] = item if item.filename else item.value return self._POST
Example #8
Source File: bottle3.py From pyFileFixity with MIT License | 6 votes |
def body(self): """ The HTTP request body as a seekable buffer object. This property returns a copy of the `wsgi.input` stream and should be used instead of `environ['wsgi.input']`. """ if self._body is None: maxread = max(0, self.content_length) stream = self.environ['wsgi.input'] self._body = BytesIO() if maxread < MEMFILE_MAX else TemporaryFile(mode='w+b') while maxread > 0: part = stream.read(min(maxread, MEMFILE_MAX)) if not part: #TODO: Wrong content_length. Error? Do nothing? break self._body.write(part) maxread -= len(part) self.environ['wsgi.input'] = self._body self._body.seek(0) return self._body
Example #9
Source File: basecontroller.py From conifer with Apache License 2.0 | 6 votes |
def jinja2_view(self, template_name, refresh_cookie=True): def decorator(view_func): @wraps(view_func) def wrapper(*args, **kwargs): resp = view_func(*args, **kwargs) if isinstance(resp, dict): ctx_params = request.environ.get('webrec.template_params') if ctx_params: resp.update(ctx_params) template = self.jinja_env.jinja_env.get_or_select_template(template_name) return template.render(**resp) else: return resp return wrapper return decorator
Example #10
Source File: bottle2.py From pyFileFixity with MIT License | 6 votes |
def body(self): """ The HTTP request body as a seekable buffer object. This property returns a copy of the `wsgi.input` stream and should be used instead of `environ['wsgi.input']`. """ if self._body is None: maxread = max(0, self.content_length) stream = self.environ['wsgi.input'] self._body = BytesIO() if maxread < MEMFILE_MAX else TemporaryFile(mode='w+b') while maxread > 0: part = stream.read(min(maxread, MEMFILE_MAX)) if not part: #TODO: Wrong content_length. Error? Do nothing? break self._body.write(part) maxread -= len(part) self.environ['wsgi.input'] = self._body self._body.seek(0) return self._body
Example #11
Source File: bottle2.py From pyFileFixity with MIT License | 6 votes |
def POST(self): """ The HTTP POST body parsed into a MultiDict. This supports urlencoded and multipart POST requests. Multipart is commonly used for file uploads and may result in some of the values beeing cgi.FieldStorage objects instead of strings. Multiple values per key are possible. See MultiDict for details. """ if self._POST is None: save_env = dict() # Build a save environment for cgi for key in ('REQUEST_METHOD', 'CONTENT_TYPE', 'CONTENT_LENGTH'): if key in self.environ: save_env[key] = self.environ[key] save_env['QUERY_STRING'] = '' # Without this, sys.argv is called! if TextIOWrapper: fb = TextIOWrapper(self.body, encoding='ISO-8859-1') else: fb = self.body data = cgi.FieldStorage(fp=fb, environ=save_env) self._POST = MultiDict() for item in data.list: self._POST[item.name] = item if item.filename else item.value return self._POST
Example #12
Source File: bottle2.py From pyFileFixity with MIT License | 6 votes |
def __call__(self, environ, start_response): """ The bottle WSGI-interface. """ try: request.bind(environ, self) response.bind(self) out = self.handle(request.path, request.method) out = self._cast(out, request, response) if response.status in (100, 101, 204, 304) or request.method == 'HEAD': out = [] # rfc2616 section 4.3 status = '%d %s' % (response.status, HTTP_CODES[response.status]) start_response(status, response.headerlist) return out except (KeyboardInterrupt, SystemExit, MemoryError): raise except Exception, e: if not self.catchall: raise err = '<h1>Critical error while processing request: %s</h1>' \ % environ.get('PATH_INFO', '/') if DEBUG: err += '<h2>Error:</h2>\n<pre>%s</pre>\n' % repr(e) err += '<h2>Traceback:</h2>\n<pre>%s</pre>\n' % format_exc(10) environ['wsgi.errors'].write(err) #TODO: wsgi.error should not get html start_response('500 INTERNAL SERVER ERROR', [('Content-Type', 'text/html')]) return [tob(err)]
Example #13
Source File: bottle2.py From pyFileFixity with MIT License | 6 votes |
def bind(self, environ, app=None): """ Bind a new WSGI enviroment and clear out all previously computed attributes. This is done automatically for the global `bottle.request` instance on every request. """ if isinstance(environ, Request): # Recycle already parsed content for key in self.__dict__: #TODO: Test this setattr(self, key, getattr(environ, key)) self.app = app return self._GET = self._POST = self._GETPOST = self._COOKIES = None self._body = self._header = None self.environ = environ self.app = app # These attributes are used anyway, so it is ok to compute them here self.path = '/' + environ.get('PATH_INFO', '/').lstrip('/') self.method = environ.get('REQUEST_METHOD', 'GET').upper()
Example #14
Source File: contentcontroller.py From conifer with Apache License 2.0 | 5 votes |
def __init__(self, *args, **kwargs): BaseController.__init__(self, *args, **kwargs) config = kwargs['config'] self.content_error_redirect = os.environ.get('CONTENT_ERROR_REDIRECT') config['csp-header'] = self.get_csp_header() self.browser_mgr = kwargs['browser_mgr'] RewriterApp.__init__(self, framed_replay=True, jinja_env=kwargs['jinja_env'], config=config) self.paths = config['url_templates'] self.cookie_tracker = CookieTracker(self.redis) self.record_host = os.environ['RECORD_HOST'] self.live_host = os.environ['WARCSERVER_HOST'] self.replay_host = os.environ.get('WARCSERVER_PROXY_HOST') if not self.replay_host: self.replay_host = self.live_host self.session_redirect_host = os.environ.get('SESSION_REDIRECT_HOST') self.session_share_origin = os.environ.get('SESSION_SHARE_ORIGIN', '') self.wam_loader = WAMLoader() self._init_client_archive_info() self.dyn_stats = DynStats(self.redis, config)
Example #15
Source File: main.py From bazarr with GNU General Public License v3.0 | 5 votes |
def edit_movieseditor(): authorize() ref = request.environ['HTTP_REFERER'] movies = request.forms.get('movies') movies = ast.literal_eval(str('[' + movies + ']')) lang = request.forms.getall('languages') hi = request.forms.get('hearing_impaired') forced = request.forms.get('forced') for movie in movies: if str(lang) != "[]" and str(lang) != "['']": if str(lang) == "['None']": lang = 'None' else: lang = str(lang) database.execute("UPDATE table_movies SET languages=? WHERE radarrId=?", (lang, movie)) if hi != '': database.execute("UPDATE table_movies SET hearing_impaired=? WHERE radarrId=?", (hi, movie)) if forced != '': database.execute("UPDATE table_movies SET forced=? WHERE radarrId=?", (forced, movie)) for movie in movies: list_missing_subtitles_movies(movie) redirect(ref)
Example #16
Source File: main.py From bazarr with GNU General Public License v3.0 | 5 votes |
def edit_serieseditor(): authorize() ref = request.environ['HTTP_REFERER'] series = request.forms.get('series') series = ast.literal_eval(str('[' + series + ']')) lang = request.forms.getall('languages') hi = request.forms.get('hearing_impaired') forced = request.forms.get('forced') for serie in series: if str(lang) != "[]" and str(lang) != "['']": if str(lang) == "['None']": lang = 'None' else: lang = str(lang) database.execute("UPDATE table_shows SET languages=? WHERE sonarrSeriesId=?", (lang,serie)) if hi != '': database.execute("UPDATE table_shows SET hearing_impaired=? WHERE sonarrSeriesId=?", (hi, serie)) if forced != '': database.execute("UPDATE table_shows SET forced=? WHERE sonarrSeriesId=?", (forced, serie)) for serie in series: list_missing_subtitles(no=serie) redirect(ref)
Example #17
Source File: main.py From bazarr with GNU General Public License v3.0 | 5 votes |
def edit_series(no): authorize() ref = request.environ['HTTP_REFERER'] lang = request.forms.getall('languages') if len(lang) > 0: pass else: lang = 'None' single_language = settings.general.getboolean('single_language') if single_language: if str(lang) == "['None']": lang = 'None' else: lang = str(lang) else: if str(lang) == "['']": lang = '[]' hi = request.forms.get('hearing_impaired') forced = request.forms.get('forced') if hi == "on": hi = "True" else: hi = "False" result = database.execute("UPDATE table_shows SET languages=?, hearing_impaired=?, forced=? WHERE " "sonarrSeriesId=?", (str(lang), hi, forced, no)) list_missing_subtitles(no=no) redirect(ref)
Example #18
Source File: maincontroller.py From conifer with Apache License 2.0 | 5 votes |
def init_routes(self): @self.bottle_app.route(['//<url:re:.*>']) def empty(url=''): self.redirect('/' + url) @self.bottle_app.route(['/<user>//<url:re:.*>']) def empty2(user, url=''): self.redirect('/' + user + '/' + url) @self.bottle_app.route(['/static/<path:path>', '/static_cors/<path:path>']) def static_files(path): res = static_file(path, root=self.static_root) if 'HTTP_ORIGIN' in request.environ: self.set_options_headers(None, None, res) return res @self.bottle_app.route('/_message') def flash_message(): message = request.query.getunicode('message', '') msg_type = request.query.getunicode('msg_type', '') self.flash_message(message, msg_type) return {} @self.bottle_app.route('/api/v1.yml') def get_api_spec_yaml(): response.content_type = 'text/yaml' return wr_api_spec.get_api_spec_yaml(self.access.is_superuser()) @self.bottle_app.route('/api/v1.json') def get_api_spec_json(): response.content_type = 'application/json' return json.dumps(wr_api_spec.get_api_spec_dict(self.access.is_superuser())) @self.bottle_app.route('/<:re:.*>', method='ANY') def fallthrough(): self._check_refer_redirect()
Example #19
Source File: browsermanager.py From conifer with Apache License 2.0 | 5 votes |
def get_session(self): return request.environ['webrec.session']
Example #20
Source File: usermanager.py From conifer with Apache License 2.0 | 5 votes |
def get_session(self): return request.environ['webrec.session']
Example #21
Source File: usermanager.py From conifer with Apache License 2.0 | 5 votes |
def __init__(self, redis, cork, config): self.redis = redis self.cork = cork self.config = config self.default_coll = config['default_coll'] self.temp_prefix = config['temp_prefix'] mailing_list = os.environ.get('MAILING_LIST', '').lower() self.mailing_list = mailing_list in ('true', '1', 'yes') self.default_list_endpoint = os.environ.get('MAILING_LIST_ENDPOINT', '') self.list_key = os.environ.get('MAILING_LIST_KEY', '') self.list_removal_endpoint = os.path.expandvars( os.environ.get('MAILING_LIST_REMOVAL', '')) self.payload = os.environ.get('MAILING_LIST_PAYLOAD', '') self.remove_on_delete = (os.environ.get('REMOVE_ON_DELETE', '') in ('true', '1', 'yes')) self.announce_list = os.environ.get('ANNOUNCE_MAILING_LIST_ENDPOINT', False) invites = expandvars(config.get('invites_enabled', 'true')).lower() self.invites_enabled = invites in ('true', '1', 'yes') try: self.redis.hsetnx('h:defaults', 'max_size', int(config['default_max_size'])) self.redis.hsetnx('h:defaults', 'max_anon_size', int(config['default_max_anon_size'])) except Exception as e: print('WARNING: Unable to init defaults: ' + str(e)) self.all_users = UserTable(self.redis, self._get_access) self.invites = RedisTable(self.redis, 'h:invites')
Example #22
Source File: contentcontroller.py From conifer with Apache License 2.0 | 5 votes |
def get_host_prefix(self, environ): if self.content_host and 'wsgiprox.proxy_host' not in environ: return environ['wsgi.url_scheme'] + '://' + self.content_host else: return super(ContentController, self).get_host_prefix(environ)
Example #23
Source File: usercontroller.py From conifer with Apache License 2.0 | 5 votes |
def __init__(self, *args, **kwargs): super(UserController, self).__init__(*args, **kwargs) config = kwargs['config'] self.default_user_desc = config['user_desc'] self.allow_external = get_bool(os.environ.get('ALLOW_EXTERNAL', False))
Example #24
Source File: contentcontroller.py From conifer with Apache License 2.0 | 5 votes |
def handle_custom_response(self, environ, wb_url, full_prefix, host_prefix, kwargs): # don't attempt to check if url is valid by accessing content kwargs['no_timegate_check'] = True # test if request specifies a containerized browser if wb_url.mod.startswith('$br:'): return self.handle_browser_embed(wb_url, kwargs) return RewriterApp.handle_custom_response(self, environ, wb_url, full_prefix, host_prefix, kwargs)
Example #25
Source File: contentcontroller.py From conifer with Apache License 2.0 | 5 votes |
def do_put_record(self): reqid = request.query.getunicode('reqid') info = self.browser_mgr.init_remote_browser_session(reqid=reqid) if not info: return self._raise_error(400, 'invalid_connection_source') user = info['the_user'] collection = info['collection'] recording = info['recording'] kwargs = dict(user=user.name, coll=collection.my_id, rec=recording.my_id, type='put_record') url = request.query.getunicode('target_uri') params = {'url': url} upstream_url = self.get_upstream_url('', kwargs, params) headers = {'Content-Type': request.environ.get('CONTENT_TYPE', 'text/plain')} r = requests.put(upstream_url, data=request.body, headers=headers, ) try: res = r.json() if res['success'] != 'true': print(res) return {'error_message': 'put_record_failed'} warc_date = res.get('WARC-Date') except Exception as e: print(e) return {'error_message': 'put_record_failed'} return res
Example #26
Source File: contentcontroller.py From conifer with Apache License 2.0 | 5 votes |
def redir_set_session(self): full_path = request.environ['SCRIPT_NAME'] + request.environ['PATH_INFO'] full_path = self.add_query(full_path) self.redir_host(self.session_redirect_host, '/_set_session?path=' + quote(full_path))
Example #27
Source File: contentcontroller.py From conifer with Apache License 2.0 | 5 votes |
def check_if_content(self, wb_url, environ, is_top_frame): if not wb_url.is_replay(): return if not self.content_host: return if is_top_frame: if self.is_content_request(): self.redir_host(self.app_host) else: if not self.is_content_request(): self.redir_host(self.content_host)
Example #28
Source File: contentcontroller.py From conifer with Apache License 2.0 | 5 votes |
def _context_massage(self, wb_url): # reset HTTP_COOKIE to guarded request_cookie for LiveRewriter if 'webrec.request_cookie' in request.environ: request.environ['HTTP_COOKIE'] = request.environ['webrec.request_cookie'] try: del request.environ['HTTP_X_PUSH_STATE_REQUEST'] except: pass #TODO: generalize if wb_url.endswith('&spf=navigate') and wb_url.startswith('mp_/https://www.youtube.com'): wb_url = wb_url.replace('&spf=navigate', '') return wb_url
Example #29
Source File: contentcontroller.py From conifer with Apache License 2.0 | 5 votes |
def _full_url(self, url=''): request_uri = request.environ.get('REQUEST_URI') script_name = request.environ.get('SCRIPT_NAME', '') + '/' if request_uri and script_name and request_uri.startswith(script_name): url = request_uri[len(script_name):] else: if not url: url = environ.request.environ['SCRIPT_NAME'] + environ.request.environ['PATH_INFO'] url = self.add_query(url) return url
Example #30
Source File: contentcontroller.py From conifer with Apache License 2.0 | 5 votes |
def get_top_frame_params(self, wb_url, kwargs): type = kwargs['type'] top_prefix = super(ContentController, self).get_host_prefix(request.environ) top_prefix += self.get_rel_prefix(request.environ) if type == 'live': return {'curr_mode': type, 'is_embed': kwargs.get('is_embed'), 'is_display': kwargs.get('is_display'), 'top_prefix': top_prefix} # refresh cookie expiration, # disable until can guarantee cookie is not changed! #self.get_session().update_expires() info = self.get_content_inject_info(kwargs['the_user'], kwargs['collection'], kwargs['recording']) return {'info': info, 'curr_mode': type, 'user': kwargs['user'], 'coll': kwargs['coll'], 'coll_name': kwargs['coll_name'], 'coll_title': info.get('coll_title', ''), 'rec': kwargs['rec'], 'rec_name': kwargs['rec_name'], 'rec_title': info.get('rec_title', ''), 'is_embed': kwargs.get('is_embed'), 'is_display': kwargs.get('is_display'), 'top_prefix': top_prefix, 'sources': kwargs.get('sources'), 'inv_sources': kwargs.get('inv_sources'), }