python类route()的实例源码

create.py 文件源码 项目:deb-python-falcon 作者: openstack 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def flask(body, headers):
    import flask

    path = '/hello/<account_id>/test'
    flask_app = flask.Flask('hello')

    @flask_app.route(path)
    def hello(account_id):
        request = flask.request
        user_agent = request.headers['User-Agent']  # NOQA
        limit = request.args.get('limit', '10')  # NOQA

        return flask.Response(body, headers=headers,
                              mimetype='text/plain')

    return flask_app
base1k.py 文件源码 项目:base1k 作者: xiaq 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def http(host, port):
    from bottle import route, response, run

    @route('/')
    def root():
        return http_root_str

    @route('/<s:path>')
    def do_conversion(s):
        try:
            i = parse_input(s)
        except ValueError as e:
            response.status = 400
            return str(e)
        return convert(i)

    run(host=host, port=port)
test_outputfilter.py 文件源码 项目:Pardus-Bulut 作者: ferhatacikalin 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def test_unicode(self):
        self.app.route('/')(lambda: touni('äöüß'))
        self.assertBody(touni('äöüß').encode('utf8'))

        self.app.route('/')(lambda: [touni('äö'), touni('üß')])
        self.assertBody(touni('äöüß').encode('utf8'))

        @self.app.route('/')
        def test5():
            bottle.response.content_type='text/html; charset=iso-8859-15'
            return touni('äöüß')
        self.assertBody(touni('äöüß').encode('iso-8859-15'))

        @self.app.route('/')
        def test5():
            bottle.response.content_type='text/html'
            return touni('äöüß')
        self.assertBody(touni('äöüß').encode('utf8'))
test_outputfilter.py 文件源码 项目:Pardus-Bulut 作者: ferhatacikalin 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def test_iterator_with_close(self):
        class MyIter(object):
            def __init__(self, data):
                self.data = data
                self.closed = False
            def close(self):    self.closed = True
            def __iter__(self): return iter(self.data)

        byte_iter = MyIter([tob('abc'), tob('def')])
        unicode_iter = MyIter([touni('abc'), touni('def')])

        for test_iter in (byte_iter, unicode_iter):
            @self.app.route('/')
            def test(): return test_iter
            self.assertInBody('abcdef')
            self.assertTrue(byte_iter.closed)
create.py 文件源码 项目:zenchmarks 作者: squeaky-pl 项目源码 文件源码 阅读 34 收藏 0 点赞 0 评论 0
def flask(body, headers):
    import flask

    path = '/hello/<account_id>/test'
    flask_app = flask.Flask('hello')

    @flask_app.route(path)
    def hello(account_id):
        request = flask.request
        user_agent = request.headers['User-Agent']  # NOQA
        limit = request.args.get('limit', '10')  # NOQA

        return flask.Response(body, headers=headers,
                              mimetype='text/plain')

    return flask_app
create.py 文件源码 项目:deb-python-falcon 作者: openstack 项目源码 文件源码 阅读 35 收藏 0 点赞 0 评论 0
def bottle(body, headers):
    import bottle
    path = '/hello/<account_id>/test'

    @bottle.route(path)
    def hello(account_id):
        user_agent = bottle.request.headers['User-Agent']  # NOQA
        limit = bottle.request.query.limit or '10'  # NOQA

        return bottle.Response(body, headers=headers)

    return bottle.default_app()
app.py 文件源码 项目:bottle_beginner 作者: denzow 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def hello():
    """
    route ??????URL???????????????????
    ??????

    ????return???????????????????

    route??????????????????URL??????????????
    :return:
    """
    return "Hello World!"
Api.py 文件源码 项目:experiment-manager 作者: softfire-eu 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def server_static(filename):
    """ route to the css and static files"""
    if ".." in filename:
        return HTTPError(status=403)
    return bottle.static_file(filename, root='%s/static' % get_config('api', 'view-path', '/etc/softfire/views'))


