Exemplo n.º 1
0
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
Exemplo n.º 2
0
    def run(options: dict) -> bool:
        """Run the app

        Run the CLI app using supplied options and print the result or error.

        Arguments:
            options {dict} -- The options dict with file, start, end props

        Returns:
            bool           -- True if success false otherwise
        """
        try:
            routes, nodes = Parser.parse(options['file'])
            route = Route(routes, nodes)
            cost = route.calculate(options['start'], options['end'], 'two-way'
                                   in options)
            print(
                'The route from {} to {} includes {} stops and will take {} minutes.'
                .format(options['start'], options['end'], cost.stops,
                        cost.time))

            return True
        except NoRouteException:
            print('No routes from {} to {}.'.format(options['start'],
                                                    options['end']))

            return False
        except ParserException as e:
            print(e)

            return False
Exemplo n.º 3
0
def url(route=None, controller=None, action=None, name=None):

    route = Route(name, route)
    route.makeregexp('')

    regexp = re.sub(r'(?<!\\)\\', '', route.regexp)

    return URLSpec(regexp, controller, dict(action=action), name=name)
Exemplo n.º 4
0
    def test_calculate(self):
        routes, nodes = Parser.parse(self.TEST_CSV)

        for case in [('A', 'A', '(0, 0)'), ('A', 'B', '(0, 5)'),
                     ('A', 'C', '(1, 10)'), ('A', 'D', '(0, 15)'),
                     ('E', 'J', '(2, 30)')]:
            cost = Route(routes, nodes).calculate(case[0], case[1])
            cost1 = Route(routes, nodes).calculate(case[1], case[0], True)
            self.assertEqual('{}'.format(cost), case[2])
            self.assertEqual('{}'.format(cost1), case[2])
Exemplo n.º 5
0
 def connect(self, *args, **kargs):
     """Create and connect a new Route to the Mapper.
     
     Usage:
     
     .. code-block:: python
     
         m = Mapper()
         m.connect(':controller/:action/:id')
         m.connect('date/:year/:month/:day', controller="blog", action="view")
         m.connect('archives/:page', controller="blog", action="by_page",
         requirements = { 'page':'\d{1,2}' })
         m.connect('category_list', 'archives/category/:section', controller='blog', action='category',
         section='home', type='list')
         m.connect('home', '', controller='blog', action='view', section='home')
     
     """
     routename = None
     if len(args) > 1:
         routename = args[0]
     else:
         args = (None,) + args
     if '_explicit' not in kargs:
         kargs['_explicit'] = self.explicit
     if '_minimize' not in kargs:
         kargs['_minimize'] = self.minimization
     route = Route(*args, **kargs)
             
     # Apply encoding and errors if its not the defaults and the route 
     # didn't have one passed in.
     if (self.encoding != 'utf-8' or self.decode_errors != 'ignore') and \
        '_encoding' not in kargs:
         route.encoding = self.encoding
         route.decode_errors = self.decode_errors
     
     if not route.static:
         self.matchlist.append(route)
     
     if routename:
         self._routenames[routename] = route
         route.name = routename
     if route.static:
         return
     exists = False
     for key in self.maxkeys:
         if key == route.maxkeys:
             self.maxkeys[key].append(route)
             exists = True
             break
     if not exists:
         self.maxkeys[route.maxkeys] = [route]
     self._created_gens = False
     self._created_regs = False
Exemplo n.º 6
0
def get_map():
    " This function returns mapper object for dispatcher "
    map = Mapper()
    # Add routes here
    urlmap(map, [('/', 'controllers#index'), ('/write', 'controllers#write'),
                 ('/read', 'controllers#read'),
                 ('/clean', 'controllers#clean'),
                 ('/reset', 'controllers#reset')])

    # 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')

    return map
Exemplo n.º 7
0
    def test_calculate_raises(self):
        routes, nodes = Parser.parse(self.TEST_CSV)

        for case in [('A', 'E'), ('A', 'F'), ('A', 'G'), ('A', 'H'),
                     ('A', 'I'), ('X', 'Y')]:
            with self.assertRaises(NoRouteException):
                Route(routes, nodes).calculate(case[0], case[1])
Exemplo n.º 8
0
 def test_add_routes(self):
     map = Mapper(explicit=True)
     map.minimization = False
     routes = [Route(
         'foo',
         '/foo',
     )]
     map.extend(routes)
     eq_(map.match('/foo'), {})
