本文整理汇总了Python中brubeck.request_handling.Brubeck类的典型用法代码示例。如果您正苦于以下问题:Python Brubeck类的具体用法?Python Brubeck怎么用?Python Brubeck使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Brubeck类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
def setUp(self):
""" will get run for each test """
config = {
'mongrel2_pair': ('ipc://127.0.0.1:9999', 'ipc://127.0.0.1:9998'),
'msg_conn': WSGIConnection()
}
self.app = Brubeck(**config)
示例2: __init__
def __init__(self, settings_file, project_dir,
*args, **kwargs):
""" Most of the parameters are dealt with by Brubeck,
do a little before call to super
"""
if project_dir == None:
raise Exception('missing project_dir from config')
else:
self.project_dir = project_dir
"""load our settings"""
if settings_file != None:
self.settings = self.get_settings_from_file(settings_file)
else:
self.settings = {}
# we may have overriden default mongrel2_pairs in settings
#if 'mongrel2_pair' in self.settings:
# kwargs['mongrel2_pair'] = self.settings['mongrel2_pair']
Brubeck.__init__(self, **kwargs)
示例3: WSGIConnection
"""
Flush the database occasionally.
"""
while True:
chat.flush(db_conn)
coro_lib.sleep(TIMEOUT)
#
# RUN BRUBECK RUN
#
config = {
"msg_conn": WSGIConnection(port=PORT),
"handler_tuples": [
(r"^/$", IndexHandler),
(r"^/rooms$", RoomsHandler),
(r"^/buffer$", BufferHandler),
(r"^/(?P<room>[^/]+)/?$", RoomHandler),
(r"^/(?P<room>[^/]+)/users$", UsersHandler),
(r"^/(?P<room>[^/]+)/messages$", MessagesHandler),
],
"cookie_secret": COOKIE_SECRET,
"db_conn": redis.StrictRedis(db=DB),
"template_loader": load_mustache_env(TEMPLATES_DIR),
}
onionchat = Brubeck(**config)
toilet = onionchat.pool.spawn(drain, onionchat.db_conn)
onionchat.run()
toilet.kill()
示例4: init_db_conn
###
# 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()
示例5: TodosHandler
class TodosHandler(BaseHandler, Jinja2Rendering):
def get(self):
"""A list display matching the parameters of a user's dashboard. The
parameters essentially map to the variation in how `load_listitems` is
called.
"""
return self.render_template("todos.html")
###
### Configuration
###
# Routing config
handler_tuples = [(r"^/$", TodosHandler)]
# Application config
config = {
"mongrel2_pair": ("ipc://127.0.0.1:9999", "ipc://127.0.0.1:9998"),
"handler_tuples": handler_tuples,
"template_loader": load_jinja2_env("."),
}
# Instantiate app instance
app = Brubeck(**config)
app.register_api(TodosAPI)
app.run()
示例6: post
it is ready.
"""
def post(self):
json_request = self.message.body
try:
# connect to backend
sock = CONTEXT.socket(zmq.REQ)
sock.connect(BACKEND_URI)
#request_obj = ast.literal_eval(json_request)
#sock.send_json(request_obj)
sock.send(json_request)
resp = sock.recv()
self.headers['Content-Type'] = 'application/json'
self.set_body(resp)
except Exception as e:
self.set_status(400,
status_msg="Invalid JSON Request: '%s', error '%s'"
% (json_request, e))
return self.render()
config.update({
'mongrel2_pair': (config[RECV_SPEC], config[SEND_SPEC]),
'handler_tuples': [(r'^/request$', RequestHandler)] })
openscrape = Brubeck(**config)
openscrape.run()
示例7: WSGIConnection
self.set_status(204)
else:
self.set_status(400, 'Could not submit move')
else:
self.set_status(400, 'You are not in this game')
return self.render()
###
#
# BRUBECK RUNNER
#
###
config = {
'msg_conn': WSGIConnection(port=PORT),
'handler_tuples': [(r'^/$', GameListHandler),
(r'^/create$', CreateGameHandler),
(r'^/(?P<game_name>[^/]+)$', ForwardToGameHandler),
(r'^/(?P<game_name>[^/]+)/$', GameHandler),
(r'^/(?P<game_name>[^/]+)/join$', JoinHandler),
(r'^/(?P<game_name>[^/]+)/start$', StartHandler),
(r'^/(?P<game_name>[^/]+)/move$', MoveHandler),
(r'^/(?P<game_name>[^/]+)/chat$', ChatHandler)],
'cookie_secret': COOKIE_SECRET,
'db_conn': redis.StrictRedis(db=DB),
'template_loader': load_mustache_env('./templates')
}
opengold = Brubeck(**config)
opengold.run()
示例8: Brubeck
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from brubeck.request_handling import Brubeck
from config import config
le_app = Brubeck(**config)
if __name__ == '__main__':
le_app.run()
示例9: TestRequestHandling
class TestRequestHandling(unittest.TestCase):
"""
a test class for brubeck's request_handler
"""
def setUp(self):
""" will get run for each test """
config = {
'mongrel2_pair': ('ipc://127.0.0.1:9999', 'ipc://127.0.0.1:9998'),
'msg_conn': WSGIConnection()
}
self.app = Brubeck(**config)
##
## our actual tests( test _xxxx_xxxx(self) )
##
def test_add_route_rule_method(self):
# Make sure we have no routes
self.assertEqual(hasattr(self.app,'_routes'),False)
# setup a route
self.setup_route_with_method()
# Make sure we have some routes
self.assertEqual(hasattr(self.app,'_routes'),True)
# Make sure we have exactly one route
self.assertEqual(len(self.app._routes),1)
def test_init_routes_with_methods(self):
# Make sure we have no routes
self.assertEqual(hasattr(self.app, '_routes'), False)
# Create a tuple with routes with method handlers
routes = [ (r'^/', simple_handler_method), (r'^/brubeck', simple_handler_method) ]
# init our routes
self.app.init_routes( routes )
# Make sure we have two routes
self.assertEqual(len(self.app._routes), 2)
def test_init_routes_with_objects(self):
# Make sure we have no routes
self.assertEqual(hasattr(self.app, '_routes'), False)
# Create a tuple of routes with object handlers
routes = [(r'^/', SimpleWebHandlerObject), (r'^/brubeck', SimpleWebHandlerObject)]
self.app.init_routes( routes )
# Make sure we have two routes
self.assertEqual(len(self.app._routes), 2)
def test_init_routes_with_objects_and_methods(self):
# Make sure we have no routes
self.assertEqual(hasattr(self.app, '_routes'), False)
# Create a tuple of routes with a method handler and an object handler
routes = [(r'^/', SimpleWebHandlerObject), (r'^/brubeck', simple_handler_method)]
self.app.init_routes( routes )
# Make sure we have two routes
self.assertEqual(len(self.app._routes), 2)
def test_add_route_rule_object(self):
# Make sure we have no routes
self.assertEqual(hasattr(self.app,'_routes'),False)
self.setup_route_with_object()
# Make sure we have some routes
self.assertEqual(hasattr(self.app,'_routes'),True)
# Make sure we have exactly one route
self.assertEqual(len(self.app._routes),1)
def test_brubeck_handle_request_with_object(self):
# set up our route
self.setup_route_with_object()
# Make sure we get a handler back when we request one
message = MockMessage(path='/')
handler = self.app.route_message(message)
self.assertNotEqual(handler,None)
def test_brubeck_handle_request_with_method(self):
# We ran tests on this already, so assume it works
self.setup_route_with_method()
# Make sure we get a handler back when we request one
message = MockMessage(path='/')
handler = self.app.route_message(message)
self.assertNotEqual(handler,None)
def test_cookie_handling(self):
# set our cookie key and values
cookie_key = 'my_key'
cookie_value = 'my_secret'
# encode our cookie
encoded_cookie = cookie_encode(cookie_value, cookie_key)
# Make sure we do not contain our value (i.e. we are really encrypting)
#.........这里部分代码省略.........
示例10: setUp
def setUp(self):
""" will get run for each test """
config = {
'mongrel2_pair': ('ipc://127.0.0.1:9999', 'ipc://127.0.0.1:9998')
}
self.app = Brubeck(**config)
示例11: load_mustache_env
status = 200
else:
status['error'] = "Instruction does not exist"
status = 404
if self.is_json_request():
self.set_body(json.dumps(context))
self.set_status(status)
return self.render()
else:
return self.render_template('delete_instruction', _status_code=status, **context)
V_C = VALID_URL_CHARS
config = {
'mongrel2_pair': (RECV_SPEC, SEND_SPEC),
'handler_tuples': [
(r'^/?$', IndexHandler),
(r'^/([%s]+)/?$' % V_C, UserHandler),
(r'^/([%s]+)/instructions/?$' % V_C, InstructionCollectionHandler),
(r'^/([%s]+)/instructions/([%s]+)/?$' % (V_C, V_C), InstructionModelHandler),
(r'^/([%s]+)/tagged/([%s]+)/?$' % (V_C, V_C), TagCollectionHandler)],
'template_loader': load_mustache_env(TEMPLATE_DIR),
'cookie_secret': COOKIE_SECRET,
}
app = Brubeck(**config)
db = get_db(DB_HOST, DB_PORT, DB_NAME)
app.users = Users(db)
app.instructions = Instructions(app.users, JsonGitRepository(JSON_GIT_DIR), db)
app.run()