#########
# Utils #
#########
webrouter.py 文件源码 项目:octohook 作者: dsnezhkov 项目源码 文件源码 阅读 16 收藏 0 点赞 0 评论 0
def route_server(self, sconfig):
        resource='/server/'
        if 'web' in sconfig and 'hook_route' in sconfig['web']:
            resource=sconfig['web']['hook_route']
        else:
            logging.error(
                "Webrouter: No valid resource route found. Taking defaults {}".
                    format(resource))
        logging.info("Webrouter: starting routing on {}".format(resource))
        bottle.route(resource, 'POST')(self.wsapp.exf_server)
webrouter.py 文件源码 项目:octohook 作者: dsnezhkov 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def route_client(self, cconfig):
        resource='/client/'
        if 'web' in cconfig and 'hook_route' in cconfig['web']:
            resource=cconfig['web']['hook_route']
        else:
            logging.error(
                "Webrouter: No valid resource route found. Taking defaults {}".
                    format(resource))
        logging.info("Webrouter: starting routing on {}".format(resource))
        bottle.route(resource, 'POST')(self.wsapp.exf_client)
server.py 文件源码 项目:facebook-scrapper 作者: avihai123 项目源码 文件源码 阅读 15 收藏 0 点赞 0 评论 0
def show_posts(page_id):
    return template('templates/posts', title='{} Posts'.format(get_page_name(page_id)), page_list=get_page_list(),
                    post_list=get_posts_ordered_by_popularity(page_id), page_id=page_id)


# @route('/<page_name>/')
# def page_name_posts(page_name):
#     return template('templates/posts', title=page_name, page_list=get_page_list(), post_list=get_posts_ordered_by_popularity('40796308305'), page_id='40796308305')
#                     # post_list=get_posts_ordered_by_popularity(page_id), page_id=page_id)


# TODO fix latest template, broken
test_outputfilter.py 文件源码 项目:Pardus-Bulut 作者: ferhatacikalin 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def test_bytes(self):
        self.app.route('/')(lambda: tob('test'))
        self.assertBody('test')
test_outputfilter.py 文件源码 项目:Pardus-Bulut 作者: ferhatacikalin 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def test_bytearray(self):
        self.app.route('/')(lambda: map(tob, ['t', 'e', 'st']))
        self.assertBody('test')
test_outputfilter.py 文件源码 项目:Pardus-Bulut 作者: ferhatacikalin 项目源码 文件源码 阅读 15 收藏 0 点赞 0 评论 0
def test_tuple(self):
        self.app.route('/')(lambda: ('t', 'e', 'st'))
        self.assertBody('test')
test_outputfilter.py 文件源码 项目:Pardus-Bulut 作者: ferhatacikalin 项目源码 文件源码 阅读 15 收藏 0 点赞 0 评论 0
def test_emptylist(self):
        self.app.route('/')(lambda: [])
        self.assertBody('')
test_outputfilter.py 文件源码 项目:Pardus-Bulut 作者: ferhatacikalin 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def test_none(self):
        self.app.route('/')(lambda: None)
        self.assertBody('')
test_outputfilter.py 文件源码 项目:Pardus-Bulut 作者: ferhatacikalin 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def test_error(self):
        self.app.route('/')(lambda: 1/0)
        self.assertStatus(500)
        self.assertInBody('ZeroDivisionError')
test_outputfilter.py 文件源码 项目:Pardus-Bulut 作者: ferhatacikalin 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def test_fatal_error(self):
        @self.app.route('/')
        def test(): raise KeyboardInterrupt()
        self.assertRaises(KeyboardInterrupt, self.assertStatus, 500)
test_outputfilter.py 文件源码 项目:Pardus-Bulut 作者: ferhatacikalin 项目源码 文件源码 阅读 16 收藏 0 点赞 0 评论 0
def test_file(self):
        self.app.route('/')(lambda: tobs('test'))
        self.assertBody('test')
