def test_middleware_match_fail(self): controller = DummyController() def wsgi_app(environ, start_response): url, match_dict = environ['wsgiorg.routing_args'] routes_route = environ['routes.route'] routes_url = environ['routes.url'] self.assertDictEqual(match_dict, {}) self.assertIsNone(routes_route) self.assertIsInstance(routes_url, routes.util.URLGenerator) self.assertTrue(url == routes_url) start_response('404 NOT FOUND', [('Content-Type', 'text/plain')]) return ['not found!'] # Build mapper route_name = self._testMethodName route_path = "/dummy" mapper = Mapper() mapper.connect(route_name, route_path, controller=controller, mykey="myvalue") # Build router router = routes.middleware.RoutesMiddleware(wsgi_app, mapper) # send request resp = webob.Request.blank('/dummy/impossible_to_match').get_response( router) self.assertEqual(resp.status_code, 404) self.assertEqual(resp.body, "not found!")
def make_map(): """Create, configure and return the routes Mapper""" map = Mapper(directory=config['pylons.paths']['controllers'], always_scan=config['debug'], explicit=True) map.minimization = False # The ErrorController route (handles 404/500 error pages); it should # likely stay at the top, ensuring it can always be resolved map.connect('/error/{action}', controller='error') map.connect('/error/{action}/{id}', controller='error') # CUSTOM ROUTES HERE # # Default root for Application. # For now it's marked as the dashboard because I'm not implementing the # login right away. # if python_libs_exist(): map.connect('/', controller='dashboard', action='index') else: map.connect('/', controller='error', action='no_libs') map.connect('/{controller}/{action}') map.connect('share_action', '/share/{action}/{name}', controller='share') map.connect('account_action', '/account/{action}/{subaction}/{id}', controller='account') map.connect('with_subaction', '/{controller}/{action}/{subaction}') return map
def create_routes(): """Change this function if you need to add more routes to your Pylons test app. """ app_dir = os.path.dirname(os.path.abspath(__file__)) controller_dir = os.path.join(app_dir, "controllers") routes = Mapper(directory=controller_dir) routes.connect("/", controller="root", action="index") routes.connect("/raise_exception", controller="root", action="raise_exception") routes.connect("/raise_wrong_code", controller="root", action="raise_wrong_code") routes.connect("/raise_custom_code", controller="root", action="raise_custom_code") routes.connect("/raise_code_method", controller="root", action="raise_code_method") routes.connect("/render", controller="root", action="render") routes.connect("/render_exception", controller="root", action="render_exception") routes.connect("/response_headers", controller="root", action="response_headers") return routes
def setUp(self): frame.routes.mapper = Mapper() class Resource(frame.Controller): def index(self): return 'resource.index' def show(self, slug): return 'resource.show.%s' % slug def new(self): return 'resource.new' def create(self, name): return 'resource.create.%s' % name def edit(self, slug): return 'resource.edit.%s' % slug def update(self, slug, name): return 'resource.update.%s.%s' % (slug, name) def delete(self, slug): return 'resource.delete.%s' % slug frame.routes.resource('resource')
def make_map(): """Create, configure and return the routes Mapper""" map = Mapper(directory=config['pylons.paths']['controllers'], always_scan=config['debug']) map.minimization = False # The ErrorController route (handles 404/500 error pages); it should # likely stay at the top, ensuring it can always be resolved map.connect('/error/{action}', controller='error') map.connect('/error/{action}/{id}', controller='error') # CUSTOM ROUTES HERE map.connect('/registration', controller='registration', action='create') map.connect('confirm', '/registration_confirm/{email}/{nonce}', controller='registration', action='confirm') map.connect('verify_user', '/registration/{email}/verify', controller='registration', action='verify') map.connect('license', '/license', controller='license', action='show') #map.connect('/{controller}/{action}') #map.connect('/{controller}/{action}/{id}') return map
def test_mapper_with_format(self): route_name = self._testMethodName route_path = "/dummy/fathers/{id_var}{.format}" controller = DummyController() mapper = Mapper() mapper.connect(route_name, route_path, controller=controller, key1="value1", key2="value2") # Format is ".mp3" match_dict = mapper.match("/dummy/fathers/123.mp3") self.assertDictEqual( match_dict, { 'key2': u'value2', 'controller': str(controller).decode('utf-8'), 'format': u'mp3', 'key1': u'value1', 'id_var': u'123' }) # Format is none match_dict = mapper.match("/dummy/fathers/456") self.assertDictEqual( match_dict, { 'key2': u'value2', 'controller': str(controller).decode('utf-8'), 'format': None, 'key1': u'value1', 'id_var': u'456' })
def make_map(config): """Create, configure and return the routes Mapper""" map = Mapper(directory=config['pylons.paths']['controllers'], always_scan=config['debug']) map.minimization = False # The ErrorController route (handles 404/500 error pages); it should # likely stay at the top, ensuring it can always be resolved map.connect('/error/{action}', controller='error') map.connect('/error/{action}/{id}', controller='error') # CUSTOM ROUTES HERE # Map the /admin url to FA's AdminController # Map static files map.connect('fa_static', '/admin/_static/{path_info:.*}', controller='admin', action='static') # Index page map.connect('admin', '/admin', controller='admin', action='models') map.connect('formatted_admin', '/admin.json', controller='admin', action='models', format='json') # Models map.resource('model', 'models', path_prefix='/admin/{model_name}', controller='admin') map.connect('/{controller}/{action}') map.connect('/{controller}/{action}/{id}') return map
def setup_routes(self): map = Mapper(directory=config['pylons.paths']['controllers'], always_scan=config['debug']) # Setup a default route for the root of object dispatch map.connect('*url', controller=self.root_controller, action='routes_placeholder') config['routes.map'] = map
def setup_routes(self): map = Mapper() # Setup a default route for the root of object dispatch map.connect('*url', controller=self.root_controller, action='routes_placeholder') config['routes.map'] = map
def __init__(self, name, template_folder='templates'): self._name = name self._routes = Mapper(register=False) self._before_request = [] self._after_request = [] self._error_handlers = {} self._jinja_env = Environment(loader=FileSystemLoader(template_folder))
def make_map(config): """Create, configure and return the routes Mapper""" map = Mapper(directory=config['pylons.paths']['controllers'], always_scan=config['debug']) map.minimization = False map.explicit = False # The ErrorController route (handles 404/500 error pages); it should # likely stay at the top, ensuring it can always be resolved map.connect('/error/{action}', controller='error') map.connect('/error/{action}/{id}', controller='error') # CUSTOM ROUTES HERE map.connect('/', controller='metasearch', action='index') map.connect('/search', controller='metasearch', action='custom') map.connect('/custom', controller='metasearch', action='custom') map.connect('/polarize', controller='metasearch', action='polarize') map.connect('/analysis', controller='metasearch', action='analysis') map.connect('/getasyncresults', controller='metasearch', action='getasyncresults') #map.connect('/', controller='hello', action='index') #map.connect('/search', controller='hello', action='search') #map.connect('/polarize', controller='hello', action='polarize') #map.connect('/custom', controller='hello', action='custom') #map.connect('/analysis', controller='hello', action='analysis') map.connect('/feedback', controller='hello', action='feedback') return map
def make_map(config): """Create, configure and return the routes Mapper""" map = Mapper(directory=config['pylons.paths']['controllers'], always_scan=config['debug']) map.resource('publish', 'publish') map.resource('optain', 'obtain') map.resource('distribute', 'distribute') map.resource('status', 'status') map.resource('description', 'description') map.resource('services', 'services') map.resource('policy', 'policy') map.resource('harvest', 'harvest') map.minimization = False map.explicit = False # The ErrorController route (handles 404/500 error pages); it should # likely stay at the top, ensuring it can always be resolved map.connect('/error/{action}', controller='error') map.connect('/error/{action}/{id}', controller='error') # CUSTOM ROUTES HERE map.connect('/{controller}/{action}') map.connect('/{controller}/{action}/{id}') return map
def make_map(config): """Create, configure and return the routes Mapper""" map = Mapper(directory=config['pylons.paths']['controllers'], always_scan=config['debug']) map.minimization = False map.explicit = False # The ErrorController route (handles 404/500 error pages); it should # likely stay at the top, ensuring it can always be resolved map.connect('/error/{action}', controller='error') map.connect('/error/{action}/{id}', controller='error') # CUSTOM ROUTES HERE map.connect('/{controller}/{action}') map.connect('/{controller}/{action}/{id}') map.connect('index', '/', controller='frontpage', action='index') map.connect('logout', '/logout', controller='logout', action='index') map.connect('sync', '/sync', controller='sync', action='index') map.connect('settings', '/settings', controller='settings', action='index') map.connect('fb_auth_redirect', '/fb/auth_redirect', controller='fbauth', action='index') map.connect('flickr_auth_redirect', '/flickr/auth_redirect', controller='flickrauth', action='index') map.connect('picasa_auth_redirect', '/picasa/auth_redirect', controller='picasaauth', action='index') map.connect('admin', '/admin/', controller='admin', action='index') map.connect('admin-stats', '/admin/stats', controller='admin', action='stats') return map
def __init__(self): a = controller() map = Mapper() """路由匹配条件1""" # map.connect('/images', controller=a, action='search', conditions={'method': ['GET']}) """路由匹配条件2""" # map.connect('name', "/{action}/{pid}", controller=a) """路由匹配条件3""" map.resource("message", "messages", controller=a, collection={'search': 'GET'}) """路由匹配条件4""" #map.resource('message', 'messages', controller=a, #collection={'list_many': 'GET', 'create_many': 'POST'}, #member={'update_many': 'POST', 'delete_many': 'POST'}) """路由匹配条件5""" # map.resource('message', 'messages', controller=a, path_prefix='/{projectid}', # collection={'list_many': 'GET', 'create_many': 'POST'}, # member={'update_many': 'POST', 'delete_many': 'POST'}) # map.resource('message', 'messages', controller=a, # path_prefix='/{projectid}', name_prefix='lala_', # collection={'list_many': 'GET', 'create_many': 'POST'}, # member={'update_many': 'POST', 'delete_many': 'POST'}, # new={'preview': 'POST'}, # parent_resource=dict(member_name="haha", collection_name="heihei")) self.route = middleware.RoutesMiddleware(self.dispatch, map)
def make_map(): """Create, configure and return the routes Mapper""" map = Mapper(directory=config['pylons.paths']['controllers'], always_scan=config['debug']) map.minimization = False # The ErrorController route (handles 404/500 error pages); it should # likely stay at the top, ensuring it can always be resolved map.connect('/error/{action}', controller='error') map.connect('/error/{action}/{id}', controller='error') # CUSTOM ROUTES HERE map.connect('/{controller}/', action="index") map.connect('/{controller}/{action}') map.connect('/{controller}/{action}/{id}') map.connect('/', controller='alerts', action='index') map.connect('/{action}', controller='alerts') map.connect('/{action}/{id}', controller='alerts') map.connect('alerts_css', '/style.css', _static=True) map.connect('alerts_js', '/js/alerts.js', _static=True) return map
def get_map(): " This function returns mapper object for dispatcher " map = Mapper() # Add routes here urlmap( map, [ ('/', 'controllers.index'), ('/ws', 'controllers.ChatWebsocket'), ('/room/', 'controllers.index'), ('/room/{room}', 'controllers.index'), #('/route/url', 'controllerName.actionName') ]) # Old style map connecting #map.connect('Route_name', '/route/url', controller='controllerName', action='actionName') if DEBUG: map.connect(None, '/static/{path_info:.*}', controller='static', action='index') #Handling static files return map
def test_mapper_basic(self): route_name = self._testMethodName route_path = "/dummy" controller = DummyController() mapper = Mapper() mapper.connect(route_name, route_path, controller=controller, key1="value1", key2="value2") # test invalid url for invalid_url in ("/", "dummy", "/dummy/", "/dummy/123", "dummy123"): match_dict = mapper.match(invalid_url) self.assertIsNone(match_dict) # test valid url match_dict = mapper.match("/dummy") self.assertDictEqual( match_dict, { 'key2': u'value2', 'controller': str(controller).decode('utf-8'), 'key1': u'value1' })
def make_map(config): """Create, configure and return the routes Mapper""" map = Mapper(directory=config['pylons.paths']['controllers'], always_scan=config['debug']) map.minimization = False map.explicit = False mc = map.connect # The ErrorController route (handles 404/500 error pages); it should # likely stay at the top, ensuring it can always be resolved mc('/error/{action}', controller='error') mc('/error/{action}/{id}', controller='error') # Home mc('/', controller='home', action='index') # very custom mc('/{id}-{title}', controller='page', action='view') mc('/cms', controller='mgmt', action='index') mc('/cms/{action}', controller='mgmt') mc('/cms/{action}/{id}', controller='mgmt') mc('/nieuws', controller='news', action='list') mc('/nieuws/{id}/{title}', controller='news', action='view') mc('/resource/{action}/{id}/{name}', controller='fetch') # Default fallbacks (cms, other pages) mc('/{controller}', action='index') mc('/{controller}/{action}') mc('/{controller}/{action}/{id}') return map
def test_mapper_with_conditions(self): route_name = self._testMethodName route_path = "/dummy/fathers/" controller = DummyController() mapper = Mapper() mapper.connect(route_name, route_path, controller=controller, key1="value1", key2="value2", conditions=dict(method=["GET", "HEAD"])) # environ = {"REQUEST_METHOD": "GET"} match_dict = mapper.match("/dummy/fathers/", environ) self.assertDictEqual( match_dict, { 'key2': u'value2', 'key1': u'value1', 'controller': str(controller).decode('utf-8') }) environ = {"REQUEST_METHOD": "HEAD"} match_dict = mapper.match("/dummy/fathers/", environ) self.assertDictEqual( match_dict, { 'key2': u'value2', 'key1': u'value1', 'controller': str(controller).decode('utf-8') }) environ = {"REQUEST_METHOD": "PUT"} match_dict = mapper.match("/dummy/fathers/", environ) self.assertIsNone(match_dict)
def make_map(config): """Create, configure and return the routes Mapper""" map = Mapper(directory=config['pylons.paths']['controllers'], always_scan=config['debug']) map.minimization = False map.explicit = False # The ErrorController route (handles 404/500 error pages); it should # likely stay at the top, ensuring it can always be resolved map.connect('/error/{action}', controller='error') map.connect('/error/{action}/{id}', controller='error') # CUSTOM ROUTES HERE map.connect('/autodiscover/{action}.xml', controller="autodiscover") map.connect('/Autodiscover/{action}.xml', controller="autodiscover") map.connect('/ews/oab.xml', controller="oab", action="get_oab", conditions={'method': ["GET", "POST"]}) map.connect('/ews/oab.xml', controller="oab", action="head_oab", conditions={'method': ["HEAD"]}) map.connect('/ews/{controller}') map.connect('/ews/{controller}.wsdl') map.connect('/{controller}/{action}') map.connect('/{controller}/{action}/{id}') # RPC over HTTP map.connect('/rpc/rpcproxy.dll', controller='rpcproxy') return map
def __init__(self): self.mapper = Mapper() self.controllers = {} self.resources = {} # Setup to use sub domains by default self.mapper.sub_domains = True
def make_map(config, global_conf, app_conf): """Create, configure and return the routes Mapper""" routeMap = Mapper(directory=config['pylons.paths']['controllers'], always_scan=config['debug']) routeMap.minimization = False #routeMap.explicit = False # The ErrorController route (handles 404/500 error pages); it should # likely stay at the top, ensuring it can always be resolved routeMap.connect('/error/{action}', controller='error') routeMap.connect('/error/{action}/{id}', controller='error') # CUSTOM ROUTES HERE # in case of selfservice, we route the default / to selfservice selfservice = app_conf.get('service.selfservice', 'True') == 'True' if selfservice: routeMap.connect('/selfservice/custom-style.css', controller='selfservice', action='custom_style') routeMap.connect('/selfservice', controller='selfservice', action='index') routeMap.connect('/', controller='selfservice', action='index') for cont in ['selfservice', 'account', 'userservice']: routeMap.connect('/%s/{action}' % cont , controller=cont) routeMap.connect('/%s/{action}/{id}' % cont, controller=cont) return routeMap
def make_app(self, req): map = Mapper() map.connect('index', '/', method='index') results = map.routematch(environ=req.environ) if results: match, route = results req.urlvars = ((), match) kwargs = match.copy() method = kwargs.pop('method') return getattr(self, method)(req, **kwargs) else: public_path = os.path.join(os.path.dirname(__file__), 'public') if not os.path.exists(public_path): return exc.HTTPNotFound() path = req.path if path.startswith('/'): path = path[1:] public_file_path = os.path.join(public_path, path) if os.path.exists(public_file_path): if path.endswith('.css'): req.response.content_type = 'text/css' elif path.endswith('.js'): req.response.content_type = 'text/javascript' return open(public_file_path, 'r').read().strip() else: return exc.HTTPNotFound()
def get_map(): " This function returns mapper object for dispatcher " map = Mapper() # Add routes here urlmap(map, [ ('/', 'controllers#index'), #('/route/url', 'controllerName.actionName') ]) # Old style map connecting #map.connect('Route_name', '/route/url', controller='controllerName', #action='actionName') if DEBUG: r = [Route(None, '/{path_info:.*}', controller='noodles.utils.static', action='index', path=os.path.join(os.getcwd(), 'static'), auth=True)] map.extend(r, '/static') user = [ Route(None, '/create', controller='user_controller', action='add_user'), Route(None, '/detail/:id', controller='user_controller', action='detail_user'), Route(None, '/list', controller='user_controller', action='list_users'), Route(None, '/delete/:id', controller='user_controller', action='delete_user'), Route(None, '/update/:id', controller='user_controller', action='update_user'), ] map.extend(user, '/user') article = [ Route(None, '/create', controller='article_controller', action='add_article'), Route(None, '/read/:id', controller='article_controller', action='read'), Route(None, '/list', controller='article_controller', action='list_articles'), Route(None, '/delete/:id', controller='article_controller', action='delete_article'), ] map.extend(article, '/article') return map
def make_map(config): # Base mapping map = Mapper(directory=config['pylons.paths']['controllers'], always_scan=config['debug']) map.minimization = False map.explicit = False # The ErrorController route (handles 404/500 error pages); it should # likely stay at the top, ensuring it can always be resolved map.connect('/error/{action}', controller='error') map.connect('/error/{action}/{id}', controller='error') # CUSTOM ROUTES HERE # Redirect root directory to main (home) controller map.connect('/', controller="main", action="index") # Redirect helps / about / bottom links map.connect('/about', controller="help", action="about") map.connect('/contact', controller="help", action="contact") map.connect('/license', controller="help", action="license") map.connect('/policy', controller="help", action="policy") map.connect('/help', controller="help", action="help") map.connect('/achievements', controller="help", action="achievements") # Redirect user login, logout, registration, or deletion map.connect('/login', controller="users", action="login") map.connect('/logout', controller="users", action="logout") map.connect('/register', controller="users", action="register") map.connect('/unregister', controller="users", action="unregister") map.connect('/preferences', controller="users", action="preferences") map.connect('/recover', controller="users", action="recover") map.connect('/users/*url', controller="users", action="user_view") map.connect('/leaderboard', controller="users", action="leaderboard") # Admin pages (protected) map.connect('/admin', controller="admin", action="admin") # Redirect for specific challenges and grouped challenges map.connect('/challenge/*url', controller="challenge", action="challenge_view") map.connect('/challenges/view', controller="challenges", action="challenges_view") map.connect('/challenges/*url', controller="challenges", action="challengegroup_view") # Redirect for submissions and results map.connect('/submit/*url', controller="submit", action="submit_view") map.connect('/results/*url', controller="results", action="results_view") map.connect('/result/*url', controller="results", action="result_view") # Generic redirects map.connect('/{controller}/{action}') map.connect('/{controller}/{action}/{id}') return map
def __init__(self): self.maper = Mapper() self.maper.connect('/users', controller=Controller(), action='index', conditions={'method': ['GET']}) self.router = middleware.RoutesMiddleware(self._dispatch, self.maper)
def make_map(config): """Create, configure and return the routes Mapper""" map = Mapper(directory=config['pylons.paths']['controllers'], always_scan=config['debug']) map.minimization = True map.explicit = False # The ErrorController route (handles 404/500 error pages); it should # likely stay at the top, ensuring it can always be resolved map.connect('/error/{action}', controller='error') map.connect('/error/{action}/{id}', controller='error') # CUSTOM ROUTES HERE # Route root url map.connect('/', controller='view') # Make default map.redirect("/view", "/", _redirect_code='301 Moved Permanently') map.redirect("/view/index", "/", _redirect_code='301 Moved Permanently') map.connect('/{controller}/{action}') map.connect('/{controller}/{action}/{id}') return map
def __init__(self, rmap=None, settings=None, controllers=None): """ INIT Args: base_node: The root of the traversal tree before: Method to be called before the view is called after: Method to be called after the view is called settings: Settings dictionary, will be available in all requests document_root: Root directory for mako templates """ if rmap is None: self.map = Mapper() else: self.map = rmap if settings is None: settings = {} self._session_factory = None self.settings = settings self._before = [] self._after = [] self._exc_listeners = {} self._controllers = {} if controllers is not None: self._controllers.update(controllers) RenderFactory.create(settings)
def make_map(): """Create, configure and return the routes Mapper""" map = Mapper(directory=config['pylons.paths']['controllers'], always_scan=config['debug']) map.minimization = False # The ErrorController route (handles 404/500 error pages); it should # likely stay at the top, ensuring it can always be resolved map.connect('/error/{action}', controller='error') map.connect('/error/{action}/{id}', controller='error') # CUSTOM ROUTES HERE map.connect('user', '/', controller='user_', action='home') map.connect('user', '/user/{action}', controller='user_') map.connect('project', '/project/:uri/:revision/download/{filename:.*}', controller='project', action='download') map.connect('project', '/project/:uri/:revision/share/{action}', controller='share') map.connect('project', '/project/:uri/:revision/{action}/:file', controller='project') map.connect('project', '/project/:uri/:revision/{action}', controller='project') map.connect('project', '/project/:uri/{action}', controller='project') map.connect('/{controller}/{action}') map.connect('/{controller}/{action}/{id}') return map
def make_map(config): """ Create, configure and return the routes Mapper. """ map = Mapper(directory=config["pylons.paths"]["controllers"], always_scan=config["debug"]) map.minimization = False map.explicit = False # The ErrorController route (handles 404/500 error pages); it should # likely stay at the top, ensuring it can always be resolved map.connect("/error/{action}", controller="error") map.connect("/error/{action}/{id}", controller="error") # CUSTOM ROUTES HERE # Default routes map.connect("/{controller}", action="index") map.connect("/{controller}/{action}") map.connect("/{controller}/{action}/{id}") # Define root page map.connect("/", controller="index", action="index") # Always remove trailing slash map.redirect('/*(url)/', '/{url}', _redirect_code='301 Moved Permanently') return map