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


Python cornice.Service类代码示例

本文整理汇总了Python中cornice.Service的典型用法代码示例。如果您正苦于以下问题:Python Service类的具体用法?Python Service怎么用?Python Service使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Service类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

 def __init__(self, **kw):
     self._decorators = kw.pop('decorators', [timeit, incr_count,
                                              send_mozsvc_data])
     # To work properly with venusian, we have to specify the number of
     # frames between the call to venusian.attach and the definition of
     # the attached function.  Cornice defaults to 1, and we add another.
     kw.setdefault('depth', 2)
     Service.__init__(self, **kw)
开发者ID:ncalexan,项目名称:mozservices,代码行数:8,代码来源:metrics.py

示例2: _get_app

    def _get_app(self):
        self.config.include('cornice')

        failing_service = Service(name='failing', path='/fail')
        failing_service.add_view('GET', lambda r: 1 / 0)
        self.config.add_cornice_service(failing_service)

        return TestApp(CatchErrors(self.config.make_wsgi_app()))
开发者ID:joesteeve,项目名称:cornice,代码行数:8,代码来源:test_init.py

示例3: test_fallback_no_required_csrf

 def test_fallback_no_required_csrf(self):
     service = Service(name='fallback-csrf', path='/', content_type='application/json')
     service.add_view('POST', lambda _:'', require_csrf=False)
     register_service_views(self.config, service)
     self.config.include('cornice')
     app = self.config.make_wsgi_app()
     testapp = TestApp(app)
     testapp.post('/', status=415, headers={'Content-Type': 'application/xml'})
开发者ID:mozilla-services,项目名称:cornice,代码行数:8,代码来源:test_pyramidhook.py

示例4: test_fallback_no_predicate

 def test_fallback_no_predicate(self):
     service = Service(name='fallback-test', path='/',
                       effective_principals=('group:admins',))
     service.add_view('GET', lambda _:_)
     register_service_views(self.config, service)
     self.config.include('cornice')
     app = self.config.make_wsgi_app()
     testapp = TestApp(app)
     testapp.get('/', status=404)
开发者ID:mozilla-services,项目名称:cornice,代码行数:9,代码来源:test_pyramidhook.py

示例5: includeme

def includeme(config):
    # FIXME this should also work in includeme
    user_info = Service(name='users', path='/{username}/info')
    user_info.add_view('get', get_info)
    config.add_cornice_service(user_info)

    resource.add_view(ThingImp.collection_get, permission='read')
    thing_resource = resource.add_resource(
        ThingImp, collection_path='/thing', path='/thing/{id}',
        name='thing_service')
    config.add_cornice_resource(thing_resource)
开发者ID:foozzi,项目名称:cornice,代码行数:11,代码来源:views.py

示例6: setUp

    def setUp(self):
        self.config = testing.setUp()
        self.config.include("cornice")
        self.config.add_route('proute', '/from_pyramid')
        self.config.scan("tests.test_pyramidhook")

        def handle_response(request):
            return {'service': request.current_service.name,
                    'route': request.matched_route.name}
        rserv = Service(name="ServiceWPyramidRoute", pyramid_route="proute")
        rserv.add_view('GET', handle_response)

        register_service_views(self.config, rserv)
        self.app = TestApp(CatchErrors(self.config.make_wsgi_app()))
开发者ID:mozilla-services,项目名称:cornice,代码行数:14,代码来源:test_pyramidhook.py

示例7: __init__

    def __init__(self,
                 name=None, path=None, description=None, cors_policy=None, depth=0,
                 **kwargs):

        name = name or self.__class__.__name__.lower()

        CorniceService.__init__(
            self,
            name=name,
            path=path or '/{}'.format(name),
            description=description or 'service for {}'.format(path),
            cors_policy=cors_policy,
            depth=depth + 2,
            validators=self.validate,
            **kwargs
        )

        self.post()(self.receive)
开发者ID:succhiello,项目名称:djehuty,代码行数:18,代码来源:receiver.py

示例8: test_fallback_permission

    def test_fallback_permission(self):
        """
        Fallback view should be registered with NO_PERMISSION_REQUIRED
        Fixes: https://github.com/mozilla-services/cornice/issues/245
        """
        service = Service(name='fallback-test', path='/')
        service.add_view('GET', lambda _:_)
        register_service_views(self.config, service)

        # This is a bit baroque
        introspector = self.config.introspector
        views = introspector.get_category('views')
        fallback_views = [i for i in views
                          if i['introspectable']['route_name']=='fallback-test']

        for v in fallback_views:
            if v['introspectable'].title == u'function cornice.pyramidhook._fallback_view':
                permissions = [p['value'] for p in v['related'] if p.type_name == 'permission']
                self.assertIn(NO_PERMISSION_REQUIRED, permissions)
