Python cherrypy.expose() Examples
The following are 30
code examples of cherrypy.expose().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
cherrypy
, or try the search function
.
Example #1
Source File: test_objectmapping.py From moviegrabber with GNU General Public License v3.0 | 6 votes |
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!")
Example #2
Source File: test_iterator.py From cherrypy with BSD 3-Clause "New" or "Revised" License | 6 votes |
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())
Example #3
Source File: test_etags.py From cherrypy with BSD 3-Clause "New" or "Revised" License | 6 votes |
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)
Example #4
Source File: test_objectmapping.py From cherrypy with BSD 3-Clause "New" or "Revised" License | 6 votes |
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!')
Example #5
Source File: test_core.py From cherrypy with BSD 3-Clause "New" or "Revised" License | 6 votes |
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)
Example #6
Source File: test_params.py From cherrypy with BSD 3-Clause "New" or "Revised" License | 6 votes |
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')
Example #7
Source File: test_conn.py From cherrypy with BSD 3-Clause "New" or "Revised" License | 6 votes |
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, })
Example #8
Source File: test_wsgi_unix_socket.py From cherrypy with BSD 3-Clause "New" or "Revised" License | 6 votes |
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())
Example #9
Source File: test_mime.py From cherrypy with BSD 3-Clause "New" or "Revised" License | 6 votes |
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 #
Example #10
Source File: server.py From ScoutSuite with GNU General Public License v2.0 | 6 votes |
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)
Example #11
Source File: test_wsgi_vhost.py From bazarr with GNU General Public License v3.0 | 6 votes |
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))
Example #12
Source File: test_iterator.py From bazarr with GNU General Public License v3.0 | 6 votes |
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())
Example #13
Source File: test_mime.py From bazarr with GNU General Public License v3.0 | 6 votes |
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 #
Example #14
Source File: test_wsgi_unix_socket.py From bazarr with GNU General Public License v3.0 | 6 votes |
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())
Example #15
Source File: test_conn.py From bazarr with GNU General Public License v3.0 | 6 votes |
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, })
Example #16
Source File: test_core.py From bazarr with GNU General Public License v3.0 | 6 votes |
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)
Example #17
Source File: test_params.py From bazarr with GNU General Public License v3.0 | 6 votes |
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')
Example #18
Source File: test_objectmapping.py From bazarr with GNU General Public License v3.0 | 6 votes |
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!')
Example #19
Source File: test_wsgi_vhost.py From Tautulli with GNU General Public License v3.0 | 6 votes |
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))
Example #20
Source File: test_iterator.py From Tautulli with GNU General Public License v3.0 | 6 votes |
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())
Example #21
Source File: test_mime.py From Tautulli with GNU General Public License v3.0 | 6 votes |
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 #
Example #22
Source File: test_wsgi_unix_socket.py From Tautulli with GNU General Public License v3.0 | 6 votes |
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())
Example #23
Source File: test_conn.py From Tautulli with GNU General Public License v3.0 | 6 votes |
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, })
Example #24
Source File: test_core.py From Tautulli with GNU General Public License v3.0 | 6 votes |
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)
Example #25
Source File: test_params.py From Tautulli with GNU General Public License v3.0 | 6 votes |
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')
Example #26
Source File: test_objectmapping.py From Tautulli with GNU General Public License v3.0 | 6 votes |
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!')
Example #27
Source File: test_etags.py From Tautulli with GNU General Public License v3.0 | 6 votes |
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)
Example #28
Source File: test_wsgi_vhost.py From cherrypy with BSD 3-Clause "New" or "Revised" License | 6 votes |
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))
Example #29
Source File: _cpmodpy.py From cherrypy with BSD 3-Clause "New" or "Revised" License | 5 votes |
def __init__(self, req): for method in self.expose: self.__dict__[method] = getattr(req, method)
Example #30
Source File: test_refleaks.py From bazarr with GNU General Public License v3.0 | 5 votes |
def setup_server(): class Root: @cherrypy.expose def index(self, *args, **kwargs): cherrypy.request.thing = data return 'Hello world!' cherrypy.tree.mount(Root())