Beispiel #1
0
def make_app():
    app = tbtbot.lib.Application(routes.get_routes(),
                                 debug=True,
                                 autoreload=True)

    app.add_handlers('', [
        (r"/webhook", tornado.web.RequestHandler),
    ])
    return app
Beispiel #2
0
    def __init__(self):
        handlers = routes.get_routes()

        settings = dict(
            site_title=config.project_name,
            cookie_secret=config.cookie_secret,
            template_path=utils.get_path('templates'),
            static_path=utils.get_path('static'),
            xsrf_cookies=False,  # before enabling read: http://www.tornadoweb.org/en/stable/guide/security.html
            debug=config.is_local,
            autoreload=config.is_local,
            login_url='/login'
        )

        tornado.web.Application.__init__(self, handlers, **settings)
Beispiel #3
0
def get_routes():
    from_param = request.args.get('from')
    to_param = request.args.get('to')

    if not from_param:
        error = {"error": "'From' query parameter unspecified"}
        return jsonify(error), 400

    if not to_param:
        error = {"error": "'To' query parameter unspecified"}
        return jsonify(error), 400

    global routes
    response = routes.get_routes(from_param, to_param)

    return jsonify(response)
Beispiel #4
0
    def __init__(self, mc, cache, log):
        handlers = get_routes()

        settings = {
            'cookie_secret': os.environ['COOKIE_SECRET'],
            'login_url': '/',
            'template_path': os.environ['TEMPLATE_PATH'],
            'static_path': os.environ['STATIC_PATH'],
            'debug': True,
            "xsrf_cookies": True,
        }

        self.mc = mc
        self.cache = cache
        self.log = log
        self.httpc = httpclient.AsyncHTTPClient()
        web.Application.__init__(self, handlers, **settings)
Beispiel #5
0
    def __init__(self, **more_settings):
        settings.define_app_options()
        parse_command_line(final=False)
        self_dir_path = os.path.abspath(os.path.dirname(__file__))
        if options.debug:
            conf_file_path = os.path.join(self_dir_path, 'server.conf')
        else:
            conf_file_path = os.path.join(self_dir_path, 'prod.conf')
        if os.path.exists(conf_file_path):
            parse_config_file(conf_file_path, final=False)
        parse_command_line(final=True)
        """
        loader = ChoiceLoader([
            FileSystemLoader(os.path.join(self_dir_path, 'templates')),
        ])
        """
        loader = JinjaLoader(loader=ChoiceLoader([
            FileSystemLoader(os.path.join(self_dir_path, 'templates')),
        ]),
                             debug=options.debug)
        SmartStaticFileHandler.file_finder = MultiFileFindler(
            [], os.path.join(self_dir_path, 'static'))
        the_settings = {
            'template_loader': loader,
            'debug': options.debug,
            'cookie_secret': options.cookie_secret,
            'xsrf_cookies': True,
            'db': self.setup_db_client(),
            'asy_db': self.setup_asy_db_client(),
            'userdb': self.setup_user_db(),
            'oss_bucket': self.setup_oss_bucket(),
            'static_path': u'/static/',
            'static_handler_class': SmartStaticFileHandler,
        }

        the_settings.update(more_settings)
        routes = get_routes()
        self.app = Application(routes, **the_settings)
        self.app.settings['template_loader'].env.globals.update({
            'options':
            options,
            'datetime':
            datetime.datetime,
        })
Beispiel #6
0
"""
This is designed more for backend developers building quick prototypes
If you want to optimize your frontend you should probably start with
using less and having a script the merge and compress them
"""
import logging
import webapp2
import config
import routes
from google.appengine.ext import deferred, ndb
from web import errors
from lib import basehandler

app = webapp2.WSGIApplication(debug=basehandler.IS_DEV, config=config.webapp2_config, routes=routes.get_routes())


# If you want dynamic custom error handlers use below
# or just comment it out. This is useful for gracefully showing errors to users
# with all your layout in place
if not basehandler.IS_BACKEND:

    # defined custom error handlers
    class Webapp2HandlerAdapter(webapp2.BaseHandlerAdapter):

        def __call__(self, request, response, exception):
            request.route_args = {
                'exception': exception
            }
            logging.exception(exception)
            handler = self.handler(request, response)
Beispiel #7
0
import webapp2
import config
import routes

