Python cherrypy.HTTPRedirect() Examples
The following are 30
code examples of cherrypy.HTTPRedirect().
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
cherrypy
, or try the search function
.
Example #1
Source File: cptools.py From cherrypy with BSD 3-Clause "New" or "Revised" License | 7 votes |
def do_login(self, username, password, from_page='..', **kwargs): """Login. May raise redirect, or return True if request handled.""" response = cherrypy.serving.response error_msg = self.check_username_and_password(username, password) if error_msg: body = self.login_screen(from_page, username, error_msg) response.body = body if 'Content-Length' in response.headers: # Delete Content-Length header so finalize() recalcs it. del response.headers['Content-Length'] return True else: cherrypy.serving.request.login = username cherrypy.session[self.session_key] = username self.on_login(username) raise cherrypy.HTTPRedirect(from_page or '/')
Example #2
Source File: cptools.py From Tautulli with GNU General Public License v3.0 | 6 votes |
def trailing_slash(missing=True, extra=False, status=None, debug=False): """Redirect if path_info has (missing|extra) trailing slash.""" request = cherrypy.serving.request pi = request.path_info if debug: cherrypy.log('is_index: %r, missing: %r, extra: %r, path_info: %r' % (request.is_index, missing, extra, pi), 'TOOLS.TRAILING_SLASH') if request.is_index is True: if missing: if not pi.endswith('/'): new_url = cherrypy.url(pi + '/', request.query_string) raise cherrypy.HTTPRedirect(new_url, status=status or 301) elif request.is_index is False: if extra: # If pi == '/', don't redirect to ''! if pi.endswith('/') and pi != '/': new_url = cherrypy.url(pi[:-1], request.query_string) raise cherrypy.HTTPRedirect(new_url, status=status or 301)
Example #3
Source File: cprp.py From JWTConnect-Python-OidcRP with Apache License 2.0 | 6 votes |
def index(self, uid='', iss=''): link = '' if iss: link = iss elif uid: pass else: fname = os.path.join(self.html_home, 'opbyuid.html') return as_bytes(open(fname, 'r').read()) if link or uid: if uid: args = {'user_id': uid} else: args = {} try: result = self.rph.begin(link, **args) except Exception as err: raise cherrypy.HTTPError(message='{}'.format(err)) else: raise cherrypy.HTTPRedirect(result['url'])
Example #4
Source File: auth_web.py From AlexaPiDEPRECATED with MIT License | 6 votes |
def index(self): scope="alexa_all" sd = json.dumps({ "alexa:all": { "productID": ProductID, "productInstanceAttributes": { "deviceSerialNumber": "001" } } }) url = "https://www.amazon.com/ap/oa" callback = cherrypy.url() + "code" payload = {"client_id" : Client_ID, "scope" : "alexa:all", "scope_data" : sd, "response_type" : "code", "redirect_uri" : callback } req = requests.Request('GET', url, params=payload) p = req.prepare() raise cherrypy.HTTPRedirect(p.url)
Example #5
Source File: auth_web.py From AlexaChipDEPRECATED with MIT License | 6 votes |
def index(self): scope="alexa_all" sd = json.dumps({ "alexa:all": { "productID": ProductID, "productInstanceAttributes": { "deviceSerialNumber": "001" } } }) url = "https://www.amazon.com/ap/oa" callback = cherrypy.url() + "code" payload = {"client_id" : Client_ID, "scope" : "alexa:all", "scope_data" : sd, "response_type" : "code", "redirect_uri" : callback } req = requests.Request('GET', url, params=payload) p = req.prepare() raise cherrypy.HTTPRedirect(p.url)
Example #6
Source File: cptools.py From moviegrabber with GNU General Public License v3.0 | 6 votes |
def do_login(self, username, password, from_page='..', **kwargs): """Login. May raise redirect, or return True if request handled.""" response = cherrypy.serving.response error_msg = self.check_username_and_password(username, password) if error_msg: body = self.login_screen(from_page, username, error_msg) response.body = body if "Content-Length" in response.headers: # Delete Content-Length header so finalize() recalcs it. del response.headers["Content-Length"] return True else: cherrypy.serving.request.login = username cherrypy.session[self.session_key] = username self.on_login(username) raise cherrypy.HTTPRedirect(from_page or "/")
Example #7
Source File: test_etags.py From cherrypy with BSD 3-Clause "New" or "Revised" License | 6 votes |
def setup_server(): class Root: @cherrypy.expose def resource(self): return 'Oh wah ta goo Siam.' @cherrypy.expose def fail(self, code): code = int(code) if 300 <= code <= 399: raise cherrypy.HTTPRedirect([], code) else: raise cherrypy.HTTPError(code) @cherrypy.expose # In Python 3, tools.encode is on by default @cherrypy.config(**{'tools.encode.on': True}) def unicoded(self): return ntou('I am a \u1ee4nicode string.', 'escape') conf = {'/': {'tools.etags.on': True, 'tools.etags.autotags': True, }} cherrypy.tree.mount(Root(), config=conf)
Example #8
Source File: cptools.py From moviegrabber with GNU General Public License v3.0 | 6 votes |
def trailing_slash(missing=True, extra=False, status=None, debug=False): """Redirect if path_info has (missing|extra) trailing slash.""" request = cherrypy.serving.request pi = request.path_info if debug: cherrypy.log('is_index: %r, missing: %r, extra: %r, path_info: %r' % (request.is_index, missing, extra, pi), 'TOOLS.TRAILING_SLASH') if request.is_index is True: if missing: if not pi.endswith('/'): new_url = cherrypy.url(pi + '/', request.query_string) raise cherrypy.HTTPRedirect(new_url, status=status or 301) elif request.is_index is False: if extra: # If pi == '/', don't redirect to ''! if pi.endswith('/') and pi != '/': new_url = cherrypy.url(pi[:-1], request.query_string) raise cherrypy.HTTPRedirect(new_url, status=status or 301)
Example #9
Source File: test_etags.py From moviegrabber with GNU General Public License v3.0 | 6 votes |
def setup_server(): class Root: def resource(self): return "Oh wah ta goo Siam." resource.exposed = True def fail(self, code): code = int(code) if 300 <= code <= 399: raise cherrypy.HTTPRedirect([], code) else: raise cherrypy.HTTPError(code) fail.exposed = True def unicoded(self): return ntou('I am a \u1ee4nicode string.', 'escape') unicoded.exposed = True # In Python 3, tools.encode is on by default unicoded._cp_config = {'tools.encode.on': True} conf = {'/': {'tools.etags.on': True, 'tools.etags.autotags': True, }} cherrypy.tree.mount(Root(), config=conf)
Example #10
Source File: _cprequest.py From cherrypy with BSD 3-Clause "New" or "Revised" License | 6 votes |
def respond(self, path_info): """Generate a response for the resource at self.path_info. (Core)""" try: try: try: self._do_respond(path_info) except (cherrypy.HTTPRedirect, cherrypy.HTTPError): inst = sys.exc_info()[1] inst.set_response() self.stage = 'before_finalize (HTTPError)' self.hooks.run('before_finalize') cherrypy.serving.response.finalize() finally: self.stage = 'on_end_resource' self.hooks.run('on_end_resource') except self.throws: raise except Exception: if self.throw_errors: raise self.handle_error()
Example #11
Source File: _cprequest.py From bazarr with GNU General Public License v3.0 | 6 votes |
def run(self, point): """Execute all registered Hooks (callbacks) for the given point.""" exc = None hooks = self[point] hooks.sort() for hook in hooks: # Some hooks are guaranteed to run even if others at # the same hookpoint fail. We will still log the failure, # but proceed on to the next hook. The only way # to stop all processing from one of these hooks is # to raise SystemExit and stop the whole server. if exc is None or hook.failsafe: try: hook() except (KeyboardInterrupt, SystemExit): raise except (cherrypy.HTTPError, cherrypy.HTTPRedirect, cherrypy.InternalRedirect): exc = sys.exc_info()[1] except: exc = sys.exc_info()[1] cherrypy.log(traceback=True, severity=40) if exc: raise exc
Example #12
Source File: cptools.py From bazarr with GNU General Public License v3.0 | 6 votes |
def trailing_slash(missing=True, extra=False, status=None, debug=False): """Redirect if path_info has (missing|extra) trailing slash.""" request = cherrypy.serving.request pi = request.path_info if debug: cherrypy.log('is_index: %r, missing: %r, extra: %r, path_info: %r' % (request.is_index, missing, extra, pi), 'TOOLS.TRAILING_SLASH') if request.is_index is True: if missing: if not pi.endswith('/'): new_url = cherrypy.url(pi + '/', request.query_string) raise cherrypy.HTTPRedirect(new_url, status=status or 301) elif request.is_index is False: if extra: # If pi == '/', don't redirect to ''! if pi.endswith('/') and pi != '/': new_url = cherrypy.url(pi[:-1], request.query_string) raise cherrypy.HTTPRedirect(new_url, status=status or 301)
Example #13
Source File: _cprequest.py From moviegrabber with GNU General Public License v3.0 | 6 votes |
def run(self, point): """Execute all registered Hooks (callbacks) for the given point.""" exc = None hooks = self[point] hooks.sort() for hook in hooks: # Some hooks are guaranteed to run even if others at # the same hookpoint fail. We will still log the failure, # but proceed on to the next hook. The only way # to stop all processing from one of these hooks is # to raise SystemExit and stop the whole server. if exc is None or hook.failsafe: try: hook() except (KeyboardInterrupt, SystemExit): raise except (cherrypy.HTTPError, cherrypy.HTTPRedirect, cherrypy.InternalRedirect): exc = sys.exc_info()[1] except: exc = sys.exc_info()[1] cherrypy.log(traceback=True, severity=40) if exc: raise exc
Example #14
Source File: cptools.py From cherrypy with BSD 3-Clause "New" or "Revised" License | 6 votes |
def trailing_slash(missing=True, extra=False, status=None, debug=False): """Redirect if path_info has (missing|extra) trailing slash.""" request = cherrypy.serving.request pi = request.path_info if debug: cherrypy.log('is_index: %r, missing: %r, extra: %r, path_info: %r' % (request.is_index, missing, extra, pi), 'TOOLS.TRAILING_SLASH') if request.is_index is True: if missing: if not pi.endswith('/'): new_url = cherrypy.url(pi + '/', request.query_string) raise cherrypy.HTTPRedirect(new_url, status=status or 301) elif request.is_index is False: if extra: # If pi == '/', don't redirect to ''! if pi.endswith('/') and pi != '/': new_url = cherrypy.url(pi[:-1], request.query_string) raise cherrypy.HTTPRedirect(new_url, status=status or 301)
Example #15
Source File: cptools.py From bazarr with GNU General Public License v3.0 | 6 votes |
def do_login(self, username, password, from_page='..', **kwargs): """Login. May raise redirect, or return True if request handled.""" response = cherrypy.serving.response error_msg = self.check_username_and_password(username, password) if error_msg: body = self.login_screen(from_page, username, error_msg) response.body = body if 'Content-Length' in response.headers: # Delete Content-Length header so finalize() recalcs it. del response.headers['Content-Length'] return True else: cherrypy.serving.request.login = username cherrypy.session[self.session_key] = username self.on_login(username) raise cherrypy.HTTPRedirect(from_page or '/')
Example #16
Source File: test_etags.py From bazarr with GNU General Public License v3.0 | 6 votes |
def setup_server(): class Root: @cherrypy.expose def resource(self): return 'Oh wah ta goo Siam.' @cherrypy.expose def fail(self, code): code = int(code) if 300 <= code <= 399: raise cherrypy.HTTPRedirect([], code) else: raise cherrypy.HTTPError(code) @cherrypy.expose # In Python 3, tools.encode is on by default @cherrypy.config(**{'tools.encode.on': True}) def unicoded(self): return ntou('I am a \u1ee4nicode string.', 'escape') conf = {'/': {'tools.etags.on': True, 'tools.etags.autotags': True, }} cherrypy.tree.mount(Root(), config=conf)
Example #17
Source File: auth_web.py From AlexaPi with MIT License | 6 votes |
def index(self): scope="alexa_all" sd = json.dumps({ "alexa:all": { "productID": ProductID, "productInstanceAttributes": { "deviceSerialNumber": "001" } } }) url = "https://www.amazon.com/ap/oa" callback = cherrypy.url() + "code" payload = {"client_id" : Client_ID, "scope" : "alexa:all", "scope_data" : sd, "response_type" : "code", "redirect_uri" : callback } req = requests.Request('GET', url, params=payload) p = req.prepare() raise cherrypy.HTTPRedirect(p.url)
Example #18
Source File: authorization.py From python-alexa-voice-service with MIT License | 6 votes |
def index(self): sd = json.dumps({ "alexa:all": { "productID": self.config['ProductID'], "productInstanceAttributes": { "deviceSerialNumber": "123456" } } }) callback = cherrypy.url() + "code" payload = { "client_id": self.config['Client_ID'], "scope": "alexa:all", "scope_data": sd, "response_type": "code", "redirect_uri": callback } req = requests.Request('GET', "https://www.amazon.com/ap/oa", params=payload) p = req.prepare() raise cherrypy.HTTPRedirect(p.url)
Example #19
Source File: webauth.py From Tautulli with GNU General Public License v3.0 | 6 votes |
def logout(self, redirect_uri='', *args, **kwargs): self.check_auth_enabled() payload = check_jwt_token() if payload: self.on_logout(payload['user'], payload['user_group']) jwt_cookie = str(JWT_COOKIE_NAME + plexpy.CONFIG.PMS_UUID) cherrypy.response.cookie[jwt_cookie] = '' cherrypy.response.cookie[jwt_cookie]['expires'] = 0 cherrypy.response.cookie[jwt_cookie]['path'] = plexpy.HTTP_ROOT.rstrip('/') or '/' if plexpy.HTTP_ROOT != '/': # Also expire the JWT on the root path cherrypy.response.headers['Set-Cookie'] = jwt_cookie + '=""; expires=Thu, 01 Jan 1970 12:00:00 GMT; path=/' cherrypy.request.login = None if redirect_uri: redirect_uri = '?redirect_uri=' + redirect_uri raise cherrypy.HTTPRedirect(plexpy.HTTP_ROOT + "auth/login" + redirect_uri)
Example #20
Source File: cptools.py From opsbro with MIT License | 6 votes |
def do_login(self, username, password, from_page='..', **kwargs): """Login. May raise redirect, or return True if request handled.""" response = cherrypy.serving.response error_msg = self.check_username_and_password(username, password) if error_msg: body = self.login_screen(from_page, username, error_msg) response.body = body if "Content-Length" in response.headers: # Delete Content-Length header so finalize() recalcs it. del response.headers["Content-Length"] return True else: cherrypy.serving.request.login = username cherrypy.session[self.session_key] = username self.on_login(username) raise cherrypy.HTTPRedirect(from_page or "/")
Example #21
Source File: cptools.py From opsbro with MIT License | 6 votes |
def trailing_slash(missing=True, extra=False, status=None, debug=False): """Redirect if path_info has (missing|extra) trailing slash.""" request = cherrypy.serving.request pi = request.path_info if debug: cherrypy.log('is_index: %r, missing: %r, extra: %r, path_info: %r' % (request.is_index, missing, extra, pi), 'TOOLS.TRAILING_SLASH') if request.is_index is True: if missing: if not pi.endswith('/'): new_url = cherrypy.url(pi + '/', request.query_string) raise cherrypy.HTTPRedirect(new_url, status=status or 301) elif request.is_index is False: if extra: # If pi == '/', don't redirect to ''! if pi.endswith('/') and pi != '/': new_url = cherrypy.url(pi[:-1], request.query_string) raise cherrypy.HTTPRedirect(new_url, status=status or 301)
Example #22
Source File: webauth.py From Tautulli with GNU General Public License v3.0 | 6 votes |
def check_auth(*args, **kwargs): """A tool that looks in config for 'auth.require'. If found and it is not None, a login is required and the entry is evaluated as a list of conditions that the user must fulfill""" conditions = cherrypy.request.config.get('auth.require', None) if conditions is not None: payload = check_jwt_token() if payload: cherrypy.request.login = payload for condition in conditions: # A condition is just a callable that returns true or false if not condition(): raise cherrypy.HTTPRedirect(plexpy.HTTP_ROOT) else: redirect_uri = cherrypy.request.wsgi_environ['REQUEST_URI'] if redirect_uri: redirect_uri = '?redirect_uri=' + quote(redirect_uri) raise cherrypy.HTTPRedirect(plexpy.HTTP_ROOT + "auth/logout" + redirect_uri)
Example #23
Source File: test_etags.py From Tautulli with GNU General Public License v3.0 | 6 votes |
def setup_server(): class Root: @cherrypy.expose def resource(self): return 'Oh wah ta goo Siam.' @cherrypy.expose def fail(self, code): code = int(code) if 300 <= code <= 399: raise cherrypy.HTTPRedirect([], code) else: raise cherrypy.HTTPError(code) @cherrypy.expose # In Python 3, tools.encode is on by default @cherrypy.config(**{'tools.encode.on': True}) def unicoded(self): return ntou('I am a \u1ee4nicode string.', 'escape') conf = {'/': {'tools.etags.on': True, 'tools.etags.autotags': True, }} cherrypy.tree.mount(Root(), config=conf)
Example #24
Source File: _cprequest.py From opsbro with MIT License | 6 votes |
def run(self, point): """Execute all registered Hooks (callbacks) for the given point.""" exc = None hooks = self[point] hooks.sort() for hook in hooks: # Some hooks are guaranteed to run even if others at # the same hookpoint fail. We will still log the failure, # but proceed on to the next hook. The only way # to stop all processing from one of these hooks is # to raise SystemExit and stop the whole server. if exc is None or hook.failsafe: try: hook() except (KeyboardInterrupt, SystemExit): raise except (cherrypy.HTTPError, cherrypy.HTTPRedirect, cherrypy.InternalRedirect): exc = sys.exc_info()[1] except: exc = sys.exc_info()[1] cherrypy.log(traceback=True, severity=40) if exc: raise exc
Example #25
Source File: cptools.py From Tautulli with GNU General Public License v3.0 | 6 votes |
def do_login(self, username, password, from_page='..', **kwargs): """Login. May raise redirect, or return True if request handled.""" response = cherrypy.serving.response error_msg = self.check_username_and_password(username, password) if error_msg: body = self.login_screen(from_page, username, error_msg) response.body = body if 'Content-Length' in response.headers: # Delete Content-Length header so finalize() recalcs it. del response.headers['Content-Length'] return True else: cherrypy.serving.request.login = username cherrypy.session[self.session_key] = username self.on_login(username) raise cherrypy.HTTPRedirect(from_page or '/')
Example #26
Source File: _cprequest.py From Tautulli with GNU General Public License v3.0 | 6 votes |
def respond(self, path_info): """Generate a response for the resource at self.path_info. (Core)""" try: try: try: self._do_respond(path_info) except (cherrypy.HTTPRedirect, cherrypy.HTTPError): inst = sys.exc_info()[1] inst.set_response() self.stage = 'before_finalize (HTTPError)' self.hooks.run('before_finalize') cherrypy.serving.response.finalize() finally: self.stage = 'on_end_resource' self.hooks.run('on_end_resource') except self.throws: raise except Exception: if self.throw_errors: raise self.handle_error()
Example #27
Source File: _cprequest.py From Tautulli with GNU General Public License v3.0 | 6 votes |
def run(self, point): """Execute all registered Hooks (callbacks) for the given point.""" exc = None hooks = self[point] hooks.sort() for hook in hooks: # Some hooks are guaranteed to run even if others at # the same hookpoint fail. We will still log the failure, # but proceed on to the next hook. The only way # to stop all processing from one of these hooks is # to raise SystemExit and stop the whole server. if exc is None or hook.failsafe: try: hook() except (KeyboardInterrupt, SystemExit): raise except (cherrypy.HTTPError, cherrypy.HTTPRedirect, cherrypy.InternalRedirect): exc = sys.exc_info()[1] except Exception: exc = sys.exc_info()[1] cherrypy.log(traceback=True, severity=40) if exc: raise exc
Example #28
Source File: assetstore.py From cumulus with Apache License 2.0 | 6 votes |
def downloadFile(self, file, offset=0, headers=True, endByte=None, **kwargs): if 'path' not in file: raise Exception('Missing path property') full_path = file['path'] url = '%s/file/%s/%s?view=read' % (self.newt_base_url, self.machine, full_path) if headers: raise cherrypy.HTTPRedirect(url) else: session_id = parse('newt.sessionId').find(getCurrentUser()) if len(session_id) > 0: session_id = session_id[0].value if session_id is None: raise GirderException('Missing NEWT session id') def stream(): cookies = dict(newt_sessionid=session_id) r = requests.get(url, cookies=cookies, stream=True) for chunk in r.iter_content(chunk_size=BUF_LEN): if chunk: yield chunk return stream
Example #29
Source File: cptools.py From Tautulli with GNU General Public License v3.0 | 5 votes |
def do_logout(self, from_page='..', **kwargs): """Logout. May raise redirect, or return True if request handled.""" sess = cherrypy.session username = sess.get(self.session_key) sess[self.session_key] = None if username: cherrypy.serving.request.login = None self.on_logout(username) raise cherrypy.HTTPRedirect(from_page)
Example #30
Source File: cptools.py From bazarr with GNU General Public License v3.0 | 5 votes |
def validate_since(): """Validate the current Last-Modified against If-Modified-Since headers. If no code has set the Last-Modified response header, then no validation will be performed. """ response = cherrypy.serving.response lastmod = response.headers.get('Last-Modified') if lastmod: status, reason, msg = _httputil.valid_status(response.status) request = cherrypy.serving.request since = request.headers.get('If-Unmodified-Since') if since and since != lastmod: if (status >= 200 and status <= 299) or status == 412: raise cherrypy.HTTPError(412) since = request.headers.get('If-Modified-Since') if since and since == lastmod: if (status >= 200 and status <= 299) or status == 304: if request.method in ('GET', 'HEAD'): raise cherrypy.HTTPRedirect([], 304) else: raise cherrypy.HTTPError(412) # Tool code #