當前位置: 首頁>>代碼示例>>Python>>正文


Python pecan.expose方法代碼示例

本文整理匯總了Python中pecan.expose方法的典型用法代碼示例。如果您正苦於以下問題:Python pecan.expose方法的具體用法?Python pecan.expose怎麽用?Python pecan.expose使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pecan的用法示例。


在下文中一共展示了pecan.expose方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_nested_cells

# 需要導入模塊: import pecan [as 別名]
# 或者: from pecan import expose [as 別名]
def test_nested_cells(self):

        def before(handler):
            def deco(f):
                def wrapped(*args, **kwargs):
                    if callable(handler):
                        handler()
                    return f(*args, **kwargs)
                return wrapped
            return deco

        class RootController(object):
            @expose()
            @before(lambda: True)
            def index(self, a, b, c):
                return 'Hello, World!'

        argspec = util._cfg(RootController.index)['argspec']
        assert argspec.args == ['self', 'a', 'b', 'c'] 
開發者ID:pecan,項目名稱:pecan,代碼行數:21,代碼來源:test_util.py

示例2: test_class_based_decorator

# 需要導入模塊: import pecan [as 別名]
# 或者: from pecan import expose [as 別名]
def test_class_based_decorator(self):

        class deco(object):

            def __init__(self, arg):
                self.arg = arg

            def __call__(self, f):
                @functools.wraps(f)
                def wrapper(*args, **kw):
                    assert self.arg == '12345'
                    return f(*args, **kw)
                return wrapper

        class RootController(object):
            @expose()
            @deco('12345')
            def index(self, a, b, c):
                return 'Hello, World!'

        argspec = util._cfg(RootController.index)['argspec']
        assert argspec.args == ['self', 'a', 'b', 'c'] 
開發者ID:pecan,項目名稱:pecan,代碼行數:24,代碼來源:test_util.py

示例3: test_simple_jsonify

# 需要導入模塊: import pecan [as 別名]
# 或者: from pecan import expose [as 別名]
def test_simple_jsonify(self):
        Person = make_person()

        # register a generic JSON rule
        @jsonify.when_type(Person)
        def jsonify_person(obj):
            return dict(
                name=obj.name
            )

        class RootController(object):
            @expose('json')
            def index(self):
                # create a Person instance
                p = Person('Jonathan', 'LaCour')
                return p

        app = TestApp(Pecan(RootController()))

        r = app.get('/')
        assert r.status_int == 200
        assert loads(r.body.decode()) == {'name': 'Jonathan LaCour'} 
開發者ID:pecan,項目名稱:pecan,代碼行數:24,代碼來源:test_jsonify.py

示例4: test_simple_generic

# 需要導入模塊: import pecan [as 別名]
# 或者: from pecan import expose [as 別名]
def test_simple_generic(self):
        class RootController(object):
            @expose(generic=True)
            def index(self):
                pass

            @index.when(method='POST', template='json')
            def do_post(self):
                return dict(result='POST')

            @index.when(method='GET')
            def do_get(self):
                return 'GET'

        app = TestApp(Pecan(RootController()))
        r = app.get('/')
        assert r.status_int == 200
        assert r.body == b_('GET')

        r = app.post('/')
        assert r.status_int == 200
        assert r.body == b_(dumps(dict(result='POST')))

        r = app.get('/do_get', status=404)
        assert r.status_int == 404 
開發者ID:pecan,項目名稱:pecan,代碼行數:27,代碼來源:test_generic.py

示例5: test_nested_generic

# 需要導入模塊: import pecan [as 別名]
# 或者: from pecan import expose [as 別名]
def test_nested_generic(self):

        class SubSubController(object):
            @expose(generic=True)
            def index(self):
                return 'GET'

            @index.when(method='DELETE', template='json')
            def do_delete(self, name, *args):
                return dict(result=name, args=', '.join(args))

        class SubController(object):
            sub = SubSubController()

        class RootController(object):
            sub = SubController()

        app = TestApp(Pecan(RootController()))
        r = app.get('/sub/sub/')
        assert r.status_int == 200
        assert r.body == b_('GET')

        r = app.delete('/sub/sub/joe/is/cool')
        assert r.status_int == 200
        assert r.body == b_(dumps(dict(result='joe', args='is, cool'))) 
