Python webapp2.RedirectHandler() Examples

The following are 7 code examples of webapp2.RedirectHandler(). 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 webapp2 , or try the search function .
Example #1
Source File: main_test.py    From gae-secure-scaffold-python with Apache License 2.0 6 votes vote down vote up
def _VerifyInheritance(self, routes_list, base_class):
    """Checks that the handlers of the given routes inherit from base_class."""
    router = webapp2.Router(routes_list)
    routes = router.match_routes + router.build_routes.values()
    inheritance_errors = ''
    for route in routes:
      if issubclass(route.__class__, webapp2_extras.routes.MultiRoute):
        self._VerifyInheritance(list(route.get_routes()), base_class)
        continue

      if issubclass(route.handler, webapp2.RedirectHandler):
        continue

      if not issubclass(route.handler, base_class):
        inheritance_errors += '* %s does not inherit from %s.\n' % (
            route.handler.__name__, base_class.__name__)

    return inheritance_errors 
Example #2
Source File: main_test.py    From gae-secure-scaffold-python with Apache License 2.0 6 votes vote down vote up
def testStrictHandlerMethodRouting(self):
    """Checks that handler functions properly limit applicable HTTP methods."""
    router = webapp2.Router(main._USER_ROUTES + main._AJAX_ROUTES +
                            main._ADMIN_ROUTES + main._ADMIN_AJAX_ROUTES)
    routes = router.match_routes + router.build_routes.values()
    failed_routes = []
    while routes:
      route = routes.pop()
      if issubclass(route.__class__, webapp2_extras.routes.MultiRoute):
        routes += list(route.get_routes())
        continue

      if issubclass(route.handler, webapp2.RedirectHandler):
        continue

      if route.handler_method and not route.methods:
        failed_routes.append('%s (%s)' % (route.template,
                                          route.handler.__name__))

    if failed_routes:
      self.fail('Some handlers specify a handler_method but are missing a '
                'methods" attribute and may be vulnerable to XSRF via GET '
                'requests:\n * ' + '\n * '.join(failed_routes)) 
Example #3
Source File: admin_server.py    From browserscope with Apache License 2.0 5 votes vote down vote up
def __init__(self, dispatch, configuration):
    """Initializer for AdminApplication.

    Args:
      dispatch: A dispatcher.Dispatcher instance used to route requests and
          provide state about running servers.
      configuration: An application_configuration.ApplicationConfiguration
          instance containing the configuration for the application.
    """
    super(AdminApplication, self).__init__(
        [('/datastore', datastore_viewer.DatastoreRequestHandler),
         ('/datastore/edit/(.*)', datastore_viewer.DatastoreEditRequestHandler),
         ('/datastore/edit', datastore_viewer.DatastoreEditRequestHandler),
         ('/datastore-indexes',
          datastore_indexes_viewer.DatastoreIndexesViewer),
         ('/datastore-stats', datastore_stats_handler.DatastoreStatsHandler),
         ('/console', console.ConsoleRequestHandler),
         ('/console/restart/(.+)', console.ConsoleRequestHandler.restart),
         ('/memcache', memcache_viewer.MemcacheViewerRequestHandler),
         ('/blobstore', blobstore_viewer.BlobstoreRequestHandler),
         ('/blobstore/blob/(.+)', blobstore_viewer.BlobRequestHandler),
         ('/taskqueue', taskqueue_queues_handler.TaskQueueQueuesHandler),
         ('/taskqueue/queue/(.+)',
          taskqueue_tasks_handler.TaskQueueTasksHandler),
         ('/cron', cron_handler.CronHandler),
         ('/xmpp', xmpp_request_handler.XmppRequestHandler),
         ('/mail', mail_request_handler.MailRequestHandler),
         ('/quit', quit_handler.QuitHandler),
         ('/search', search_handler.SearchIndexesListHandler),
         ('/search/document', search_handler.SearchDocumentHandler),
         ('/search/index', search_handler.SearchIndexHandler),
         ('/assets/(.+)', static_file_handler.StaticFileHandler),
         ('/instances', servers_handler.ServersHandler),
         webapp2.Route('/',
                       webapp2.RedirectHandler,
                       defaults={'_uri': '/instances'})],
        debug=True)
    self.dispatcher = dispatch
    self.configuration = configuration 
Example #4
Source File: routes.py    From googleapps-message-recall with Apache License 2.0 5 votes vote down vote up
def _get_redirect_route(self, template=None, name=None):
        template = template or self.template
        name = name or self.name
        defaults = self.defaults.copy()
        defaults.update({
            '_uri': self._redirect,
            '_name': name,
        })
        new_route = webapp2.Route(template, webapp2.RedirectHandler,
                                  defaults=defaults)
        return new_route 
