Ejemplo n.º 1
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):
Ejemplo n.º 2
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=WSGIConnection())
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>')
Ejemplo n.º 3
0
        return self.render()

    def post(self, name):
        self.set_body('Take five post, {0} \n POST params: {1}\n'.format(
            name, self.message.arguments))
        return self.render()


def name_handler(application, message, name):
    return render('Take five, %s!' % (name), 200, 'OK', {})


urls = [('/class/<name>', NameHandler), ('/fun/<name>', name_handler),
        ('/', IndexHandler)]

config = {
    'msg_conn': WSGIConnection(),
    'handler_tuples': urls,
}

brubeck_app = Brubeck(**config)
app = SimpleURL(brubeck_app)


@app.add_route('/deco/<name>', method='GET')
def new_name_handler(application, message, name):
    return render('Take five, %s!' % (name), 200, 'OK', {})


app.run()
Ejemplo n.º 4
0
#! /usr/bin/env python
#! -*- coding: utf-8 -*-

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

brubeck_app = Brubeck(msg_conn=WSGIConnection())
app = SimpleURL(brubeck_app)


@app.add_route("/index")
def index(application, message):
    return render("index", 200, 'OK', {})


@app.add_route('/', defaults={'a': 3})
@app.add_route("/<int:a>")
def handle_int(application, message, a):
        return render("You passed int value:%s" % str(a), 200, 'OK', {})


@app.add_route('/test_endpoint', endpoint='test_endpoint')
def test(application, message):
    return render("Test Endpoint", 200, 'OK', {})


@app.add_route('/test')
def test(application, message):
    u_index = app.url_for('index')
    u_handle_int = app.url_for('handle_int', a=23)