本文整理汇总了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)
示例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()))
示例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'})
示例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)
示例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)
示例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()))
示例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)
示例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)
示例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)
示例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)
示例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()
示例12: __init__
def __init__(self, **kw):
self._decorators = kw.pop('decorators', [timeit, incr_count,
send_mozsvc_data])
Service.__init__(self, **kw)
示例13: api
def api(self, **kw):
self._decorators.update(set(kw.pop('decorators', [])))
return Service.api(self, **kw)
示例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()
示例15: __init__
def __init__(self,name,path,description,**kw):
Service.__init__(self, name='users', path='/users', description="User registration", depth=2,**kw)
pass