Example #5
Source File: main.py    From professional-services with Apache License 2.0 5 votes vote down vote up
def __init__(self):
        """Define routes to handlers."""
        super(DnsSyncApplication, self).__init__([
            ('/push_notification', ComputeEngineActivityPush),
            ('/start_audit_log_loop', audit_log.StartAuditLogLoop),
            ('/logout', auth.Logout),
            ('/auth', auth.Oauth2Callback),
            ('/stop_audit_log_loop', audit_log.StopAuditLogLoop),
            ('/get_zone_config', zones.GetZoneConfig),
            ('/get_projects', zones.GetProjects),
            ('/get_project_zones', zones.GetProjectZones),
            ('/set_zone_config', zones.SetZoneConfig),
            ('/get_audit_log_state', audit_log.GetAuditLogState),
            ('/static/(.+)', AdminStaticFileHandler),
            ('/sync_projects', SyncProjectsWithDns),
            webapp2.Route(
                '/',
                webapp2.RedirectHandler,
                defaults={'_uri': '/static/index.html'}),
            webapp2.Route(
                '/index.html',
                webapp2.RedirectHandler,
                defaults={'_uri': '/static/index.html'}),
            webapp2.Route(
                '/favicon.ico',
                webapp2.RedirectHandler,
                defaults={'_uri': '/static/images/favicon.ico'}),
        ]) 
Example #6
Source File: admin_server.py    From python-compat-runtime with Apache License 2.0 5 votes vote down vote up
def __init__(self, dispatch, configuration):
    """Initializer for AdminApplication.

    Args:
      dispatch: A dispatcher.Dispatcher instance used to route requests and
          provide state about running servers.
      configuration: An application_configuration.ApplicationConfiguration
          instance containing the configuration for the application.
    """
    super(AdminApplication, self).__init__(
        [('/datastore', datastore_viewer.DatastoreRequestHandler),
         ('/datastore/edit/(.*)', datastore_viewer.DatastoreEditRequestHandler),
         ('/datastore/edit', datastore_viewer.DatastoreEditRequestHandler),
         ('/datastore-indexes',
          datastore_indexes_viewer.DatastoreIndexesViewer),
         ('/datastore-stats', datastore_stats_handler.DatastoreStatsHandler),
         ('/console', console.ConsoleRequestHandler),
         ('/console/restart/(.+)', console.ConsoleRequestHandler.restart),
         ('/memcache', memcache_viewer.MemcacheViewerRequestHandler),
         ('/blobstore', blobstore_viewer.BlobstoreRequestHandler),
         ('/blobstore/blob/(.+)', blobstore_viewer.BlobRequestHandler),
         ('/taskqueue', taskqueue_queues_handler.TaskQueueQueuesHandler),
         ('/taskqueue/queue/(.+)',
          taskqueue_tasks_handler.TaskQueueTasksHandler),
         ('/cron', cron_handler.CronHandler),
         ('/xmpp', xmpp_request_handler.XmppRequestHandler),
         ('/mail', mail_request_handler.MailRequestHandler),
         ('/quit', quit_handler.QuitHandler),
         ('/search', search_handler.SearchIndexesListHandler),
         ('/search/document', search_handler.SearchDocumentHandler),
         ('/search/index', search_handler.SearchIndexHandler),
         ('/assets/(.+)', static_file_handler.StaticFileHandler),
         ('/instances', modules_handler.ModulesHandler),
         webapp2.Route('/',
                       webapp2.RedirectHandler,
                       defaults={'_uri': '/instances'})],
        debug=True)
    self.dispatcher = dispatch
    self.configuration = configuration 
Example #7
Source File: routes.py    From googleapps-message-recall with Apache License 2.0 4 votes vote down vote up
def __init__(self, template, handler=None, name=None, defaults=None,
                 build_only=False, handler_method=None, methods=None,
                 schemes=None, redirect_to=None, redirect_to_name=None,
                 strict_slash=False):
        """Initializes a URL route. Extra arguments compared to
        :meth:`webapp2.Route.__init__`:

        :param redirect_to:
            A URL string or a callable that returns a URL. If set, this route
            is used to redirect to it. The callable is called passing
            ``(handler, *args, **kwargs)`` as arguments. This is a
            convenience to use :class:`RedirectHandler`. These two are
            equivalent::

                route = Route('/foo', handler=webapp2.RedirectHandler,
                              defaults={'_uri': '/bar'})
                route = Route('/foo', redirect_to='/bar')

        :param redirect_to_name:
            Same as `redirect_to`, but the value is the name of a route to
            redirect to. In the example below, accessing '/hello-again' will
            redirect to the route named 'hello'::

                route = Route('/hello', handler=HelloHandler, name='hello')
                route = Route('/hello-again', redirect_to_name='hello')

        :param strict_slash:
            If True, redirects access to the same URL with different trailing
            slash to the strict path defined in the route. For example, take
            these routes::

                route = Route('/foo', FooHandler, strict_slash=True)
                route = Route('/bar/', BarHandler, strict_slash=True)

            Because **strict_slash** is True, this is what will happen:

            - Access to ``/foo`` will execute ``FooHandler`` normally.
            - Access to ``/bar/`` will execute ``BarHandler`` normally.
            - Access to ``/foo/`` will redirect to ``/foo``.
            - Access to ``/bar`` will redirect to ``/bar/``.
        """
        super(RedirectRoute, self).__init__(
            template, handler=handler, name=name, defaults=defaults,
            build_only=build_only, handler_method=handler_method,
            methods=methods, schemes=schemes)

        if strict_slash and not name:
            raise ValueError('Routes with strict_slash must have a name.')

        self.strict_slash = strict_slash
        self.redirect_to_name = redirect_to_name

        if redirect_to is not None:
            assert redirect_to_name is None
            self.handler = webapp2.RedirectHandler
            self.defaults['_uri'] = redirect_to