def _default(self, *args, **kw): """The default controller method. This method is called whenever a request reaches this controller. It prepares the WSGI environment and delegates the request to the WSGI app. """ body_is_seekable = tg.config.get('make_body_seekable', False) if not body_is_seekable: raise RuntimeError('Mounting nested WSGI apps requires make_body_seekable=True option') # Push into SCRIPT_NAME the path components that have been consumed, request = tg.request._current_obj() new_req = request.copy() to_pop = len(new_req.path_info.strip('/').split('/')) - len(args) for i in range(to_pop): new_req.path_info_pop() if not new_req.path_info: #pragma: no cover # This should not happen redirect(request.path_info + '/') new_req.body_file.seek(0) return self.delegate(new_req)
def _default(self, *args, **kw): """The default controller method. This method is called whenever a request reaches this controller. It prepares the WSGI environment and delegates the request to the WSGI app. """ body_is_seekable = tg.config.get('make_body_seekable', False) if not body_is_seekable: raise RuntimeError( 'Mounting nested WSGI apps requires make_body_seekable=True option' ) # Push into SCRIPT_NAME the path components that have been consumed, request = tg.request._current_obj() new_req = request.copy() to_pop = len(new_req.path_info.strip('/').split('/')) - len(args) for i in range(to_pop): new_req.path_info_pop() if not new_req.path_info: #pragma: no cover # This should not happen redirect(request.path_info + '/') new_req.body_file.seek(0) return self.delegate(new_req)
def _default(self, *args, **kw): """The default controller method. This method is called whenever a request reaches this controller. It prepares the WSGI environment and delegates the request to the WSGI app. """ # Push into SCRIPT_NAME the path components that have been consumed, request = pylons.request._current_obj() new_req = request.copy() to_pop = len(new_req.path_info.strip('/').split('/')) - len(args) for i in xrange(to_pop): new_req.path_info_pop() if not new_req.path_info: # Append trailing slash and redirect redirect(request.path_info + '/') new_req.body_file.seek(0) return self.delegate(new_req.environ, request.start_response)
def with_trailing_slash(remainder, params): """This decorator allows you to ensure that the URL ends in "/". The decorator accomplish this by redirecting to the correct URL. :Usage: You use this decorator as follows:: class MyController(object): @with_trailing_slash @expose() def sample(self, *args): return "found sample" In the above example http://localhost:8080/sample redirects to http://localhost:8080/sample/ In addition, the URL http://localhost:8080/sample/1 redirects to http://localhost:8080/sample/1/ """ req = request._current_obj() if (req.method == 'GET' and not(req.path.endswith('/')) and not(req._response_type) and len(req.params)==0): redirect(request.url+'/', redirect_with=HTTPMovedPermanently)
def https(remainder, params): """Ensure that the decorated method is always called with https.""" if request.scheme.lower() == 'https': return if request.method.upper() == 'GET': redirect('https' + request.url[len(request.scheme):]) raise HTTPMethodNotAllowed(headers=dict(Allow='GET'))
def index(self): redirect("home/list")