本文整理汇总了Python中pyramid.configuration.Configurator类的典型用法代码示例。如果您正苦于以下问题:Python Configurator类的具体用法?Python Configurator怎么用?Python Configurator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Configurator类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: registerDummySecurityPolicy
def registerDummySecurityPolicy(userid=None, groupids=(), permissive=True):
""" Registers a pair of faux :app:`Pyramid` security policies:
a :term:`authentication policy` and a :term:`authorization
policy`.
The behavior of the registered :term:`authorization policy`
depends on the ``permissive`` argument. If ``permissive`` is
true, a permissive :term:`authorization policy` is registered;
this policy allows all access. If ``permissive`` is false, a
nonpermissive :term:`authorization policy` is registered; this
policy denies all access.
The behavior of the registered :term:`authentication policy`
depends on the values provided for the ``userid`` and ``groupids``
argument. The authentication policy will return the userid
identifier implied by the ``userid`` argument and the group ids
implied by the ``groupids`` argument when the
:func:`pyramid.security.authenticated_userid` or
:func:`pyramid.security.effective_principals` APIs are used.
This function is most useful when testing code that uses the APIs
named :func:`pyramid.security.has_permission`,
:func:`pyramid.security.authenticated_userid`,
:func:`pyramid.security.effective_principals`, and
:func:`pyramid.security.principals_allowed_by_permission`.
.. warning:: This API is deprecated as of :app:`Pyramid` 1.0.
Instead use the
:meth:`pyramid.configuration.Configurator.testing_securitypolicy`
method in your unit and integration tests.
"""
registry = get_current_registry()
config = Configurator(registry=registry)
return config.testing_securitypolicy(userid=userid, groupids=groupids, permissive=permissive)
开发者ID:blaflamme,项目名称:pyramid,代码行数:34,代码来源:testing.py
示例2: registerSettings
def registerSettings(dictarg=None, **kw):
"""Register one or more 'setting' key/value pairs. A setting is
a single key/value pair in the dictionary-ish object returned from
the API :attr:`pyramid.registry.Registry.settings`.
You may pass a dictionary::
registerSettings({'external_uri':'http://example.com'})
Or a set of key/value pairs::
registerSettings(external_uri='http://example.com')
Use of this function is required when you need to test code that calls
the :attr:`pyramid.registry.Registry.settings` API and which uses return
values from that API.
.. warning:: This API is deprecated as of :app:`Pyramid` 1.0.
Instead use the
:meth:`pyramid.configuration.Configurator.add_settings`
method in your unit and integration tests.
"""
registry = get_current_registry()
config = Configurator(registry=registry)
config.add_settings(dictarg, **kw)
开发者ID:blaflamme,项目名称:pyramid,代码行数:25,代码来源:testing.py
示例3: TestSubscriber
class TestSubscriber(unittest.TestCase):
def setUp(self):
registry = DummyRegistry()
from pyramid.configuration import Configurator
self.config = Configurator(registry)
self.config.begin()
def tearDown(self):
self.config.end()
def _makeOne(self, *ifaces):
from pyramid.events import subscriber
return subscriber(*ifaces)
def test_register(self):
from zope.interface import Interface
class IFoo(Interface): pass
class IBar(Interface): pass
dec = self._makeOne(IFoo, IBar)
def foo(): pass
config = DummyConfigurator()
scanner = Dummy()
scanner.config = config
dec.register(scanner, None, foo)
self.assertEqual(config.subscribed, [(foo, (IFoo, IBar))])
def test___call__(self):
dec = self._makeOne()
dummy_venusian = DummyVenusian()
dec.venusian = dummy_venusian
def foo(): pass
dec(foo)
self.assertEqual(dummy_venusian.attached, [(foo, dec.register, 'bfg')])
开发者ID:markramm,项目名称:pyramid,代码行数:33,代码来源:test_events.py
示例4: AddPageTests
class AddPageTests(unittest.TestCase):
def setUp(self):
self.session = _initTestingDB()
self.config = Configurator()
self.config.begin()
def tearDown(self):
self.session.remove()
self.config.end()
def _callFUT(self, request):
from tutorial.views import add_page
return add_page(request)
def test_it_notsubmitted(self):
_registerRoutes(self.config)
request = testing.DummyRequest()
request.matchdict = {'pagename':'AnotherPage'}
info = self._callFUT(request)
self.assertEqual(info['page'].data,'')
self.assertEqual(info['save_url'],
'http://example.com/add_page/AnotherPage')
def test_it_submitted(self):
from tutorial.models import Page
_registerRoutes(self.config)
request = testing.DummyRequest({'form.submitted':True,
'body':'Hello yo!'})
request.matchdict = {'pagename':'AnotherPage'}
self._callFUT(request)
page = self.session.query(Page).filter_by(name='AnotherPage').one()
self.assertEqual(page.data, 'Hello yo!')
开发者ID:blaflamme,项目名称:pyramid,代码行数:32,代码来源:tests.py
示例5: renderer
def renderer(_context, factory, name=''):
# renderer factories must be registered eagerly so they can be
# found by the view machinery
reg = get_current_registry()
config = Configurator(reg, package=_context.package)
config.add_renderer(name, factory, _info=_context.info)
_context.action(discriminator=(IRendererFactory, name))
开发者ID:markramm,项目名称:pyramid,代码行数:7,代码来源:zcml.py
示例6: registerEventListener
def registerEventListener(event_iface=None):
""" Registers an :term:`event` listener (aka :term:`subscriber`)
listening for events of the type ``event_iface``. This method
returns a list object which is appended to by the subscriber
whenever an event is captured.
When an event is dispatched that matches ``event_iface``, that
event will be appended to the list. You can then compare the
values in the list to expected event notifications. This method
is useful when testing code that wants to call
:meth:`pyramid.registry.Registry.notify`,
:func:`zope.component.event.dispatch` or
:func:`zope.component.event.objectEventNotify`.
The default value of ``event_iface`` (``None``) implies a
subscriber registered for *any* kind of event.
.. warning:: This API is deprecated as of :app:`Pyramid` 1.0.
Instead use the
:meth:`pyramid.configuration.Configurator.testing_add_subscriber`
method in your unit and integration tests.
"""
registry = get_current_registry()
config = Configurator(registry=registry)
return config.testing_add_subscriber(event_iface)
开发者ID:blaflamme,项目名称:pyramid,代码行数:25,代码来源:testing.py
示例7: TestGetSettings
class TestGetSettings(unittest.TestCase):
def setUp(self):
from pyramid.configuration import Configurator
from pyramid.registry import Registry
registry = Registry('testing')
self.config = Configurator(registry=registry)
self.config.begin()
from zope.deprecation import __show__
__show__.off()
def tearDown(self):
self.config.end()
from zope.deprecation import __show__
__show__.on()
def _callFUT(self):
from pyramid.settings import get_settings
return get_settings()
def test_it_nosettings(self):
self.assertEqual(self._callFUT(), None)
def test_it_withsettings(self):
settings = {'a':1}
self.config.registry.settings = settings
self.assertEqual(self._callFUT(), settings)
开发者ID:blaflamme,项目名称:pyramid,代码行数:26,代码来源:test_settings.py
示例8: test_it_with_dotted_renderer
def test_it_with_dotted_renderer(self):
from zope.interface import implementedBy
from pyramid.threadlocal import get_current_registry
from pyramid.interfaces import IRequest
from pyramid.interfaces import IView
from pyramid.interfaces import IViewClassifier
from pyramid.exceptions import Forbidden
from pyramid.configuration import Configurator
context = DummyContext()
reg = get_current_registry()
config = Configurator(reg)
def dummy_renderer_factory(*arg, **kw):
return lambda *arg, **kw: 'OK'
config.add_renderer('.pt', dummy_renderer_factory)
def view(request):
return {}
self._callFUT(context, view, renderer='fake.pt')
actions = context.actions
regadapt = actions[0]
register = regadapt['callable']
register()
derived_view = reg.adapters.lookup(
(IViewClassifier, IRequest, implementedBy(Forbidden)),
IView, default=None)
self.assertNotEqual(derived_view, None)
self.assertEqual(derived_view(None, None).body, 'OK')
self.assertEqual(derived_view.__name__, 'bwcompat_view')
开发者ID:junkafarian,项目名称:pyramid,代码行数:27,代码来源:test_zcml.py
示例9: ViewPageTests
class ViewPageTests(unittest.TestCase):
def setUp(self):
self.session = _initTestingDB()
self.config = Configurator()
self.config.begin()
def tearDown(self):
self.session.remove()
self.config.end()
def _callFUT(self, request):
from tutorial.views import view_page
return view_page(request)
def test_it(self):
from tutorial.models import Page
request = testing.DummyRequest()
request.matchdict['pagename'] = 'IDoExist'
page = Page('IDoExist', 'Hello CruelWorld IDoExist')
self.session.add(page)
_registerRoutes(self.config)
info = self._callFUT(request)
self.assertEqual(info['page'], page)
self.assertEqual(
info['content'],
'<div class="document">\n'
'<p>Hello <a href="http://example.com/add_page/CruelWorld">'
'CruelWorld</a> '
'<a href="http://example.com/IDoExist">'
'IDoExist</a>'
'</p>\n</div>\n')
self.assertEqual(info['edit_url'],
'http://example.com/IDoExist/edit_page')
开发者ID:blaflamme,项目名称:pyramid,代码行数:33,代码来源:tests.py
示例10: aclauthorizationpolicy
def aclauthorizationpolicy(_context):
policy = ACLAuthorizationPolicy()
# authorization policies must be registered eagerly so they can be
# found by the view registration machinery
reg = get_current_registry()
config = Configurator(reg, package=_context.package)
config._set_authorization_policy(policy, _info=_context.info)
_context.action(discriminator=IAuthorizationPolicy)
开发者ID:markramm,项目名称:pyramid,代码行数:8,代码来源:zcml.py
示例11: default_permission
def default_permission(_context, name):
""" Register a default permission name """
# the default permission must be registered eagerly so it can
# be found by the view registration machinery
reg = get_current_registry()
config = Configurator(reg, package=_context.package)
config.set_default_permission(name)
_context.action(discriminator=IDefaultPermission)
开发者ID:markramm,项目名称:pyramid,代码行数:8,代码来源:zcml.py
示例12: register
def register():
try:
reg = _context.registry
except AttributeError: # pragma: no cover (b/c)
reg = get_current_registry()
config = Configurator(reg, package=_context.package)
config.set_forbidden_view(view=view, attr=attr, renderer=renderer,
wrapper=wrapper, _info=_context.info)
开发者ID:RyoAbe,项目名称:pyramid,代码行数:8,代码来源:zcml.py
示例13: repozewho1authenticationpolicy
def repozewho1authenticationpolicy(_context, identifier_name='auth_tkt',
callback=None):
policy = RepozeWho1AuthenticationPolicy(identifier_name=identifier_name,
callback=callback)
# authentication policies must be registered eagerly so they can
# be found by the view registration machinery
reg = get_current_registry()
config = Configurator(reg, package=_context.package)
config._set_authentication_policy(policy, _info=_context.info)
_context.action(discriminator=IAuthenticationPolicy)
开发者ID:markramm,项目名称:pyramid,代码行数:10,代码来源:zcml.py
示例14: register
def register():
config = Configurator(reg, package=_context.package)
config.add_view(
permission=permission, context=context, view=view, name=name,
request_type=request_type, route_name=route_name,
request_method=request_method, request_param=request_param,
containment=containment, attr=attr, renderer=renderer,
wrapper=wrapper, xhr=xhr, accept=accept, header=header,
path_info=path_info, custom_predicates=custom_predicates,
_info=_context.info)
开发者ID:markramm,项目名称:pyramid,代码行数:10,代码来源:zcml.py
示例15: renderer
def renderer(_context, factory, name=''):
# renderer factories must be registered eagerly so they can be
# found by the view machinery
try:
reg = _context.registry
except AttributeError: # pragma: no cover (b/c)
reg = get_current_registry()
config = Configurator(reg, package=_context.package)
config.add_renderer(name, factory, _info=_context.info)
_context.action(discriminator=(IRendererFactory, name))
开发者ID:RyoAbe,项目名称:pyramid,代码行数:10,代码来源:zcml.py
示例16: remoteuserauthenticationpolicy
def remoteuserauthenticationpolicy(_context, environ_key='REMOTE_USER',
callback=None):
policy = RemoteUserAuthenticationPolicy(environ_key=environ_key,
callback=callback)
# authentication policies must be registered eagerly so they can
# be found by the view registration machinery
reg = get_current_registry()
config = Configurator(reg, package=_context.package)
config._set_authentication_policy(policy, _info=_context.info)
_context.action(discriminator=IAuthenticationPolicy)
开发者ID:markramm,项目名称:pyramid,代码行数:10,代码来源:zcml.py
示例17: BaseViewTests
class BaseViewTests(unittest.TestCase):
def setUp(self):
config['io_device'] = {'class': MockDriver, 'kw':{}}
self.config = Configurator()
self.config.begin()
registerSettings(io_dev='')
self.front_page = get_root(None)
def tearDown(self):
self.config.end()
开发者ID:cswank,项目名称:brewserver,代码行数:11,代码来源:base.py
示例18: default_permission
def default_permission(_context, name):
""" Register a default permission name """
# the default permission must be registered eagerly so it can
# be found by the view registration machinery
try:
reg = _context.registry
except AttributeError: # pragma: no cover (b/c)
reg = get_current_registry()
config = Configurator(reg, package=_context.package)
config.set_default_permission(name)
_context.action(discriminator=IDefaultPermission)
开发者ID:RyoAbe,项目名称:pyramid,代码行数:11,代码来源:zcml.py
示例19: aclauthorizationpolicy
def aclauthorizationpolicy(_context):
policy = ACLAuthorizationPolicy()
# authorization policies must be registered eagerly so they can be
# found by the view registration machinery
try:
reg = _context.registry
except AttributeError: # pragma: no cover (b/c)
reg = get_current_registry()
config = Configurator(reg, package=_context.package)
config._set_authorization_policy(policy, _info=_context.info)
_context.action(discriminator=IAuthorizationPolicy)
开发者ID:RyoAbe,项目名称:pyramid,代码行数:11,代码来源:zcml.py
示例20: Base
class Base(object):
def setUp(self):
from pyramid.configuration import Configurator
self.config = Configurator()
self.config.begin()
import os
here = os.path.abspath(os.path.dirname(__file__))
self.templates_dir = os.path.join(here, 'fixtures')
def tearDown(self):
self.config.end()
开发者ID:RyoAbe,项目名称:pyramid,代码行数:11,代码来源:test_mako_templating.py
注:本文中的pyramid.configuration.Configurator类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论