當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。