예제 #1
0
def dispatch(hnd):
    """
    A function to dispatch request to appropriate handler function.
    It receive hander object which has request/response object.
    The dispatcher uses route to determine which controller is needed for
    the request, passes them to appropriate hander.
    This function internally called by wsgi application.
    """
    from aha.dispatch.router import get_router
    from plugin.microne.app import Microne
    # resolve the URL
    url = hnd.request.path
    r = get_router()
    route = r.match(url)
    if route:
        # call the controller function.
        func = route['controller']
        args, varargs, varkw, defaults = getargspec(func)
        # set request and response objects.
        Microne.set_handler(hnd, route)
        Microne.get_controller()
        if len(args) == 1:
            route['controller'](hnd)
        else:
            route['controller']()
        Microne.controller.put_cookies()
        Microne.clear_controller()

    else:
        # No route for given url found.
        hnd.response.set_status(404)
        raise Exception('No route for url:%s' % url)
예제 #2
0
파일: app.py 프로젝트: Letractively/aha-gae
 def decorate(func):
     """
     A function returned as a object in load time,
     which set route to given url along with decorated function.
     """
     from aha.dispatch.router import get_router
     r = get_router()
     r.connect(None, path, controller = func, **params)
     return func
예제 #3
0
    def test_route(self):
        # make a new router
        rebuild_router()

        foo = lambda x: x*2
        bar = lambda id: id*2

        app = Microne('foo')

        app.route('/foo_url')(foo)
        app.route('/bar_url/{id}')(bar)

        # checking if route for '/url' matches the function foo()
        from aha.dispatch.router import get_router

        router = get_router()
        route = router.match('/foo_url')
        assert_not_equal(route, None)
        assert_equal(route['controller'], foo)

        route = router.match('/bar_url/the_id')
        assert_not_equal(route, None)
        assert_equal(route['controller'], bar)
예제 #4
0
def appConfig():
    import aha
    from aha.controller.decorator import cache
    cache.set_namespace_func(cache_namespace)

    config = aha.Config()
    # initialize route and the installed plugins
    from aha.dispatch.router import get_router, get_fallback_router
    # initialize router with default rule.
    r = get_router()

    # setting up well known config attributes
    config.initial_user = ['*****@*****.**', '*****@*****.**', 'ats']
    config.site_root = 'http://coreblog.org'
    config.error_template = '/common/error'
    config.logout_url = '/logout'

    config.page_cache_expire = 60*60*4 # 8 hours
    config.query_cache_expire = 60*60*2 # 2 hours

    if not hasattr(config, 'site_admin_menus'):
        config.site_admin_menus = [
            ('/style/img/edit_icon.gif', 'Site setting', '/_edit_sitedata' ),
            ]

    # urls for admin interfaces
    r.connect(r'/_edit_sitedata', controller = 'sitedata', action = 'edit')

    from plugin.twitteroauth.twitter_auth import TwitterOAuth
    config.auth_obj = TwitterOAuth

    # route fot oauth redirector.
    r.connect('/_oauth', controller = 'twitteroauth')

    config.consumer_key = '8tvBBBU4P8SqPypC1X4tpA'
    config.consumer_secret = 'RGdpAxEnuETjKQdpDxsJkR67Ki16st6gfv4URhfdM'

    # set the default authenticate function
    from util.authenticate import admin
    config.admin_auth = admin

    # set the fallback route leading to object structure dispatcher
    fr = get_fallback_router()
    fr.connect(r'*url', controller = 'main', action = 'index')

    if config.debug:
        from aha.auth.appengine import AppEngineAuth
        config.auth_obj = AppEngineAuth
        """
        from plugin.user.datastoreauth import DataStoreAuth
        config.auth_obj = DataStoreAuth
        config.login_url = '/login'
        """

        #config.page_cache_expire = 0  # no caceh in development envronment.
        #config.query_cache_expire = 0  # no caceh in development envronment.

        config.site_root = 'http://127.0.0.1:8080'
        # setting log level
        logging.basicConfig(level = logging.DEBUG)
    else:
        # setting log level
        logging.basicConfig(level = logging.DEBUG)