本文整理汇总了Python中pyramid.registry.Registry类的典型用法代码示例。如果您正苦于以下问题:Python Registry类的具体用法?Python Registry怎么用?Python Registry使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Registry类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test__find_view_traversal_multiview
def test__find_view_traversal_multiview(self):
from zope.interface import implementer
from zope.interface import providedBy
from pyramid.interfaces import IRequest
from pyramid.interfaces import IViewClassifier
from pyramid.interfaces import IMultiView
from pyramid.traversal import DefaultRootFactory
from pyramid.registry import Registry
registry = Registry()
@implementer(IMultiView)
class View1(object):
pass
request = dummy.DummyRequest()
request.path_info = '/a'
root = DefaultRootFactory(request)
root_iface = providedBy(root)
view = View1()
registry.registerAdapter(
view, (IViewClassifier, IRequest, root_iface), IMultiView, name='a'
)
self._register_mapper(registry, [])
command = self._makeOne(registry=registry)
request = self._makeRequest('/a', registry)
result = command._find_view(request)
self.assertEqual(result, view)
示例2: test__find_view_route_no_multiview
def test__find_view_route_no_multiview(self):
from zope.interface import Interface
from zope.interface import implementer
from pyramid.interfaces import IRouteRequest
from pyramid.interfaces import IViewClassifier
from pyramid.interfaces import IView
from pyramid.registry import Registry
registry = Registry()
def view():pass
class IMyRoot(Interface):
pass
class IMyRoute(Interface):
pass
registry.registerAdapter(view,
(IViewClassifier, IMyRoute, IMyRoot),
IView, '')
registry.registerUtility(IMyRoute, IRouteRequest, name='a')
@implementer(IMyRoot)
class Factory(object):
def __init__(self, request):
pass
routes = [dummy.DummyRoute('a', '/a', factory=Factory, matchdict={}),
dummy.DummyRoute('b', '/b', factory=Factory)]
self._register_mapper(registry, routes)
command = self._makeOne(registry=registry)
result = command._find_view('/a', registry)
self.assertEqual(result, view)
示例3: setUp
def setUp(self):
self.__request = DummyRequest()
self.__request.matchdict['registration_id'] = 'a1-b2-c3-d4-e5'
self.__request.headers['File-Name'] = 'dummy.zip'
reg = Registry()
reg.settings = {'hpz.frs.upload_base_path': '/dev/null', 'hpz.frs.file_size_limit': '1024'}
self.__config = testing.setUp(registry=reg, request=self.__request, hook_zca=False)
示例4: test_single_route_one_view_registered_with_factory
def test_single_route_one_view_registered_with_factory(self):
from zope.interface import Interface
from pyramid.registry import Registry
from pyramid.interfaces import IRouteRequest
from pyramid.interfaces import IViewClassifier
from pyramid.interfaces import IView
registry = Registry()
def view():pass
class IMyRoot(Interface):
pass
class IMyRoute(Interface):
pass
registry.registerAdapter(view,
(IViewClassifier, IMyRoute, IMyRoot),
IView, '')
registry.registerUtility(IMyRoute, IRouteRequest, name='a')
command = self._makeOne()
def factory(request): pass
route = dummy.DummyRoute('a', '/a', factory=factory)
mapper = dummy.DummyMapper(route)
command._get_mapper = lambda *arg: mapper
L = []
command.out = L.append
command.bootstrap = (dummy.DummyBootstrap(registry=registry),)
result = command.run()
self.assertEqual(result, None)
self.assertEqual(len(L), 3)
self.assertEqual(L[-1].split()[:3], ['a', '/a', '<unknown>'])
示例5: setUp
def setUp(self):
self.__workspace = tempfile.mkdtemp()
self.__staging = tempfile.mkdtemp()
# setup request
self.__request = DummyRequest()
self.__request.method = 'POST'
# setup settings
# use the one for UDL
here = os.path.abspath(os.path.dirname(__file__))
self.gpg_home = os.path.abspath(os.path.join(here, '..', '..', '..', '..', 'config', 'gpg'))
self.settings = {
'smarter_score_batcher.gpg.keyserver': None,
'smarter_score_batcher.gpg.homedir': self.gpg_home,
'smarter_score_batcher.gpg.public_key.ca': '[email protected]',
'smarter_score_batcher.gpg.public_key.cat': '[email protected]',
'smarter_score_batcher.gpg.public_key.fish': '[email protected]',
'smarter_score_batcher.gpg.path': 'gpg',
'smarter_score_batcher.base_dir.working': self.__workspace,
'smarter_score_batcher.base_dir.staging': self.__staging
}
# setup registr
reg = Registry()
reg.settings = self.settings
self.__config = testing.setUp(registry=reg, request=self.__request, hook_zca=False)
self._prepare_testing_files()
示例6: test_single_route_one_view_registered
def test_single_route_one_view_registered(self):
from zope.interface import Interface
from pyramid.registry import Registry
from pyramid.interfaces import IRouteRequest
from pyramid.interfaces import IViewClassifier
from pyramid.interfaces import IView
registry = Registry()
def view():
pass
class IMyRoute(Interface):
pass
registry.registerAdapter(view, (IViewClassifier, IMyRoute, Interface), IView, "")
registry.registerUtility(IMyRoute, IRouteRequest, name="a")
command = self._makeOne()
route = DummyRoute("a", "/a")
mapper = DummyMapper(route)
command._get_mapper = lambda *arg: mapper
L = []
command.out = L.append
app = DummyApp()
app.registry = registry
loadapp = DummyLoadApp(app)
command.loadapp = (loadapp,)
command.args = ("/foo/bar/myapp.ini", "myapp")
result = command.command()
self.assertEqual(result, None)
self.assertEqual(len(L), 3)
self.assertEqual(L[-1].split()[:4], ["a", "/a", "<function", "view"])
示例7: test_single_route_one_view_registered
def test_single_route_one_view_registered(self):
from zope.interface import Interface
from pyramid.registry import Registry
from pyramid.interfaces import IRouteRequest
from pyramid.interfaces import IViewClassifier
from pyramid.interfaces import IView
registry = Registry()
def view():pass
class IMyRoute(Interface):
pass
registry.registerAdapter(view,
(IViewClassifier, IMyRoute, Interface),
IView, '')
registry.registerUtility(IMyRoute, IRouteRequest, name='a')
command = self._makeOne()
route = dummy.DummyRoute('a', '/a')
mapper = dummy.DummyMapper(route)
command._get_mapper = lambda *arg: mapper
L = []
command.out = L.append
command.bootstrap = (dummy.DummyBootstrap(registry=registry),)
result = command.run()
self.assertEqual(result, 0)
self.assertEqual(len(L), 3)
compare_to = L[-1].split()[:3]
self.assertEqual(
compare_to,
['a', '/a', 'pyramid.tests.test_scripts.test_proutes.view']
)
示例8: test__find_view_route_multiview_no_view_registered
def test__find_view_route_multiview_no_view_registered(self):
from zope.interface import Interface
from zope.interface import implementer
from pyramid.interfaces import IRouteRequest
from pyramid.interfaces import IMultiView
from pyramid.interfaces import IRootFactory
from pyramid.registry import Registry
registry = Registry()
def view1():pass
def view2():pass
class IMyRoot(Interface):
pass
class IMyRoute1(Interface):
pass
class IMyRoute2(Interface):
pass
registry.registerUtility(IMyRoute1, IRouteRequest, name='a')
registry.registerUtility(IMyRoute2, IRouteRequest, name='b')
@implementer(IMyRoot)
class Factory(object):
def __init__(self, request):
pass
registry.registerUtility(Factory, IRootFactory)
routes = [dummy.DummyRoute('a', '/a', matchdict={}),
dummy.DummyRoute('b', '/a', matchdict={})]
self._register_mapper(registry, routes)
command = self._makeOne(registry=registry)
result = command._find_view('/a', registry)
self.assertTrue(IMultiView.providedBy(result))
示例9: test_single_route_one_view_registered_with_factory
def test_single_route_one_view_registered_with_factory(self):
from zope.interface import Interface
from pyramid.registry import Registry
from pyramid.interfaces import IRouteRequest
from pyramid.interfaces import IViewClassifier
from pyramid.interfaces import IView
registry = Registry()
def view():pass
class IMyRoot(Interface):
pass
class IMyRoute(Interface):
pass
registry.registerAdapter(view,
(IViewClassifier, IMyRoute, IMyRoot),
IView, '')
registry.registerUtility(IMyRoute, IRouteRequest, name='a')
command = self._makeOne()
def factory(request): pass
route = DummyRoute('a', '/a', factory=factory)
mapper = DummyMapper(route)
command._get_mapper = lambda *arg: mapper
L = []
command.out = L.append
app = DummyApp()
app.registry = registry
loadapp = DummyLoadApp(app)
command.loadapp = (loadapp,)
command.args = ('/foo/bar/myapp.ini', 'myapp')
result = command.command()
self.assertEqual(result, None)
self.assertEqual(len(L), 3)
self.assertEqual(L[-1].split()[:3], ['a', '/a', '<unknown>'])
示例10: _makeRequest
def _makeRequest(self, **kwargs):
""":rtype: pyramid.request.Request"""
from pyramid.registry import Registry
registry = Registry()
registry.settings = {'app.timezone': 'Asia/Bangkok'}
testing.setUp(registry=registry)
return testing.DummyRequest(**kwargs)
示例11: test_dn_with_one_base_element
def test_dn_with_one_base_element(self):
reg = Registry()
reg.settings = {}
reg.settings['ldap.base.dn'] = 'ou=dummy'
self.__config = testing.setUp(registry=reg, request=DummyRequest(), hook_zca=False)
attributes = {'dn': ['ou=dummyOrg,ou=dummy']}
tenant = BasicIdentityParser.get_tenant_name(attributes)
self.assertEqual(tenant[0], 'dummyorg')
示例12: setUp
def setUp(self):
reg = Registry()
reg.settings = {'store_type':'rdflib',
'debug_sparql':True}
self.config = testing.setUp(reg)
self.config.add_settings({'mako.directories':'plingback.sparql:templates'})
self.config.add_renderer(None, mako_renderer_factory)
self.config.begin()
示例13: test_add_settings_settings_None
def test_add_settings_settings_None(self):
from pyramid.registry import Registry
from pyramid.interfaces import ISettings
reg = Registry()
config = self._makeOne(reg)
config.add_settings(None, a=1)
settings = reg.getUtility(ISettings)
self.assertEqual(settings['a'], 1)
示例14: get_registry
def get_registry(settings):
registry = Registry('testing')
config = Configurator(registry=registry)
if getattr(registry, 'settings', None) is None:
config._set_settings(settings)
registry.registerUtility(RoutesMapper(), IRoutesMapper)
config.commit()
return registry
示例15: test_setup_registry_debug_logger_None_default
def test_setup_registry_debug_logger_None_default(self):
from pyramid.registry import Registry
from pyramid.interfaces import IDebugLogger
reg = Registry()
config = self._makeOne(reg)
config.setup_registry()
logger = reg.getUtility(IDebugLogger)
self.assertEqual(logger.name, 'tests.test_config')