本文整理汇总了Python中web.application函数的典型用法代码示例。如果您正苦于以下问题:Python application函数的具体用法?Python application怎么用?Python application使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了application函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: testCustomNotFound
def testCustomNotFound(self):
urls_a = ("/", "a")
urls_b = ("/", "b")
app_a = web.application(urls_a, locals())
app_b = web.application(urls_b, locals())
app_a.notfound = lambda: web.HTTPError("404 Not Found", {}, "not found 1")
urls = (
"/a", app_a,
"/b", app_b
)
app = web.application(urls, locals())
def assert_notfound(path, message):
response = app.request(path)
self.assertEquals(response.status.split()[0], "404")
self.assertEquals(response.data, message)
assert_notfound("/a/foo", b"not found 1")
assert_notfound("/b/foo", b"not found")
app.notfound = lambda: web.HTTPError("404 Not Found", {}, "not found 2")
assert_notfound("/a/foo", b"not found 1")
assert_notfound("/b/foo", b"not found 2")
开发者ID:FrankSun0634,项目名称:webpy,代码行数:26,代码来源:application.py
示例2: test_redirect
def test_redirect(self):
urls = ("/(.*)", "blog")
class blog:
def GET(self, path):
if path == "foo":
raise web.seeother("/login", absolute=True)
else:
raise web.seeother("/bar")
app_blog = web.application(urls, locals())
urls = ("/blog", app_blog, "/(.*)", "index")
class index:
def GET(self, path):
return "hello " + path
app = web.application(urls, locals())
response = app.request("/blog/foo")
self.assertEquals(response.headers["Location"], "http://0.0.0.0:8080/login")
response = app.request("/blog/foo", env={"SCRIPT_NAME": "/x"})
self.assertEquals(response.headers["Location"], "http://0.0.0.0:8080/x/login")
response = app.request("/blog/foo2")
self.assertEquals(response.headers["Location"], "http://0.0.0.0:8080/blog/bar")
response = app.request("/blog/foo2", env={"SCRIPT_NAME": "/x"})
self.assertEquals(response.headers["Location"], "http://0.0.0.0:8080/x/blog/bar")
开发者ID:hyh626,项目名称:webpy,代码行数:31,代码来源:application.py
示例3: test_redirect
def test_redirect(self):
urls = (
"/(.*)", "blog"
)
class blog:
def GET(self, path):
if path == 'foo':
raise web.seeother('/login', absolute=True)
else:
raise web.seeother('/bar')
app_blog = web.application(urls, locals())
urls = (
"/blog", app_blog,
"/(.*)", "index"
)
class index:
def GET(self, path):
return "hello " + path
app = web.application(urls, locals())
response = app.request('/blog/foo')
self.assertEquals(response.headers['Location'], 'http://0.0.0.0:8080/login')
response = app.request('/blog/foo', env={'SCRIPT_NAME': '/x'})
self.assertEquals(response.headers['Location'], 'http://0.0.0.0:8080/x/login')
response = app.request('/blog/foo2')
self.assertEquals(response.headers['Location'], 'http://0.0.0.0:8080/blog/bar')
response = app.request('/blog/foo2', env={'SCRIPT_NAME': '/x'})
self.assertEquals(response.headers['Location'], 'http://0.0.0.0:8080/x/blog/bar')
开发者ID:yejun,项目名称:webpy,代码行数:32,代码来源:application.py
示例4: test_processors
def test_processors(self):
urls = (
"/(.*)", "blog"
)
class blog:
def GET(self, path):
return 'blog ' + path
state = web.storage(x=0, y=0)
def f():
state.x += 1
app_blog = web.application(urls, locals())
app_blog.add_processor(web.loadhook(f))
urls = (
"/blog", app_blog,
"/(.*)", "index"
)
class index:
def GET(self, path):
return "hello " + path
app = web.application(urls, locals())
def g():
state.y += 1
app.add_processor(web.loadhook(g))
app.request('/blog/foo')
assert state.x == 1 and state.y == 1, repr(state)
app.request('/foo')
assert state.x == 1 and state.y == 2, repr(state)
开发者ID:yejun,项目名称:webpy,代码行数:31,代码来源:application.py
示例5: test_subdirs
def test_subdirs(self):
urls = (
"/(.*)", "blog"
)
class blog:
def GET(self, path):
return "blog " + path
app_blog = web.application(urls, locals())
urls = (
"/blog", app_blog,
"/(.*)", "index"
)
class index:
def GET(self, path):
return "hello " + path
app = web.application(urls, locals())
self.assertEquals(app.request('/blog/foo').data, 'blog foo')
self.assertEquals(app.request('/foo').data, 'hello foo')
def processor(handler):
return web.ctx.path + ":" + handler()
app.add_processor(processor)
self.assertEquals(app.request('/blog/foo').data, '/blog/foo:blog foo')
开发者ID:yejun,项目名称:webpy,代码行数:25,代码来源:application.py
示例6: get_app
def get_app(config_file):
""" Get the application. config_file is the path to the configuration file """
frontend.configuration.INGIniousConfiguration.load(config_file)
if frontend.configuration.INGIniousConfiguration.get("maintenance", False):
appli = web.application(urls_maintenance, globals(), autoreload=False)
return appli
appli = web.application(urls, globals(), autoreload=False)
frontend.base.init_database()
update_database()
frontend.session.init(appli)
def not_found():
""" Display the error 404 page """
return web.notfound(frontend.base.renderer.notfound('Page not found'))
appli.notfound = not_found
plugin_manager = PluginManager(appli, frontend.configuration.INGIniousConfiguration.get("plugins", []))
# Plugin Manager is also a Hook Manager
backend_interface.init(plugin_manager)
# Loads template_helper
TemplateHelper()
# Loads plugins
plugin_manager.load()
# Start the backend
backend_interface.start()
return appli
开发者ID:jonsan21,项目名称:INGInious,代码行数:34,代码来源:app.py
示例7: main
def main():
"""<comment-ja>
Web Application 起動処理
</comment-ja>
<comment-en>
TODO: English Comment
</comment-en>
"""
# logging load
karesansui.lib.log.logger.reload_conf(karesansui.config['application.log.config'])
if karesansui.lib.log.logger.is_ready() is False:
raise karesansui.lib.log.logger.KaresansuiLogError("""Warning!!
Logging set initial startup failed.
example : Does the log configuration file exist?
The present file path : %s
""" % karesansui.config['application.log.config'])
logger = logging.getLogger('karesansui.app')
logger_trace = logging.getLogger('karesansui_trace.app')
if not os.popen("ps -eo cmd | grep -e ^libvirtd -e ^/usr/sbin/libvirtd").read():
logger.error('libvirtd not running."/etc/init.d/libvirtd start" Please start.')
print >>sys.stderr, '[Error] libvirtd not running."/etc/init.d/libvirtd start" Please start.'
sys.exit(1)
if web.wsgi._is_dev_mode() is True and env.has_key('FCGI') is False:
logger.info('Start Mode [development]')
app = web.application(urls, globals(), autoreload=True)
app.internalerror = web.debugerror
sys.argv = [] # argv clear
else:
logger.info('Start Mode [fastcgi]')
web.config.debug = False
app = web.application(urls, globals(), autoreload=False)
#sys.argv = [] # argv clear
# load processor!
# - karesansui database!
app.add_processor(load_sqlalchemy_karesansui)
logger.info('The load was added. - load_sqlalchemy_karesansui')
# - pysilhouette database!
app.add_processor(load_sqlalchemy_pysilhouette)
logger.info('The load was added. - load_sqlalchemy_pysilhouette')
# http://domain/(../..)/hoge
if karesansui.config['application.url.prefix']:
mapping = (karesansui.config['application.url.prefix'], app)
app = web.subdir_application(mapping)
try:
if (not opts is None) and opts.shell is True: # shell mode!!
shell()
else:
app.run() # Web Application Start!
except Exception, e:
logger_trace.critical(traceback.format_exc())
print >>sys.stderr, "[ERROR] %s" % str(e.args)
print >>sys.stderr, traceback.format_exc()
return 1
开发者ID:goura,项目名称:karesansui,代码行数:59,代码来源:app.py
示例8: main
def main():
#if __name__=="__main__":
#sys.argv.append("5940")
#Because web.py expects the port to be passed on argv[1] I will replace it here. The original argv[1] is '--genconf'
sys.argv[1]='5940'
print "Starting web.py at port 5940..."
web.internalerror = web.debugerror
# Start timer thread to run after 5 seconds
print 'Waiting for page to load in browser...'
threading.Timer(5.0, open_page).start()
web.application(urls, globals()).run()
开发者ID:pombredanne,项目名称:harvestman-crawler-2,代码行数:11,代码来源:genconfig.py
示例9: main
def main():
#/ PYTHONPATH bootstrap
my_pp_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
## |pp| means PYTHONPATH
if my_pp_dir not in sys.path:
sys.path.insert(0, my_pp_dir)
#/
import aoikwebpystart.urlstohdlrs as urlstohdlrs
#/
parser = ArgumentParser(add_help=False)
parser.add_argument(
'-o', '--host',
default='127.0.0.1',
)
parser.add_argument(
'-p', '--port',
type=int,
default=8000,
)
parser.add_argument(
'-w', '--wsgi',
dest='wsgi_on',
action='store_true',
)
args_obj, _ = parser.parse_known_args()
#/
wsgi_on = args_obj.wsgi_on
if wsgi_on:
host = args_obj.host
port = args_obj.port
wsgi_app = web.application(urlstohdlrs.SPEC_S).wsgifunc()
#/
print('HTTP is on: {}:{}'.format(host, port))
srvr = make_server(host, port, wsgi_app)
srvr.serve_forever()
else:
app = web.application(urlstohdlrs.SPEC_S)
app.run()
开发者ID:AoiKuiyuyou,项目名称:AoikWebpyStart,代码行数:52,代码来源:main.py
示例10: init_app
def init_app(root, logger):
abs_root = abspath(root)
node = root_node(abs_root)
URLS = ('/(.*)', 'handler')
return application(URLS, { 'handler': Handler(node, logger) })
开发者ID:itayd,项目名称:w,代码行数:7,代码来源:__init__.py
示例11: application
def application(urls, env):
'''
A pythonic web.py application
def hello(ctx, name):
if not name:
name = 'World'
return 'Hello, ' + name + '!'
urls = ('GET', '/(.*)', hello)
app = application(urls, locals())
'''
def webpy_handler_class(method, pattern, handler):
''' convert functional view to class based view consumable by rest of webpy '''
class _Handler:
pass
def wrap(_handler):
def wrapped(self, *args, **kwargs):
return _handler(web.ctx, *args, **kwargs)
return wrapped
_Handler.__dict__[method] = wrap(handler)
env[handler.__name__] = _Handler
return pattern, handler.__name__
def compile_to_webpy(urls):
''' convert to webpy format '''
return [component
for method, pattern, handler in urls
for component in webpy_handler_class(method, pattern, handler) ]
app = web.application(compile_to_webpy(chunk_urls(urls)), env)
app.add_processor(web.loadhook(hook_less(app)))
return app
开发者ID:pavanmishra,项目名称:lesswebpy,代码行数:31,代码来源:lessweb.py
示例12: run
def run(self):
port = 8080
app = web.application(self.urls, {
'bot':self.bot,
'bot_commands':self.bot_commands,
'bot_status_all':self.bot_status_all})
web.httpserver.runsimple(app.wsgifunc(), ("0.0.0.0", self.port))
开发者ID:toxtli,项目名称:chat-bots-manager,代码行数:7,代码来源:ChatBot.py
示例13: serve_http
def serve_http(hostname, port):
"""Starts the HTTP web server at the specified socket."""
sys.argv.insert(1, "%s:%s" % (hostname, port))
logging.info("Starting the ardj web service at http://%s:%s/" % (hostname, port))
if "--debug" not in sys.argv:
ScrobblerThread().start()
app = web.application((
"/", IndexController,
"/api/auth(?:\.json)?", AuthController,
"/api/status\.js(?:on)?", StatusController,
"/api/tag/cloud\.json", TagCloudController,
"/api/track/info\.json", InfoController,
"/api/track/rocks\.json", RocksController,
"/api/track/sucks\.json", SucksController,
"/commit\.json", CommitController,
"/raise", RaiseController,
"/track/info\.js(?:on)?", InfoController,
"/track/next\.json", NextController,
"/track/queue\.json", QueueController,
"/track/recent\.js(?:on)?", RecentController,
"/track/search\.json", SearchController,
))
app.run(ExceptionHandlingMiddleWare)
开发者ID:Alwnikrotikz,项目名称:ardj,代码行数:26,代码来源:server.py
示例14: init_app
def init_app():
app = web.application(urls, globals())
#app.notfound = api_notfound
#app.internalerror = api_internalerror
app.add_processor(web.loadhook(api_loadhook))
app.add_processor(web.unloadhook(api_unloadhook))
return app
开发者ID:gaotianpu,项目名称:todolist,代码行数:7,代码来源:api.py
示例15: server_thread
def server_thread(urls, funcs):
""" thread for running the web server """
from x84.bbs import ini
from web.wsgiserver import CherryPyWSGIServer
from web.wsgiserver.ssl_pyopenssl import pyOpenSSLAdapter
from OpenSSL import SSL
cert, key, chain = None, None, None
if ini.CFG.has_option('web', 'cert'):
cert = ini.CFG.get('web', 'cert')
if ini.CFG.has_option('web', 'key'):
key = ini.CFG.get('web', 'key')
if ini.CFG.has_option('web', 'chain'):
chain = ini.CFG.get('web', 'chain')
CherryPyWSGIServer.ssl_adapter = pyOpenSSLAdapter(cert, key, chain)
CherryPyWSGIServer.ssl_adapter.context = SSL.Context(SSL.SSLv23_METHOD)
CherryPyWSGIServer.ssl_adapter.context.set_options(SSL.OP_NO_SSLv3)
CherryPyWSGIServer.ssl_adapter.context.use_certificate_file(cert)
CherryPyWSGIServer.ssl_adapter.context.use_privatekey_file(key)
if chain:
CherryPyWSGIServer.ssl_adapter.context.use_certificate_chain_file(chain)
CherryPyWSGIServer.ssl_adapter.context.set_cipher_list('ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:DH+3DES:RSA+AESGCM:RSA+AES:RSA+3DES:!aNULL:!MD5:!DSS')
app = web.application(urls, funcs)
addr = (ini.CFG.get('web', 'addr'), ini.CFG.getint('web', 'port'))
web.httpserver.runsimple(app.wsgifunc(), addr)
开发者ID:ztaylor,项目名称:x84,代码行数:30,代码来源:webserve.py
示例16: run
def run(self):
urls = []
views = {}
for id, view in self._views.iteritems():
for pattern in view['patterns']:
urls.extend([pattern, id])
views[id] = makeBoundedViewType(self, view['view'])
web.config.debug = self._conf['debug']
if not urls:
raise Exception("No Url registered")
elif not views:
raise Exception("No views registered")
it = iter(urls)
print "Published urls:"
for url in it:
print " - '%s'" % url
it.next()
app = web.application(urls, views)
if self._conf['debug']:
app.internalerror = web.debugerror
# enable fastcgi
if self.conf.get('fastcgi') is True:
web.wsgi.runwsgi = lambda func, addr=None: web.wsgi.runfcgi(func, addr)
self._is_running = True
app.run()
开发者ID:hotgloupi,项目名称:troll,代码行数:29,代码来源:application.py
示例17: testUnicodeInput
def testUnicodeInput(self):
urls = (
"(/.*)", "foo"
)
class foo:
def GET(self, path):
i = web.input(name='')
return repr(i.name)
def POST(self, path):
if path == '/multipart':
i = web.input(file={})
return i.file.value
else:
i = web.input()
return repr(dict(i))
app = web.application(urls, locals())
def f(name):
path = '/?' + urllib.urlencode({"name": name})
self.assertEquals(app.request(path).data, repr(name))
f(u'\u1234')
f(u'foo')
response = app.request('/', method='POST', data=dict(name='foo'))
self.assertEquals(response.data, "{'name': u'foo'}")
data = '--boundary\r\nContent-Disposition: form-data; name="x"\r\nfoo\r\n--boundary\r\nContent-Disposition: form-data; name="file"; filename="a.txt"\r\nContent-Type: text/plain\r\n\r\na\r\n--boundary--\r\n'
headers = {'Content-Type': 'multipart/form-data; boundary=boundary'}
response = app.request('/multipart', method="POST", data=data, headers=headers)
self.assertEquals(response.data, 'a')
开发者ID:bmiles,项目名称:molecular-weight,代码行数:33,代码来源:application.py
示例18: getApplication
def getApplication(orm_cls):
class lst(BaseListController):
ORM_CLS = orm_cls
class show(BaseShowController):
ORM_CLS = orm_cls
class deletectl(BaseDeleteController):
ORM_CLS = orm_cls
class new(BaseController):
ID = orm_cls.__name__.lower()
TITLE = 'New %s'%orm_cls.__name__
ORM_CLS = orm_cls
urls = (
"/", lst,
"/new", new,
"/([0-9]+)", show,
"/delete", deletectl
)
return web.application(urls, locals())
开发者ID:dolfandringa,项目名称:biodata,代码行数:27,代码来源:dynamic_controller.py
示例19: webpy_run
def webpy_run(msg):
print msg
webpy_app = web.application(urls,globals())
webpy_app.notfound = nf#自定义未找到页面
webpy_app.internalerror = ine#自定义 500 错误消息
webpy_app.run()
print 'webpy bay!'
开发者ID:hsp86,项目名称:Search_file,代码行数:7,代码来源:webpy_main.py
示例20: __new__
def __new__(cls, *args, **kwargs):
app = web.application(*args, **kwargs)
app.add_processor(web.loadhook(cls._connect))
app.add_processor(web.unloadhook(cls._disconnect))
return app
开发者ID:AmitShah,项目名称:numenta-apps,代码行数:7,代码来源:__init__.py
注:本文中的web.application函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论