开发者ID:mozilla-services,项目名称:cornice,代码行数:19,代码来源:test_pyramidhook.py

示例9: test

 def test(self):
     # Compiled regexs are, apparently, non-pickleable
     service = Service(name="test", path="/", schema={'a': re.compile('')})
     service.add_view('GET', lambda _:_)
     register_service_views(self.config, service)
开发者ID:mozilla-services,项目名称:cornice,代码行数:5,代码来源:test_pyramidhook.py

示例10: get_fresh_air

        self.context = context

    def get_fresh_air(self):
        resp = Response()
        resp.text = u'air with ' + repr(self.context)
        return resp

    def make_it_fresh(self, response):
        response.text = u'fresh ' + response.text
        return response

    def check_temperature(self, request, **kw):
        if not 'X-Temperature' in request.headers:
            request.errors.add('header', 'X-Temperature')

tc = Service(name="TemperatureCooler", path="/fresh-air",
             klass=TemperatureCooler, factory=dummy_factory)
tc.add_view("GET", "get_fresh_air", filters=('make_it_fresh',),
            validators=('check_temperature',))


class TestService(TestCase):

    def setUp(self):
        self.config = testing.setUp(
            settings={'pyramid.debug_authorization': True})

        # Set up debug_authorization logging to console
        logging.basicConfig(level=logging.DEBUG)
        debug_logger = logging.getLogger()
        self.config.registry.registerUtility(debug_logger, IDebugLogger)
开发者ID:mozilla-services,项目名称:cornice,代码行数:31,代码来源:test_pyramidhook.py

示例11: get_fresh_air

        self.request = request

    def get_fresh_air(self):
        resp = Response()
        resp.body = 'air'
        return resp

    def make_it_fresh(self, response):
        response.body = 'fresh ' + response.body
        return response

    def check_temperature(self, request):
        if not 'X-Temperature' in request.headers:
            request.errors.add('header', 'X-Temperature')

tc = Service(name="TemperatureCooler", path="/fresh-air",
             klass=TemperatureCooler)
tc.add_view("GET", "get_fresh_air", filters=('make_it_fresh',),
            validators=('check_temperature',))


class TestService(TestCase):

    def setUp(self):
        self.config = testing.setUp()
        self.config.include("cornice")
        self.config.scan("cornice.tests.test_service")
        self.config.scan("cornice.tests.test_pyramidhook")
        self.app = TestApp(CatchErrors(self.config.make_wsgi_app()))

    def tearDown(self):
        testing.tearDown()
开发者ID:CDC,项目名称:cornice,代码行数:32,代码来源:test_pyramidhook.py

示例12: __init__

 def __init__(self, **kw):
     self._decorators = kw.pop('decorators', [timeit, incr_count,
                                              send_mozsvc_data])
     Service.__init__(self, **kw)
开发者ID:pombredanne,项目名称:mozservices,代码行数:4,代码来源:metrics.py

示例13: api

    def api(self, **kw):
        self._decorators.update(set(kw.pop('decorators', [])))

        return Service.api(self, **kw)
开发者ID:crankycoder,项目名称:mozservices,代码行数:4,代码来源:metrics.py

示例14: get_fresh_air

        self.context = context

    def get_fresh_air(self):
        resp = Response()
        resp.text = u'air with ' + repr(self.context)
        return resp

    def make_it_fresh(self, response):
        response.text = u'fresh ' + response.text
        return response

    def check_temperature(self, request):
        if not 'X-Temperature' in request.headers:
            request.errors.add('header', 'X-Temperature')

tc = Service(name="TemperatureCooler", path="/fresh-air",
             klass=TemperatureCooler, factory=dummy_factory)
tc.add_view("GET", "get_fresh_air", filters=('make_it_fresh',),
            validators=('check_temperature',))


class TestService(TestCase):

    def setUp(self):
        self.config = testing.setUp()
        self.config.include("cornice")
        self.config.scan("cornice.tests.test_service")
        self.config.scan("cornice.tests.test_pyramidhook")
        self.app = TestApp(CatchErrors(self.config.make_wsgi_app()))

    def tearDown(self):
        testing.tearDown()
开发者ID:cghnassia,项目名称:Roki_Rakat,代码行数:32,代码来源:test_pyramidhook.py

示例15: __init__

	def __init__(self,name,path,description,**kw):
		Service.__init__(self, name='users', path='/users', description="User registration", depth=2,**kw)
		pass
开发者ID:alexmerser,项目名称:opensaas,代码行数:3,代码来源:oservice.py


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