Exemple #1
0
    def inner_run(self, *args, **options):
        threading = options.get('use_threading')
        shutdown_message = options.get('shutdown_message', '')
        quit_command = (sys.platform
                        == 'win32') and 'CTRL-BREAK' or 'CONTROL-C'

        try:
            """
              handler = self.get_handler(*args, **options)
              basehttp.run(self.addr, int(self.port), handler,
                           ipv6=self.use_ipv6, threading=threading)
            """
            config = {
                'msg_conn':
                Mongrel2Connection('tcp://127.0.0.1:9999',
                                   'tcp://127.0.0.1:9998'),
                'handler_tuples': [(r'^/brubeck', DemoHandler)],
            }
            app = Brubeck(**config)
            app.run()

        # TODO: Catch IP/port errors here!

        except KeyboardInterrupt:
            if shutdown_message:
                self.stdout.write(shutdown_message)
            sys.exit(0)
Exemple #2
0
###

# Instantiate database connection
db_conn = init_db_conn()

# Routing config
handler_tuples = [
    (r'^/login', AccountLoginHandler),
    (r'^/logout', AccountLogoutHandler),
    (r'^/create', AccountCreateHandler),
    (r'^/add_item', ListAddHandler),
    (r'^/api', APIListDisplayHandler),
    (r'^/$', ListDisplayHandler),
]

# Application config
config = {
    'msg_conn': Mongrel2Connection('tcp://127.0.0.1:9999','tcp://127.0.0.1:9998'),
    'handler_tuples': handler_tuples,
    'template_loader': load_jinja2_env('./templates'),
    'db_conn': db_conn,
    'login_url': '/login',
    'cookie_secret': 'OMGSOOOOOSECRET',
    'log_level': logging.DEBUG,
}


# Instantiate app instance
app = Brubeck(**config)
app.run()
Exemple #3
0
#! /usr/bin/env python
#! -*- coding: utf-8 -*-

from simpleurl import SimpleURL
from brubeck.request_handling import Brubeck, render
from brubeck.connections import Mongrel2Connection

brubeck_app = Brubeck(msg_conn=Mongrel2Connection('tcp://127.0.0.1:9999',
                                          'tcp://127.0.0.1:9998'))
app = SimpleURL(brubeck_app)


def index(application, message):
    body = 'Take five index'
    return render(body, 200, 'OK', {})


def one(application, message):
    body = 'Take five one'
    return render(body, 200, 'OK', {})


@app.add_route('/all/', defaults={'ids': 1}, method=['GET', 'POST'])
@app.add_route('/all/<ids>', method=['GET', 'POST'])
def process(application, message, ids):
    body = 'Take five - %s' % (str(ids))
    return render(body, 200, 'OK', {})


@app.add_route('/float/<float:value>')
def check_float(application, message, value):
Exemple #4
0
    def get(self):
        """Offers login form to user
        """
        return self.render_template('landing.html')

    def post(self):
        """Checks credentials with decorator and sends user authenticated
        users to the landing page.
        """
        if hasattr(self.message, 'files'):
            print 'FILES:', self.message.files['data'][0]['body']
            im = Image.open(
                StringIO.StringIO(self.message.files['data'][0]['body']))
            im.save('word.png')
        return self.redirect('/')


###
### Configuration
###

config = {
    'msg_conn': Mongrel2Connection("tcp://127.0.0.1:9999",
                                   "tcp://127.0.0.1:9998"),
    'handler_tuples': [(r'^/add_file', UploadHandler)],
    'template_loader': load_jinja2_env('./templates/multipart'),
}

app = Brubeck(**config)
app.run()