本文整理匯總了Python中cherrypy.expose方法的典型用法代碼示例。如果您正苦於以下問題:Python cherrypy.expose方法的具體用法?Python cherrypy.expose怎麽用?Python cherrypy.expose使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類cherrypy
的用法示例。
在下文中一共展示了cherrypy.expose方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: setup_server
# 需要導入模塊: import cherrypy [as 別名]
# 或者: from cherrypy import expose [as 別名]
def setup_server():
class ClassOfRoot(object):
def __init__(self, name):
self.name = name
@cherrypy.expose
def index(self):
return 'Welcome to the %s website!' % self.name
default = cherrypy.Application(None)
domains = {}
for year in range(1997, 2008):
app = cherrypy.Application(ClassOfRoot('Class of %s' % year))
domains['www.classof%s.example' % year] = app
cherrypy.tree.graft(cherrypy._cpwsgi.VirtualHost(default, domains))
示例2: setup_server
# 需要導入模塊: import cherrypy [as 別名]
# 或者: from cherrypy import expose [as 別名]
def setup_server():
class Root(object):
@cherrypy.expose
def count(self, clsname):
cherrypy.response.headers['Content-Type'] = 'text/plain'
return str(globals()[clsname].created)
@cherrypy.expose
def getall(self, clsname):
cherrypy.response.headers['Content-Type'] = 'text/plain'
return globals()[clsname]()
@cherrypy.expose
@cherrypy.config(**{'response.stream': True})
def stream(self, clsname):
return self.getall(clsname)
cherrypy.tree.mount(Root())
示例3: setup_server
# 需要導入模塊: import cherrypy [as 別名]
# 或者: from cherrypy import expose [as 別名]
def setup_server():
class Root:
@cherrypy.expose
def multipart(self, parts):
return repr(parts)
@cherrypy.expose
def multipart_form_data(self, **kwargs):
return repr(list(sorted(kwargs.items())))
@cherrypy.expose
def flashupload(self, Filedata, Upload, Filename):
return ('Upload: %s, Filename: %s, Filedata: %r' %
(Upload, Filename, Filedata.file.read()))
cherrypy.config.update({'server.max_request_body_size': 0})
cherrypy.tree.mount(Root())
# Client-side code #
示例4: setup_server
# 需要導入模塊: import cherrypy [as 別名]
# 或者: from cherrypy import expose [as 別名]
def setup_server():
class Root(object):
@cherrypy.expose
def index(self):
return 'Test OK'
@cherrypy.expose
def error(self):
raise Exception('Invalid page')
config = {
'server.socket_file': USOCKET_PATH
}
cherrypy.config.update(config)
cherrypy.tree.mount(Root())
示例5: setup_upload_server
# 需要導入模塊: import cherrypy [as 別名]
# 或者: from cherrypy import expose [as 別名]
def setup_upload_server():
class Root:
@cherrypy.expose
def upload(self):
if not cherrypy.request.method == 'POST':
raise AssertionError("'POST' != request.method %r" %
cherrypy.request.method)
return "thanks for '%s'" % tonative(cherrypy.request.body.read())
cherrypy.tree.mount(Root())
cherrypy.config.update({
'server.max_request_body_size': 1001,
'server.socket_timeout': 10,
'server.accepted_queue_size': 5,
'server.accepted_queue_timeout': 0.1,
})
示例6: setup_server
# 需要導入模塊: import cherrypy [as 別名]
# 或者: from cherrypy import expose [as 別名]
def setup_server():
def break_header():
# Add a header after finalize that is invalid
cherrypy.serving.response.header_list.append((2, 3))
cherrypy.tools.break_header = cherrypy.Tool(
'on_end_resource', break_header)
class Root:
@cherrypy.expose
def index(self):
return 'hello'
@cherrypy.config(**{'tools.break_header.on': True})
def start_response_error(self):
return 'salud!'
@cherrypy.expose
def stat(self, path):
with cherrypy.HTTPError.handle(OSError, 404):
os.stat(path)
root = Root()
cherrypy.tree.mount(root)
示例7: test_syntax
# 需要導入模塊: import cherrypy [as 別名]
# 或者: from cherrypy import expose [as 別名]
def test_syntax(self):
if sys.version_info < (3,):
return self.skip('skipped (Python 3 only)')
code = textwrap.dedent("""
class Root:
@cherrypy.expose
@cherrypy.tools.params()
def resource(self, limit: int):
return type(limit).__name__
conf = {'/': {'tools.params.on': True}}
cherrypy.tree.mount(Root(), config=conf)
""")
exec(code)
self.getPage('/resource?limit=0')
self.assertStatus(200)
self.assertBody('int')
示例8: testExpose
# 需要導入模塊: import cherrypy [as 別名]
# 或者: from cherrypy import expose [as 別名]
def testExpose(self):
# Test the cherrypy.expose function/decorator
self.getPage('/exposing/base')
self.assertBody('expose works!')
self.getPage('/exposing/1')
self.assertBody('expose works!')
self.getPage('/exposing/2')
self.assertBody('expose works!')
self.getPage('/exposingnew/base')
self.assertBody('expose works!')
self.getPage('/exposingnew/1')
self.assertBody('expose works!')
self.getPage('/exposingnew/2')
self.assertBody('expose works!')
示例9: setup_server
# 需要導入模塊: import cherrypy [as 別名]
# 或者: from cherrypy import expose [as 別名]
def setup_server():
class Root:
@cherrypy.expose
def resource(self):
return 'Oh wah ta goo Siam.'
@cherrypy.expose
def fail(self, code):
code = int(code)
if 300 <= code <= 399:
raise cherrypy.HTTPRedirect([], code)
else:
raise cherrypy.HTTPError(code)
@cherrypy.expose
# In Python 3, tools.encode is on by default
@cherrypy.config(**{'tools.encode.on': True})
def unicoded(self):
return ntou('I am a \u1ee4nicode string.', 'escape')
conf = {'/': {'tools.etags.on': True,
'tools.etags.autotags': True,
}}
cherrypy.tree.mount(Root(), config=conf)
示例10: init
# 需要導入模塊: import cherrypy [as 別名]
# 或者: from cherrypy import expose [as 別名]
def init(database_filename, host, port):
"""
Configure and starts the server.
:param database_filename: Location of the database file.
:param host: Address on which to listen.
:param port: Port on which to listen.
"""
cherrypy_cors.install()
config = {
'/': {
'cors.expose.on': True,
'tools.sessions.on': True,
'tools.response_headers.on': True,
'tools.response_headers.headers': [('Content-Type', 'text/plain')],
},
}
cherrypy.config.update({
'server.socket_host': host,
'server.socket_port': port,
})
cherrypy.quickstart(Server(database_filename), "/api", config=config)
示例11: setup_server
# 需要導入模塊: import cherrypy [as 別名]
# 或者: from cherrypy import expose [as 別名]
def setup_server():
class Root(object):
@cherrypy.expose
def count(self, clsname):
cherrypy.response.headers['Content-Type'] = 'text/plain'
return six.text_type(globals()[clsname].created)
@cherrypy.expose
def getall(self, clsname):
cherrypy.response.headers['Content-Type'] = 'text/plain'
return globals()[clsname]()
@cherrypy.expose
@cherrypy.config(**{'response.stream': True})
def stream(self, clsname):
return self.getall(clsname)
cherrypy.tree.mount(Root())
示例12: setup_server
# 需要導入模塊: import cherrypy [as 別名]
# 或者: from cherrypy import expose [as 別名]
def setup_server():
def break_header():
# Add a header after finalize that is invalid
cherrypy.serving.response.header_list.append((2, 3))
cherrypy.tools.break_header = cherrypy.Tool(
'on_end_resource', break_header)
class Root:
@cherrypy.expose
def index(self):
return 'hello'
@cherrypy.config(**{'tools.break_header.on': True})
def start_response_error(self):
return 'salud!'
@cherrypy.expose
def stat(self, path):
with cherrypy.HTTPError.handle(OSError, 404):
st = os.stat(path)
root = Root()
cherrypy.tree.mount(root)
示例13: testExpose
# 需要導入模塊: import cherrypy [as 別名]
# 或者: from cherrypy import expose [as 別名]
def testExpose(self):
# Test the cherrypy.expose function/decorator
self.getPage("/exposing/base")
self.assertBody("expose works!")
self.getPage("/exposing/1")
self.assertBody("expose works!")
self.getPage("/exposing/2")
self.assertBody("expose works!")
self.getPage("/exposingnew/base")
self.assertBody("expose works!")
self.getPage("/exposingnew/1")
self.assertBody("expose works!")
self.getPage("/exposingnew/2")
self.assertBody("expose works!")
示例14: __init__
# 需要導入模塊: import cherrypy [as 別名]
# 或者: from cherrypy import expose [as 別名]
def __init__(self, req):
for method in self.expose:
self.__dict__[method] = getattr(req, method)
示例15: setup_server
# 需要導入模塊: import cherrypy [as 別名]
# 或者: from cherrypy import expose [as 別名]
def setup_server():
def check(username, password):
# Dummy check_username_and_password function
if username != 'test' or password != 'password':
return 'Wrong login/password'
def augment_params():
# A simple tool to add some things to request.params
# This is to check to make sure that session_auth can handle
# request params (ticket #780)
cherrypy.request.params['test'] = 'test'
cherrypy.tools.augment_params = cherrypy.Tool(
'before_handler', augment_params, None, priority=30)
class Test:
_cp_config = {
'tools.sessions.on': True,
'tools.session_auth.on': True,
'tools.session_auth.check_username_and_password': check,
'tools.augment_params.on': True,
}
@cherrypy.expose
def index(self, **kwargs):
return 'Hi %s, you are logged in' % cherrypy.request.login
cherrypy.tree.mount(Test())