def save_html(self, data, suffix=''): """ Saves the 'content' attribute of a form POST request for display as HTML as part of a webpage """ self.authored_html = data.POST['content'] response = HTTPTemporaryRedirect() response.location = data.referrer return response
def __call__(self, environ, start_response): req = Request(environ) val = req.cookies.get(self.from_key) if val: log.info("Renaming %s=%s to %s on client IP %s", self.from_key, val, self.to_key, req.remote_addr) resp = HTTPTemporaryRedirect(location=req.url) resp.delete_cookie(self.from_key) resp.set_cookie(self.to_key, val, **self.cookie_kwargs) else: resp = req.get_response(self.app) return resp(environ, start_response)
def get_concrete_response(self): try: result = self.get_data_response() except NoViewMethod as exc: return HTTPUnsupportedMediaType( body=render_error_page(415, exc), content_type="text/html" ) except InvalidInput as exc: ## if the model raises a InvalidInput, retry the request as ## a GET request for the same program, and set the code to 400. request = make_duplicate_request(self.request) request.method = 'GET' c = HTTPController(request, self.manifest, self.model_mock, errors=exc) response = c.get_response() response.status_int = 400 return response except NotAuthorized as exc: return HTTPForbidden( body=render_error_page(403, exc), content_type="text/html" ) except (DataNotFound, ProgramNotFound) as exc: return HTTPNotFound( body=render_error_page(404, exc), content_type="text/html" ) if type(result['body']) == Redirection: response = HTTPTemporaryRedirect(location=result['body'].path) else: lazy = None body = result['body'] if type(body) == tuple: lazy = body body = '' if hasattr(body, 'read'): body = body.read() response = Response( status=200, body=body, content_type=result['mimetype'], ) response.lazy_data = lazy return response
def logout(environ, start_response): session = environ[session_key].session if session is not None: if 'user' in session: del session['user'] response = HTTPTemporaryRedirect(location='/') return response(environ, start_response)
def _wrapper(context, REQUEST): """ admin required decorator """ is_admin = users.is_current_user_admin() if is_admin: return func(context, REQUEST) else: return HTTPTemporaryRedirect( location=users.create_login_url(REQUEST.url))
def __call__(self, environ, start_response): req = Request(environ) to_delete = set() for cookie in req.cookies: if ((self.whitelist and (cookie not in self.whitelist)) or (self.blacklist and (cookie in self.blacklist))): to_delete.add(cookie) if to_delete: resp = HTTPTemporaryRedirect(location=req.url) for cookie in to_delete: resp.delete_cookie(cookie) else: resp = req.get_response(self.app) return resp(environ, start_response)
def _intercept(self, context): """Called after dispatch has returned and the response populated, to intercept and redirect. Optionally assigned to the correct callback name (`after`) only if interception is enabled. """ if context.response.status_int not in self._intercept: return # Exit early if our condition is not met. if not self._internal: context.response = HTTPTemporaryRedirect(location=self._handler) return # External redirects are easy. # Internal redirection is a touch more difficult. request = context.request.copy_get( ) # Preserve the user's original request data, such as cookies. request.path = self._handler # Point the internal request at the authentication endpoint. request.environ[ 'HTTP_REFERER'] = context.request.path_qs # Inform authentication where the user was. response = request.send(context.app) # Perform the internal redirect. response.status_int = context.response.status_int # Match the status to ensure browser caching not applied. context.response = response # Override the current (failed) response.
def f(environ, start_response): return HTTPTemporaryRedirect(location=location)(environ, start_response)
def main(app, request): # return Response('this is man page') raise HTTPTemporaryRedirect( location='/r2/hello/jkzhao/26') # 302临时跳转,webob内部实现了
def no_auth(request, token): """No authentication, just pass along""" callback = token.get_callback_url() return HTTPTemporaryRedirect(location=callback), None
def redirect(url, permanent=False): if permanent: return HTTPMovedPermanently(location=url) return HTTPTemporaryRedirect(location=url)
def main(application, request): #if application.options.get('debug'): # for k, v in request.headers.items(): # print('{} => {}'.format(k, v)) #return Response("this is a man page") raise HTTPTemporaryRedirect(location='/r2/hello/xxx/111')