開發者ID:pecan,項目名稱:pecan,代碼行數:27,代碼來源:test_generic.py

示例6: test_generics_not_allowed

# 需要導入模塊: import pecan [as 別名]
# 或者: from pecan import expose [as 別名]
def test_generics_not_allowed(self):

        class C(object):

            def _default(self):
                pass

            def _lookup(self):
                pass

            def _route(self):
                pass

        for method in (C._default, C._lookup, C._route):
            self.assertRaises(
                ValueError,
                expose(generic=True),
                getattr(method, '__func__', method)
            ) 
開發者ID:pecan,項目名稱:pecan,代碼行數:21,代碼來源:test_generic.py

示例7: setUp

# 需要導入模塊: import pecan [as 別名]
# 或者: from pecan import expose [as 別名]
def setUp(self):
        super(SecureControllerSharedPermissionsRegression, self).setUp()

        class Parent(object):
            @expose()
            def index(self):
                return 'hello'

        class UnsecuredChild(Parent):
            pass

        class SecureChild(Parent, SecureController):
            @classmethod
            def check_permissions(cls):
                return False

        class RootController(object):

            secured = SecureChild()
            unsecured = UnsecuredChild()

        self.app = TestApp(make_app(RootController())) 
開發者ID:pecan,項目名稱:pecan,代碼行數:24,代碼來源:test_secure.py

示例8: root

# 需要導入模塊: import pecan [as 別名]
# 或者: from pecan import expose [as 別名]
def root(self):
        class RootController(object):
            @expose()
            def index(self, req, resp):
                assert isinstance(req, webob.BaseRequest)
                assert isinstance(resp, webob.Response)
                return 'Hello, World!'

            @expose()
            def warning(self):
                return ("This should be unroutable because (req, resp) are not"
                        " arguments.  It should raise a TypeError.")

            @expose(generic=True)
            def generic(self):
                return ("This should be unroutable because (req, resp) are not"
                        " arguments.  It should raise a TypeError.")

            @generic.when(method='PUT')
            def generic_put(self, _id):
                return ("This should be unroutable because (req, resp) are not"
                        " arguments.  It should raise a TypeError.")

        return RootController 
開發者ID:pecan,項目名稱:pecan,代碼行數:26,代碼來源:test_no_thread_locals.py

示例9: app_

# 需要導入模塊: import pecan [as 別名]
# 或者: from pecan import expose [as 別名]
def app_(self):
        class LookupController(object):
            def __init__(self, someID):
                self.someID = someID

            @expose()
            def index(self, req, resp):
                return '/%s' % self.someID

            @expose()
            def name(self, req, resp):
                return '/%s/name' % self.someID

        class RootController(object):
            @expose()
            def index(self, req, resp):
                return '/'

            @expose()
            def _lookup(self, someID, *remainder):
                return LookupController(someID), remainder

        return TestApp(Pecan(RootController(), use_context_locals=False)) 
開發者ID:pecan,項目名稱:pecan,代碼行數:25,代碼來源:test_no_thread_locals.py

示例10: test_post_with_kwargs_only

# 需要導入模塊: import pecan [as 別名]
# 或者: from pecan import expose [as 別名]
def test_post_with_kwargs_only(self):

        class RootController(RestController):

            @expose()
            def get_all(self):
                return 'INDEX'

            @expose('json')
            def post(self, **kw):
                return kw

        # create the app
        app = TestApp(make_app(RootController()))

        r = app.get('/')
        assert r.status_int == 200
        assert r.body == b_('INDEX')

        kwargs = {'foo': 'bar', 'spam': 'eggs'}
        r = app.post('/', kwargs)
        assert r.status_int == 200
        assert r.namespace['foo'] == 'bar'
        assert r.namespace['spam'] == 'eggs' 