Exemplo n.º 9
0
 def match(self, request):
     d = None
     if self.domain:
         if self._domain_route is None:
             self._domain_route = RoutesRoute(None, self.domain, _explicit=True)
             self._domain_route.makeregexp([])
         m = self._domain_route.match(request.host)
         if m is not False:
             d = m.copy()
     if self.path:
         if self._path_route is None:
             self._path_route = RoutesRoute(None, self.path, _explicit=True)
             self._path_route.makeregexp([])
         m = self._path_route.match(request.path)
         if m is not False:
             if d is None:
                 d = {}
             d.update(m)
     return d
Exemplo n.º 10
0
 def match(self, request):
     d = None
     if self.domain:
         if self._domain_route is None:
             self._domain_route = RoutesRoute(None, self.domain, _explicit=True)
             self._domain_route.makeregexp([])
         m = self._domain_route.match(request.host)
         if m is not False:
             d = m.copy()
     if self.path:
         if self._path_route is None:
             self._path_route = RoutesRoute(None, self.path, _explicit=True)
             self._path_route.makeregexp([])
         m = self._path_route.match(request.path)
         if m is not False:
             if d is None:
                 d = {}
             d.update(m)
     return d
Exemplo n.º 11
0
    def __init__(self, json_path):
        self.trains = {}
        self.routes = {}
        self.resources = {}
        self.data = None

        with open(json_path) as f:
            data = json.load(f)
            self.data = data
            self.label = data["label"]
            self.hash = data["hash"]

            for d in data["resources"]:
                self.add_resource(Resource(data=d))

            routes = {}
            for d in data["routes"]:
                routes[d["id"]] = d

            for d in data["service_intentions"]:
                train = self.add_train(Train(data=d))
                train.network.add_route(
                    Route(data=routes[train.get_id()], train=train))
Exemplo n.º 12
0
class Route(object):
    __attributes__ = ('name', 'domain', 'path', 'target')

    def __init__(self, **kwargs):
        for attr in self.__attributes__:
            setattr(self, attr, None)
        self._update(kwargs)
        self._domain_route, self._path_route = None, None
            
    def _update(self, kwargs):
        for attr in self.__attributes__:
            if attr in kwargs:
                setattr(self, attr, kwargs[attr])

    def match(self, request):
        d = None
        if self.domain:
            if self._domain_route is None:
                self._domain_route = RoutesRoute(None, self.domain, _explicit=True)
                self._domain_route.makeregexp([])
            m = self._domain_route.match(request.host)
            if m is not False:
                d = m.copy()
        if self.path:
            if self._path_route is None:
                self._path_route = RoutesRoute(None, self.path, _explicit=True)
                self._path_route.makeregexp([])
            m = self._path_route.match(request.path)
            if m is not False:
                if d is None:
                    d = {}
                d.update(m)
        return d

    def to_json(self):
        """Return a python dict."""
        return dict((attr, getattr(self, attr))
                    for attr in self.__attributes__)
Exemplo n.º 13
0
class Route(object):
    __attributes__ = ('name', 'domain', 'path', 'target')

    def __init__(self, **kwargs):
        for attr in self.__attributes__:
            setattr(self, attr, None)
        self._update(kwargs)
        self._domain_route, self._path_route = None, None

    def _update(self, kwargs):
        for attr in self.__attributes__:
            if attr in kwargs:
                setattr(self, attr, kwargs[attr])

    def match(self, request):
        d = None
        if self.domain:
            if self._domain_route is None:
                self._domain_route = RoutesRoute(None, self.domain, _explicit=True)
                self._domain_route.makeregexp([])
            m = self._domain_route.match(request.host)
            if m is not False:
                d = m.copy()
        if self.path:
            if self._path_route is None:
                self._path_route = RoutesRoute(None, self.path, _explicit=True)
                self._path_route.makeregexp([])
            m = self._path_route.match(request.path)
            if m is not False:
                if d is None:
                    d = {}
                d.update(m)
        return d

    def to_json(self):
        """Return a python dict."""
        return dict((attr, getattr(self, attr))
                    for attr in self.__attributes__)
Exemplo n.º 14
0
 def test_route_with_backslash(self):
     r = Route('test', '/foo\\\\bar')
     self.assertEqual(r.routelist, ['/foo\\bar'])
Exemplo n.º 15
0
 def test_normal_route(self):
     r = Route('test', '/foo/bar')
     self.assertEqual(r.routelist, ['/foo/bar'])
Exemplo n.º 16
0
 def test_route_with_all_escapes(self):
     r = Route('test', '/hmm\\:\\*\\{\\}*star/{brackets}/:colon')
     self.assertEqual(
         r.routelist, ['/hmm:*{}', {'name': 'star', 'type': '*'}, '/',
                       {'name': 'brackets', 'type': ':'}, '/',
                       {'name': 'colon', 'type': ':'}])