test_outputfilter.py 文件源码 项目:Pardus-Bulut 作者: ferhatacikalin 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def test_json(self):
        self.app.route('/')(lambda: {'a': 1})
        try:
            self.assertBody(bottle.json_dumps({'a': 1}))
            self.assertHeader('Content-Type','application/json')
        except ImportError:
            warn("Skipping JSON tests.")
test_outputfilter.py 文件源码 项目:Pardus-Bulut 作者: ferhatacikalin 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def test_json_HTTPResponse(self):
        self.app.route('/')(lambda: bottle.HTTPResponse({'a': 1}, 500))
        try:
            self.assertBody(bottle.json_dumps({'a': 1}))
            self.assertHeader('Content-Type','application/json')
        except ImportError:
            warn("Skipping JSON tests.")
test_outputfilter.py 文件源码 项目:Pardus-Bulut 作者: ferhatacikalin 项目源码 文件源码 阅读 16 收藏 0 点赞 0 评论 0
def test_json_HTTPError(self):
        self.app.error(400)(lambda e: e.body)
        self.app.route('/')(lambda: bottle.HTTPError(400, {'a': 1}))
        try:
            self.assertBody(bottle.json_dumps({'a': 1}))
            self.assertHeader('Content-Type','application/json')
        except ImportError:
            warn("Skipping JSON tests.")
test_outputfilter.py 文件源码 项目:Pardus-Bulut 作者: ferhatacikalin 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def test_generator_callback(self):
        @self.app.route('/')
        def test():
            bottle.response.headers['Test-Header'] = 'test'
            yield 'foo'
        self.assertBody('foo')
        self.assertHeader('Test-Header', 'test')
test_outputfilter.py 文件源码 项目:Pardus-Bulut 作者: ferhatacikalin 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def test_empty_generator_callback(self):
        @self.app.route('/')
        def test():
            yield
            bottle.response.headers['Test-Header'] = 'test'
        self.assertBody('')
        self.assertHeader('Test-Header', 'test')
test_outputfilter.py 文件源码 项目:Pardus-Bulut 作者: ferhatacikalin 项目源码 文件源码 阅读 16 收藏 0 点赞 0 评论 0
def test_error_in_generator_callback(self):
        @self.app.route('/')
        def test():
            yield 1/0
        self.assertStatus(500)
        self.assertInBody('ZeroDivisionError')
test_outputfilter.py 文件源码 项目:Pardus-Bulut 作者: ferhatacikalin 项目源码 文件源码 阅读 16 收藏 0 点赞 0 评论 0
def test_httperror_in_generator_callback(self):
        @self.app.route('/')
        def test():
            yield
            bottle.abort(404, 'teststring')
        self.assertInBody('teststring')
        self.assertInBody('404 Not Found')
        self.assertStatus(404)
test_outputfilter.py 文件源码 项目:Pardus-Bulut 作者: ferhatacikalin 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def test_httpresponse_in_generator_callback(self):
        @self.app.route('/')
        def test():
            yield bottle.HTTPResponse('test')
        self.assertBody('test')
test_outputfilter.py 文件源码 项目:Pardus-Bulut 作者: ferhatacikalin 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def test_unicode_generator_callback(self):
        @self.app.route('/')
        def test():
            yield touni('äöüß')
        self.assertBody(touni('äöüß').encode('utf8'))
test_outputfilter.py 文件源码 项目:Pardus-Bulut 作者: ferhatacikalin 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def test_invalid_generator_callback(self):
        @self.app.route('/')
        def test():
            yield 1234
        self.assertStatus(500)
        self.assertInBody('Unsupported response type')
test_auth.py 文件源码 项目:Pardus-Bulut 作者: ferhatacikalin 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def test__header(self):
        @bottle.route('/')
        @bottle.auth_basic(lambda x, y: False)
        def test(): return {}
        self.assertStatus(401)
        self.assertHeader('Www-Authenticate', 'Basic realm="private"')


问题


面经


文章

微信
公众号

扫码关注公众号