from tests import test_base

app = webapp2.WSGIApplication(routes.get_routes(),
                              config=config.webapp2_config)


class TestAuthHandler(test_base.BaseTestCase):
    def tearDown(self):
        super(TestAuthHandler, self).tearDown()
        app.error_handlers = {}

    def test_redirect_if_no_session(self):
        rsp = app.get_response('/secure/')
        self.assertEqual(rsp.status_int, 302)

    def test_create_user_and_login(self):
        req = webapp2.Request.blank(
            '/',
            POST={
                'username': '******',
                'password': '******'
            },
            headers=[('Content-Type',
                      'application/x-www-form-urlencoded; charset=utf-8')])
        req.app = app
        rsp = req.get_response(app)
        self.assertEqual(rsp.status_int, 302)
import webapp2
import config
import routes

from tests import test_base

app = webapp2.WSGIApplication(routes.get_routes(), config=config.webapp2_config)

class TestAuthHandler(test_base.BaseTestCase):
    def tearDown(self):
        super(TestAuthHandler, self).tearDown()
        app.error_handlers = {}

    def test_redirect_if_no_session(self):
        rsp = app.get_response('/secure/')
        self.assertEqual(rsp.status_int, 302)

    def test_create_user_and_login(self):
        req = webapp2.Request.blank('/', POST={'username': '******', 'password': '******'},
            headers=[('Content-Type', 'application/x-www-form-urlencoded; charset=utf-8')])
        req.app = app
        rsp = req.get_response(app)
        self.assertEqual(rsp.status_int, 302)

        rsp = app.get_response('/login/', POST={'username': '******', 'password': '******'},
            headers=[('Content-Type', 'application/x-www-form-urlencoded; charset=utf-8')])
        self.assertEqual(rsp.status_int, 302)
Beispiel #9
0
This is designed more for backend developers building quick prototypes
If you want to optimize your frontend you should probably start with
using less and having a script the merge and compress them
"""
import logging
from paste.cascade import Cascade
from paste.urlparser import StaticURLParser
import webapp2
import config
import routes
from web import errors
from lib import basehandler

app = webapp2.WSGIApplication(debug=basehandler.IS_DEV,
                              config=config.webapp2_config,
                              routes=routes.get_routes())


# defined custom error handlers
class Webapp2HandlerAdapter(webapp2.BaseHandlerAdapter):
    def __call__(self, request, response, exception):
        request.route_args = {'exception': exception}
        logging.exception(exception)
        handler = self.handler(request, response)

        return handler.get()


app.error_handlers[403] = Webapp2HandlerAdapter(errors.Error403Handler)
app.error_handlers[404] = Webapp2HandlerAdapter(errors.Error404Handler)
app.error_handlers[503] = Webapp2HandlerAdapter(errors.Error503Handler)
Beispiel #10
0
def main():
    # Create the WSGI application and define route handlers
    app = WSGIApplication(routes.get_routes(), debug=config.debug)
Beispiel #11
0
# main.py - main starting point of app
import webapp2

import routes # app url routes
import config # webapp2 configuration

app = webapp2.WSGIApplication(routes.get_routes(), config=config.get_config(),debug=True)
Beispiel #12
0
"""
This is designed more for backend developers building quick prototypes
If you want to optimize your frontend you should probably start with
using less and having a script the merge and compress them
"""
import logging
import webapp2
import config
import routes
from google.appengine.ext import deferred, ndb
from web import errors
from lib import basehandler

app = webapp2.WSGIApplication(debug=basehandler.IS_DEV, config=config.webapp2_config, routes=routes.get_routes())


# If you want dynamic custom error handlers use below
# or just comment it out. This is useful for gracefully showing errors to users
class Webapp2HandlerAdapter(webapp2.BaseHandlerAdapter):

    def __call__(self, request, response, exception):
        request.route_args = {
            'exception': exception
        }
        logging.exception(exception)
        handler = self.handler(request, response)

        return handler.get()

app.error_handlers[403] = Webapp2HandlerAdapter(errors.Error403Handler)
app.error_handlers[404] = Webapp2HandlerAdapter(errors.Error404Handler)
Beispiel #13
0
def make_app():
    return tornado.web.Application(routes.get_routes(),
                                   debug=True,
                                   autoreload=True)