Exemplo n.º 17
0
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

from routes.route import Route

auth_routes = [
    Route('mediagoblin.auth.register',
          '/register/',
          controller='mediagoblin.auth.views:register'),
    Route('mediagoblin.auth.register_success',
          '/register/success/',
          template='mediagoblin/auth/register_success.html',
          controller='mediagoblin.views:simple_template_render'),
    Route('mediagoblin.auth.login',
          '/login/',
          controller='mediagoblin.auth.views:login'),
    Route('mediagoblin.auth.logout',
          '/logout/',
          controller='mediagoblin.auth.views:logout'),
    Route('mediagoblin.auth.verify_email',
          '/verify_email/',
          controller='mediagoblin.auth.views:verify_email'),
    Route('mediagoblin.auth.verify_email_notice',
Exemplo n.º 18
0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
'''
'''
Created on Nov 29, 2011

@author: biyu
'''
from agent.lib.baseappservice import BaseAppServiceController


class dummyService(BaseAppServiceController):
    def __init__(self):
        BaseAppServiceController.__init__(self)

    def index(self):
        return 'Inside dummyService controller.index'


from routes.route import Route

ControllerMeta = ([
    Route("DummyService", "/dummyService/{action}", controller="dummyService"),
], {
    "dummyService": ("dummy.controller.dummyService", 'dummyService')
})
Exemplo n.º 19
0
 def test_route_with_random_escapes(self):
     r = Route('test', '\\/f\\oo\\/ba\\r')
     self.assertEqual(r.routelist, ['\\/f\\oo\\/ba\\r'])
Exemplo n.º 20
0
# GNU MediaGoblin -- federated, autonomous media hosting
# Copyright (C) 2011 Free Software Foundation, Inc
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

from routes.route import Route

submit_routes = [
    Route('mediagoblin.submit.start',
          '/',
          controller='mediagoblin.submit.views:submit_start'),
    Route('mediagoblin.submit.success',
          '/success/',
          controller='mediagoblin.submit.views:submit_success'),
]
Exemplo n.º 21
0
# GNU MediaGoblin -- federated, autonomous media hosting
# Copyright (C) 2011 Free Software Foundation, Inc
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

from routes.route import Route

submit_routes = [
    Route('mediagoblin.submit.start',
          '/',
          controller='mediagoblin.submit.views:submit_start'),
    Route('mediagoblin.submit.success',
          '/success/',
          template='mediagoblin/submit/success.html',
          controller='mediagoblin.views:simple_template_render')
]
Exemplo n.º 22
0
from routes.route import Route

chooser_routes = [
    Route("choose_index", "/",
          controller="cc.engine.chooser.views:chooser_view"),
    Route("choose_index", "/classic_chooser/",
          controller="cc.engine.chooser.views:classic_chooser_view"),
    Route("choose_results_one", "/results-one",
          controller="cc.engine.chooser.views:choose_results_view"),
    Route("choose_results_one", "/xhr_api",
          controller="cc.engine.chooser.views:xhr_api"),
    Route("choose_results_one", "/xmp",
          controller="cc.engine.chooser.views:choose_xmp_view"),
    Route("choose_get_html", "/get-html",
          controller="cc.engine.chooser.views:get_html"),
    Route("choose_get_rdf", "/get-rdf",
          controller="cc.engine.chooser.views:get_rdf"),
    Route("choose_non_web_popup", "/non-web-popup",
          controller="cc.engine.chooser.views:non_web_popup"),
    Route("choose_xmp_popup", "/metadata.xmp",
          controller="cc.engine.chooser.views:choose_xmp_view"),
    Route("choose_work_html_popup", "/work-html-popup",
          controller="cc.engine.chooser.views:work_email_popup"),
    Route("choose_work_html_send", "/work-email",
          controller="cc.engine.chooser.views:work_email_send"),

    Route("choose_wiki", "/wiki",
          controller="cc.engine.chooser.views:choose_wiki_redirect"),
    Route("choose_music", "/music",
          controller="cc.engine.chooser.views:outdated_choosers_redirect"),
    Route("choose_sampling", "/sampling",
Exemplo n.º 23
0
from routes.route import Route

licenses_routes = [
    Route("licenses_index",
          "/",
          controller="cc.engine.licenses.views:licenses_view"),

    # MIT / BSD routing
    Route("license_deed_mit",
          "/MIT/",
          redirect_to="http://opensource.org/licenses/mit-license.php",
          controller="cc.engine.licenses.views:moved_permanently_redirect"),
    Route("license_deed_bsd",
          "/BSD/",
          redirect_to="http://opensource.org/licenses/bsd-license.php",
          controller="cc.engine.licenses.views:moved_permanently_redirect"),
    Route("license_deed_explicit_mit",
          "/MIT/deed",
          redirect_to="http://opensource.org/licenses/mit-license.php",
          controller="cc.engine.licenses.views:moved_permanently_redirect"),
    Route("license_deed_lang_mit",
          "/MIT/deed.{target_lang}",
          redirect_to="http://opensource.org/licenses/mit-license.php",
          controller="cc.engine.licenses.views:moved_permanently_redirect"),
    Route("license_deed_explicit_bsd",
          "/BSD/deed",
          redirect_to="http://opensource.org/licenses/bsd-license.php",
          controller="cc.engine.licenses.views:moved_permanently_redirect"),
    Route("license_deed_lang_bsd",
          "/BSD/deed.{target_lang}",
          redirect_to="http://opensource.org/licenses/bsd-license.php",
Exemplo n.º 24
0
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

from routes.route import Route

user_routes = [
    Route('mediagoblin.user_pages.user_home',
          "/{user}/",
          controller="mediagoblin.user_pages.views:user_home"),
    Route('mediagoblin.user_pages.user_gallery',
          "/{user}/gallery/",
          controller="mediagoblin.user_pages.views:user_gallery"),
    Route('mediagoblin.user_pages.media_home',
          '/{user}/m/{media}/',
          requirements=dict(m_id="[0-9a-fA-F]{24}"),
          controller="mediagoblin.user_pages.views:media_home"),
    Route('mediagoblin.edit.edit_media',
          "/{user}/m/{media}/edit/",
          controller="mediagoblin.edit.views:edit_media"),
    Route('mediagoblin.user_pages.atom_feed',
          '/{user}/atom/',
          controller="mediagoblin.user_pages.views:atom_feed"),
    Route('mediagoblin.user_pages.media_post_comment',
Exemplo n.º 25
0
 def test_route_with_colon(self):
     r = Route('test', '/foo:bar/baz')
     self.assertEqual(
         r.routelist, ['/foo', {'name': 'bar', 'type': ':'}, '/', 'baz'])
Exemplo n.º 26
0
from routes.route import Route

characteristic_routes = [
    Route('characteristic_by',
          '/by',
          characteristic='by',
          controller="cc.engine.characteristic.views:characteristic_view"),
    Route('characteristic_nc',
          '/nc',
          characteristic='nc',
          controller="cc.engine.characteristic.views:characteristic_view"),
    Route('characteristic_nc',
          '/nd',
          characteristic='nd',
          controller="cc.engine.characteristic.views:characteristic_view"),
    Route('characteristic_sa',
          '/sa',
          characteristic='sa',
          controller="cc.engine.characteristic.views:characteristic_view")
]
Exemplo n.º 27
0
 def test_route_with_escaped_colon(self):
     r = Route('test', '/foo\\:bar/baz')
     self.assertEqual(r.routelist, ['/foo:bar/baz'])
Exemplo n.º 28
0
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

from routes.route import Route

auth_routes = [
    Route('mediagoblin.auth.register',
          '/register/',
          controller='mediagoblin.auth.views:register'),
    Route('mediagoblin.auth.register_success',
          '/register/success/',
          controller='mediagoblin.auth.views:register_success'),
    Route('mediagoblin.auth.login',
          '/login/',
          controller='mediagoblin.auth.views:login'),
    Route('mediagoblin.auth.logout',
          '/logout/',
          controller='mediagoblin.auth.views:logout'),
    Route('mediagoblin.auth.verify_email',
          '/verify_email/',
          controller='mediagoblin.auth.views:verify_email')
]
Exemplo n.º 29
0
 def test_route_with_both_colons(self):
     r = Route('test', '/prefix/escaped\\:escaped/foo=:notescaped/bar=42')
     self.assertEqual(
         r.routelist, ['/prefix/escaped:escaped/foo=',
                       {'name': 'notescaped', 'type': ':'}, '/', 'bar=42'])
Exemplo n.º 30
0
# GNU MediaGoblin -- federated, autonomous media hosting
# Copyright (C) 2011 Free Software Foundation, Inc
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

from routes.route import Route

edit_routes = [
    # Media editing view handled in user_pages/routing.py
    Route('mediagoblin.edit.profile',
          '/profile/',
          controller="mediagoblin.edit.views:edit_profile")
]
Exemplo n.º 31
0
    def make_route(self, *args, **kargs):
        """Make a new Route object

        A subclass can override this method to use a custom Route class.
        """
        return Route(*args, **kargs)