当前位置: 首页>>代码示例>>Python>>正文


Python cherrypy.expose方法代码示例

本文整理汇总了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)) 
开发者ID:cherrypy,项目名称:cherrypy,代码行数:21,代码来源:test_wsgi_vhost.py

示例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()) 
开发者ID:cherrypy,项目名称:cherrypy,代码行数:22,代码来源:test_iterator.py

示例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                             # 
开发者ID:cherrypy,项目名称:cherrypy,代码行数:24,代码来源:test_mime.py

示例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()) 
开发者ID:cherrypy,项目名称:cherrypy,代码行数:18,代码来源:test_wsgi_unix_socket.py

示例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,
    }) 
开发者ID:cherrypy,项目名称:cherrypy,代码行数:19,代码来源:test_conn.py

示例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) 
开发者ID:cherrypy,项目名称:cherrypy,代码行数:27,代码来源:test_core.py

示例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') 
开发者ID:cherrypy,项目名称:cherrypy,代码行数:19,代码来源:test_params.py

示例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!') 
开发者ID:cherrypy,项目名称:cherrypy,代码行数:21,代码来源:test_objectmapping.py

示例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) 
开发者ID:cherrypy,项目名称:cherrypy,代码行数:27,代码来源:test_etags.py

示例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) 
开发者ID:nccgroup,项目名称:ScoutSuite,代码行数:24,代码来源:server.py

示例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()) 
开发者ID:morpheus65535,项目名称:bazarr,代码行数:22,代码来源:test_iterator.py

示例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) 
开发者ID:morpheus65535,项目名称:bazarr,代码行数:27,代码来源:test_core.py

示例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!") 
开发者ID:binhex,项目名称:moviegrabber,代码行数:21,代码来源:test_objectmapping.py

示例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) 
开发者ID:cherrypy,项目名称:cherrypy,代码行数:5,代码来源:_cpmodpy.py

示例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()) 
开发者ID:cherrypy,项目名称:cherrypy,代码行数:32,代码来源:test_sessionauthenticate.py


注:本文中的cherrypy.expose方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。