開發者ID:pecan,項目名稱:pecan,代碼行數:26,代碼來源:test_rest.py

示例11: test_nested_rest_with_default

# 需要導入模塊: import pecan [as 別名]
# 或者: from pecan import expose [as 別名]
def test_nested_rest_with_default(self):

        class FooController(RestController):

            @expose()
            def _default(self, *remainder):
                return "DEFAULT %s" % remainder

        class RootController(RestController):
            foo = FooController()

        app = TestApp(make_app(RootController()))

        r = app.get('/foo/missing')
        assert r.status_int == 200
        assert r.body == b_("DEFAULT missing") 
開發者ID:pecan,項目名稱:pecan,代碼行數:18,代碼來源:test_rest.py

示例12: test_internal_redirect_with_after_hook

# 需要導入模塊: import pecan [as 別名]
# 或者: from pecan import expose [as 別名]
def test_internal_redirect_with_after_hook(self):
        run_hook = []

        class RootController(object):
            @expose()
            def internal(self):
                redirect('/testing', internal=True)

            @expose()
            def testing(self):
                return 'it worked!'

        class SimpleHook(PecanHook):
            def after(self, state):
                run_hook.append('after')

        app = TestApp(make_app(RootController(), hooks=[SimpleHook()]))
        response = app.get('/internal')
        assert response.body == b_('it worked!')

        assert len(run_hook) == 1 
開發者ID:pecan,項目名稱:pecan,代碼行數:23,代碼來源:test_hooks.py

示例13: controller

# 需要導入模塊: import pecan [as 別名]
# 或者: from pecan import expose [as 別名]
def controller(self):

        class RootController(object):

            @expose()
            def index(self, a, b, c=1, *args, **kwargs):
                return 'Hello, World!'

            @staticmethod
            @expose()
            def static_index(a, b, c=1, *args, **kwargs):
                return 'Hello, World!'

        return RootController() 
開發者ID:pecan,項目名稱:pecan,代碼行數:16,代碼來源:test_util.py

示例14: test_secure_attribute

# 需要導入模塊: import pecan [as 別名]
# 或者: from pecan import expose [as 別名]
def test_secure_attribute(self):
        authorized = False

        class SubController(object):
            @expose()
            def index(self):
                return 'Hello from sub!'

        class RootController(object):
            @expose()
            def index(self):
                return 'Hello from root!'

            sub = secure(SubController(), lambda: authorized)

        app = TestApp(make_app(RootController()))
        response = app.get('/')
        assert response.status_int == 200
        assert response.body == b_('Hello from root!')

        response = app.get('/sub/', expect_errors=True)
        assert response.status_int == 401

        authorized = True
        response = app.get('/sub/')
        assert response.status_int == 200
        assert response.body == b_('Hello from sub!') 
開發者ID:pecan,項目名稱:pecan,代碼行數:29,代碼來源:test_secure.py

示例15: test_secured_generic_controller

# 需要導入模塊: import pecan [as 別名]
# 或者: from pecan import expose [as 別名]
def test_secured_generic_controller(self):
        authorized = False

        class RootController(object):

            @classmethod
            def check_permissions(cls):
                return authorized

            @expose(generic=True)
            def index(self):
                return 'Index'

            @secure('check_permissions')
            @index.when(method='POST')
            def index_post(self):
                return 'I should not be allowed'

            @secure('check_permissions')
            @expose(generic=True)
            def secret(self):
                return 'I should not be allowed'

        app = TestApp(make_app(
            RootController(),
            debug=True,
            static_root='tests/static'
        ))
        response = app.get('/')
        assert response.status_int == 200
        response = app.post('/', expect_errors=True)
        assert response.status_int == 401
        response = app.get('/secret/', expect_errors=True)
        assert response.status_int == 401 
開發者ID:pecan,項目名稱:pecan,代碼行數:36,代碼來源:test_secure.py


注:本文中的pecan.expose方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。