Esempio n. 1
0
    def test_hosts(self):
        host_routes = route.get_routes()
        self.assertEqual( len(host_routes.keys()), 1 )

        h = 'blah.somewhere.com'

        @route('/abc', host=h)
        class AbcFake2(object):
            pass
        host_routes = route.get_routes()
        self.assertEqual( len(host_routes.keys()), 2 )
        self.assertTrue( h in host_routes.keys() )

        t = tornado.web.Application([], {})
        for host, routes in host_routes.iteritems():
            t.add_handlers(host, routes)
Esempio n. 2
0
    def test_routes_name(self):
        # our first handler's url route should be '/xyz'
        host_routes = route.get_routes()
        t = tornado.web.Application([], {})
        for host, routes in host_routes.iteritems():
            t.add_handlers(host, routes)

        self.assertTrue( t.reverse_url('abc') )
        self.assertTrue( t.reverse_url('other') )
Esempio n. 3
0
    def get_app(self):
        if self._app: return self._app

        settings.base_uri = self.get_url('/').rstrip('/')
        settings.login_url = '/no-login-handler'
        settings.xsrf_cookies = False
        settings.debug = True
        settings.debug_pdb = False
        self._app = Application( route.get_routes(), **settings )

        return self._app
Esempio n. 4
0
 def test_num_routes(self):
     self.assertTrue( len(route.get_routes()) == 4 ) # 2 routes + 2 redir
Esempio n. 5
0
 def test_routes_ordering(self):
     # our third handler's url route should be '/abc'
     self.assertTrue( route.get_routes()[''][2].reverse() == '/abc' )
Esempio n. 6
0
 def test_routes_name(self):
     # our first handler's url route should be '/xyz'
     t = tornado.web.Application(route.get_routes(), {})
     self.assertTrue(t.reverse_url('abc'))
     self.assertTrue(t.reverse_url('other'))
Esempio n. 7
0
 def tearDown(self):
     r = route.get_routes()
     r.clear()
Esempio n. 8
0
 def test_num_routes(self):
     self.assertEqual(len(route.get_routes()['']),4) # 2 routes + 2 redir
Esempio n. 9
0
 def test_routes_ordering(self):
     # our third handler's url route should be '/abc'
     self.assertTrue(route.get_routes()[2].reverse() == '/abc')
Esempio n. 10
0
from tornroutes import route, generic_route

# import time side effects ftw. importing the modules creates our routes
import auth
import about
import blog
import pages
import pastebin
import tmp

generic_route('/projects/?', 'projects.html')

@route('.*')
class Handle404(BaseHandler):
    def get(self):
        # self.request.path

        # let's look in the pages book to see if this page exists
        from pagelib import Book
        _book = Book(self.application.settings['dbpages'])

        page_maybe = self.request.path[1:]
        if page_maybe in _book:
            return self.redirect('/pages/{}'.format(page_maybe))

        self.render('lost.html')


# this needs to be the last line after all views are defined
routes = route.get_routes()
Esempio n. 11
0
def initialize_app(port):
    app = Application(route.get_routes())
    app.listen(port)
    return app
Esempio n. 12
0
class WazzUpHandler(tornado.web.RequestHandler):
    def get(self):
        self.set_header("Content-Type", "text/ plain") 
        self.write(json.dumps(r.info(), indent=4))


@route(r"/([\w+\-]+)") 
class FollowLinkHandler(tornado.web.RequestHandler):
    def get(self, words):

        resolved = None
        normalized = check_custom_name(words)
        if (normalized is not None):
            resolved = r.get(normalized)
            print(resolved)
            if (resolved is not None):
                self.redirect(resolved)

        raise tornado.web.HTTPError(404)


if __name__ == "__main__":
    routes = route.get_routes()
    routes.append((r"/static/(.*)", tornado.web.StaticFileHandler, 
                {"path": "static"}))
    port = int(os.environ.get("PORT", 8888))
    app = tornado.web.Application(route.get_routes())
    app.listen(port)
    tornado.ioloop.IOLoop.current().start()

Esempio n. 13
0
 def get_app(self):
     return tornado.web.Application(
         route.get_routes(),
         template_path = os.path.dirname(__file__),
         login_url = '/faked_for_authed_generic',
         )
Esempio n. 14
0
 def test_generic_routes_default_handler(self):
     generic_route('/something', 'some_template.html')
     assert len(route.get_routes()) == 1
Esempio n. 15
0
 def get_app(self):
     return tornado.web.Application(route.get_routes())
Esempio n. 16
0
 def test_generic_routes_default_handler(self):
     generic_route('/something', 'some_template.html')
     assert len(route.get_routes()) == 1
Esempio n. 17
0
 def get_app(self):
     return tornado.web.Application(route.get_routes())
Esempio n. 18
0
 def _get_webui_routes(self):
     webroot = self.options['theme_path']
     route._routes = list(reversed([url(webroot + u.regex.pattern, u.handler_class, u.kwargs, u.name) for u in route.get_routes()]))
     return route.get_routes()
Esempio n. 19
0
 def test_routes_name(self):
     # our first handler's url route should be '/xyz'
     t = tornado.web.Application(route.get_routes(), {})
     self.assertTrue( t.reverse_url('abc') )
     self.assertTrue( t.reverse_url('other') )
Esempio n. 20
0
__author__ = 'ZENGFANGUI'
import  tornado.httpserver
from tornroutes import route
from tornado.options import define, options
import src.com.fans.stat.restful.v1.circle
import src.com.fans.stat.restful.v1.topic

import sys,os
from tornroutes import route
# make sure we get our local tornroutes before anything else
sys.path = [os.path.abspath(os.path.dirname(__file__))] + sys.path
define("port", default=8010, help="run on the given port", type=int)
if __name__ == "__main__":
    tornado.options.parse_command_line()
    for item in route.get_routes():
        print item
    app = tornado.web.Application(route.get_routes())
    http_server = tornado.httpserver.HTTPServer(app)
    http_server.listen(options.port)
    tornado.ioloop.IOLoop.instance().start()
Esempio n. 21
0
 def test_num_routes(self):
     self.assertTrue(len(route.get_routes()) == 4)  # 2 routes + 2 redir