• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python checker.defineChecker函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: test_both_wrapper_and_object_have_checkers_not_security_proxied

    def test_both_wrapper_and_object_have_checkers_not_security_proxied(self):
        from zope.proxy import ProxyBase
        from zope.security.checker import CombinedChecker
        from zope.security.checker import NamesChecker
        from zope.security.checker import defineChecker
        from zope.security.interfaces import ForbiddenAttribute

        class Foo(object):
            a = 'a'
        fooChecker = NamesChecker(['a']) # a is public
        defineChecker(Foo, fooChecker)
        foo = Foo()
        fooChecker.check(foo, 'a') # no raise
        self.assertRaises(ForbiddenAttribute,
                          fooChecker.check, foo, 'b')

        class Wrapper(ProxyBase):
            b = 'b'
            __Security_checker__ = self._makeOne()
        wrapperChecker = NamesChecker(['b']) # b is public
        defineChecker(Wrapper, wrapperChecker)
        wrapper = Wrapper(foo)
        self.assertRaises(ForbiddenAttribute,
                          wrapperChecker.check, foo, 'a')
        wrapperChecker.check(foo, 'b') # no raise

        checker = wrapper.__Security_checker__
        self.assertTrue(isinstance(checker, CombinedChecker))
        checker.check(wrapper, 'a') # no raise
        checker.check(wrapper, 'b') # no raise
开发者ID:SalesSeek,项目名称:zope.security,代码行数:30,代码来源:test_decorator.py


示例2: setUp

    def setUp(self):
        super(AuthZopePublicationTests, self).setUp()
        principalRegistry.defineDefaultPrincipal('anonymous', '')

        root = self.db.open().root()
        app = root[ZopePublication.root_name]
        app['f1'] = rootFolder()
        f1 = app['f1']
        f1['f2'] = Folder()
        if not ISite.providedBy(f1):
            f1.setSiteManager(LocalSiteManager(f1))
        sm1 = f1.getSiteManager()
        addUtility(sm1, '', IAuthentication, AuthUtility1())

        f2 = f1['f2']
        if not ISite.providedBy(f2):
            f2.setSiteManager(LocalSiteManager(f2))
        sm2 = f2.getSiteManager()
        addUtility(sm2, '', IAuthentication, AuthUtility2())
        transaction.commit()

        from zope.container.interfaces import ISimpleReadContainer
        from zope.container.traversal import ContainerTraverser

        component.provideAdapter(ContainerTraverser,
                                 (ISimpleReadContainer, IRequest),
                                 IPublishTraverse, name='')

        from zope.site.interfaces import IFolder
        from zope.security.checker import defineChecker, InterfaceChecker
        defineChecker(Folder, InterfaceChecker(IFolder))
开发者ID:jean,项目名称:zope.app.publication,代码行数:31,代码来源:test_zopepublication.py


示例3: test_both_wrapper_and_object_have_checkers_security_proxied

    def test_both_wrapper_and_object_have_checkers_security_proxied(self):
        from zope.proxy import ProxyBase
        from zope.security.checker import CombinedChecker
        from zope.security.checker import NamesChecker
        from zope.security.checker import defineChecker
        from zope.security.proxy import ProxyFactory

        class Foo(object):
            a = 'a'
        fooChecker = NamesChecker(['a']) # a is public
        defineChecker(Foo, fooChecker)
        foo = Foo()
        f_sec = ProxyFactory(foo)

        class Wrapper(ProxyBase):
            b = 'b'
            __Security_checker__ = self._makeOne()
        wrapperChecker = NamesChecker(['b']) # b is public
        defineChecker(Wrapper, wrapperChecker)
        w_sec = Wrapper(f_sec)

        checker = w_sec.__Security_checker__
        self.assertTrue(isinstance(checker, CombinedChecker))
        checker.check(w_sec, 'a') # no raise
        checker.check(w_sec, 'b') # no raise
开发者ID:SalesSeek,项目名称:zope.security,代码行数:25,代码来源:test_decorator.py


示例4: _testBaseTags

    def _testBaseTags(self, url, expected):
        # Make sure I1 and O1 are visible in the module namespace
        # so that the classes can be pickled.
        import transaction

        pub = BrowserPublication(self.db)

        ztapi.browserView(I1, 'view', DummyView)
        ztapi.setDefaultViewName(I1, 'view')
        ztapi.browserViewProviding(None, TestTraverser, IBrowserPublisher)

        ob = O1()

        ## the following is for running the tests standalone
        principalRegistry.defineDefaultPrincipal(
            'tim', 'timbot', 'ai at its best')

        # now place our object inside the application

        connection = self.db.open()
        app = connection.root()['Application']
        app.somepath = ob
        transaction.commit()
        connection.close()

        defineChecker(app.__class__, NamesChecker(somepath='xxx'))

        req = self._createRequest(url, pub)
        response = req.response

        publish(req, handle_errors=0)

        self.assertEqual(response.getBase(), expected)
开发者ID:grodniewicz,项目名称:oship,代码行数:33,代码来源:test_browserpublication.py


示例5: portletManagerDirective

def portletManagerDirective(
    _context, name, title, for_=None, description=u'',
    class_=None, schema=None, layer=IDefaultBrowserLayer,
    provides=(), portlettype=IPortlet, **kw):

    # Build a new class
    ManagerClass = PortletManager(
        name, class_, provides, title, description, schema, portlettype, **kw)

    # Set up permission mapping for various accessible attributes
    required = {'__call__': CheckerPublic,
                'browserDefault': CheckerPublic,
                'publishTraverse': CheckerPublic}

    for iname in IPortletManager:
        required[iname] = CheckerPublic

    # security checker
    defineChecker(ManagerClass, Checker(required))

    # security for schema fields
    for iface in (IPortletManagerConfiguration, schema):
        if iface is None:
            continue
        for f_id in iface:
            field = iface[f_id]
            if IField.providedBy(field) and not field.readonly:
                protectSetAttribute(ManagerClass, f_id, 'zojax.ManagePortlets')
            protectName(ManagerClass, f_id, 'zope.Public')

    # register the portlet manager
    adapter(_context, (ManagerClass,),
            IPortletManager, (for_, layer, None), name=name)
开发者ID:Zojax,项目名称:zojax.portlet,代码行数:33,代码来源:zcml.py


示例6: AddViewFactory

def AddViewFactory(name, schema, label, permission, layer,
                   template, default_template, bases, for_,
                   fields, content_factory, arguments,
                   keyword_arguments, set_before_add, set_after_add):

    class_  = SimpleViewClass(
        template, used_for=schema, bases=bases, name=name)

    class_.schema = schema
    class_.label = label
    class_.fieldNames = fields
    class_._factory_or_id = content_factory
    class_._factory = property(_getFactory, _setFactory)
    class_._arguments = arguments
    class_._keyword_arguments = keyword_arguments
    class_._set_before_add = set_before_add
    class_._set_after_add = set_after_add

    class_.generated_form = ViewPageTemplateFile(default_template)

    defineChecker(class_,
                  NamesChecker(
                    ("__call__", "__getitem__",
                     "browserDefault", "publishTraverse"),
                    permission,
                    )
                  )
    if layer is None:
        layer = IDefaultBrowserLayer
    
    s = zope.component.getGlobalSiteManager()
    s.registerAdapter(class_, (for_, layer), Interface, name)
开发者ID:CGTIC,项目名称:Plone_SP,代码行数:32,代码来源:add.py


示例7: test_template_context_wrapping

    def test_template_context_wrapping(self):

        class AU(BrowserView):
            def __str__(self):
                name = self.context.__name__
                if name is None:
                    return 'None'
                return name

        defineChecker(AU, NamesChecker(['__str__']))

        from zope.traversing.namespace import view
        from zope.traversing.interfaces import ITraversable
        provideAdapter(view, (None,), ITraversable, name="view")
        provideAdapter(view, (None, None), ITraversable, name="view")
        provideAdapter(
            AU, (IZopachePageTemplate, TestRequest), Interface, name='name')

        page = ZopachePageTemplate()
        page.setSource(
            u'<p tal:replace="template/@@name" />'
            )
        page = contained(page, None, name='zpt')
        request = TestRequest()
        self.assertEquals(page.render(request), u'zpt')
开发者ID:clozinski,项目名称:zopache.pagetemplate,代码行数:25,代码来源:test_pt.py


示例8: makeObjects

    def makeObjects(self):
        checker = NamesChecker(["__getitem__"])
        defineChecker(SiteManagerStub, checker)
        self.futurama = futurama = SampleSite()
        directlyProvides(futurama, IContainmentRoot)
        planetexpress = SampleContainer()
        robotfactory = SampleContainer()
        nimbus = SampleContainer()
        omicronpersei = SampleSite()

        bender = SampleContent()
        fry = SampleContent()
        leela = SampleContent()
        mom = SampleContent()
        zapp = SampleContent()
        kif = SampleContent()

        setitem(futurama, futurama.__setitem__, "planetexpress", planetexpress)
        setitem(futurama, futurama.__setitem__, "robotfactory", robotfactory)
        setitem(futurama, futurama.__setitem__, "nimbus", nimbus)
        setitem(futurama, futurama.__setitem__, "omicronpersei", omicronpersei)

        setitem(planetexpress, planetexpress.__setitem__, "bender", bender)
        setitem(planetexpress, planetexpress.__setitem__, "fry", fry)
        setitem(planetexpress, planetexpress.__setitem__, "leela", leela)
        setitem(robotfactory, robotfactory.__setitem__, "mom", mom)
        setitem(nimbus, nimbus.__setitem__, "zapp", zapp)
        setitem(nimbus, nimbus.__setitem__, "kif", kif)
开发者ID:wpjunior,项目名称:proled,代码行数:28,代码来源:test_adapters.py


示例9: ttwElementDirective

def ttwElementDirective(
    _context, name, title, for_ = interface.Interface,
    description=u'', layer = IDefaultBrowserLayer, template=u''):

    # register pageelement
    pageelementDirective(
        _context, name, for_=for_,
        title=title, description=description, layer=layer, template=template)

    # Make sure that the template exists
    template = os.path.abspath(str(_context.path(template)))
    if not os.path.isfile(template):
        raise ConfigurationError("No such file", template)

    # Build a new class that we can use different permission settings if we
    # use the class more then once.
    cdict = {}
    cdict['name'] = name
    cdict['title'] = title
    cdict['description'] = description
    cdict['template'] = template

    newclass = type(
        str('<TTWResourceFactory %s>'%name), (TTWPageElementFactory,), cdict)

    # Set up permission mapping for various accessible attributes
    required = {}
    for iname in ITTWPageElementFactory:
        required[iname] = CheckerPublic

    # security checker
    defineChecker(newclass, Checker(required))

    # register the page element
    adapter(_context, (newclass,), ITTWItemFactory, (for_, layer), name=name)
开发者ID:Zojax,项目名称:zojax.ui.simplettw,代码行数:35,代码来源:zcml.py


示例10: ttwResourceDirective

def ttwResourceDirective(
    _context, name, title, for_ = interface.Interface,
    layer = IDefaultBrowserLayer, type = '', file = None, description=u'', **kwargs):

    rname = u'simplettw.%s'%name
    # register resource
    resourceDirective(
        _context, rname, file, layer, permission='zope.Public', type='')

    # Build a new class that we can use different permission settings if we
    # use the class more then once.
    cdict = {}
    cdict['name'] = name
    cdict['title'] = title
    cdict['description'] = description
    cdict['file'] = os.path.abspath(str(_context.path(file)))
    cdict['contentType'] = type

    newclass = Type(
        str('<TTWResourceFactory %s>'%name), (TTWResourceFactory,), cdict)

    # Set up permission mapping for various accessible attributes
    required = dict([(iname, CheckerPublic) for iname in ITTWResourceFactory])
    defineChecker(newclass, Checker(required))

    # register the resource element
    adapter(_context, (newclass,), ITTWItemFactory, (ISimpleTTW, layer), name=name)

    # register IStaticResource adapter
    adapter(_context, (StaticResource(rname),),
            IStaticResource, (layer,), name=name)
开发者ID:Zojax,项目名称:zojax.ui.simplettw,代码行数:31,代码来源:zcml.py


示例11: execute

    def execute(self, factory, config, permissions, **kw):
        if not permissions:
            return False

        if get_config().getboolean('auth', 'enforce_attribute_rights_definition'):
            perms = {}
        else:
            perms = AuditingPermissionDictionary()

        # mandatory, otherwise zope's default Checker impl will be used
        # which doesn't play well with Twisted.
        defineChecker(factory, Checker(perms, perms))

        # TODO: supply the 'inherit' option to the class somehow
        # to facilitate optional inheritance of all permissions
        for class_inheritance_level in permissions:
            for name, permission in class_inheritance_level.items():
                if isinstance(permission, tuple):
                    read_perm, write_perm = permission
                    config.action(discriminator=('protectNameSet', factory, name),
                                  callable=grokcore.security.util.protect_setattr,
                                  args=(factory, name, write_perm))
                else:
                    read_perm = permission

                config.action(discriminator=('protectName', factory, name),
                              callable=grokcore.security.util.protect_getattr,
                              args=(factory, name, read_perm))

        return True
开发者ID:AsherBond,项目名称:opennode-management,代码行数:30,代码来源:grokkers.py


示例12: setUp

 def setUp(self):
     super(ZopachePageTemplateTests, self).setUp()
     provideAdapter(Traverser, (None,), ITraverser)
     provideAdapter(DefaultTraversable, (None,), ITraversable)
     provideAdapter(
           LocationPhysicallyLocatable, (None,), IPhysicallyLocatable)
     provideAdapter(
           RootPhysicallyLocatable, (IContainmentRoot,), IPhysicallyLocatable)
     defineChecker(Data, NamesChecker(['URL', 'name']))
开发者ID:clozinski,项目名称:zopache.pagetemplate,代码行数:9,代码来源:test_pt.py


示例13: handle_security

def handle_security(class_, permission, interfaces, attributes):
    required = set(attributes)
    for ifc in interfaces:
        required.update(set(ifc))

    if permission == 'zope.Public':
        permission = CheckerPublic

    defineChecker(class_, Checker(dict.fromkeys(required, permission)))
开发者ID:achouhans,项目名称:schooltool-2.8.5,代码行数:9,代码来源:zcml_content.py


示例14: make_checker

def make_checker(factory, view_factory, permission, method_names=None):
    if method_names is None:
        method_names = ['__call__']
    if permission is not None:
        check_permission(factory, permission)
    if permission is None or permission == 'zope.Public':
        checker = NamesChecker(method_names)
    else:
        checker = NamesChecker(method_names, permission)
    defineChecker(view_factory, checker)
开发者ID:jean,项目名称:grokcore.view,代码行数:10,代码来源:util.py


示例15: test_resources

 def test_resources(self):
     browserResource('quux', Resource)
     # Only register the checker once, so that multiple test runs pass.
     if Resource not in _checkers:
         defineChecker(Resource, NamesChecker(['__call__']))
     self.addPage('/foo/bar/pt',
                  u'<span tal:replace="context/++resource++quux" />')
     self.verify('/foo/bar/pt', 'http://localhost/@@/quux')
     self.verify('/foo/++vh++https:localhost:443/fake/folders/++/bar/pt',
                 'https://localhost/fake/folders/@@/quux')
开发者ID:grodniewicz,项目名称:oship,代码行数:10,代码来源:test_vhosting.py


示例16: whitelist_module

def whitelist_module(module, classes=[], definitions=[]):

    # For python scripts and zope
    allow_module(module)
    for klass in classes:
        allow_class(klass)
    if definitions:
        ModuleSecurityInfo(module).declarePublic(*definitions)

    # for zope.untrustedpython
    defineChecker(imodule, NamesChecker([meth for meth in dir(imodule) if meth[0] != "_"]))
开发者ID:collective,项目名称:sandboxlib,代码行数:11,代码来源:util.py


示例17: execute

    def execute(self, factory, config, permission, **kw):
        # mandatory, otherwise zope's default Checker impl will be used
        # which doesn't play well in async frameworks like twisted.
        defineChecker(factory, Checker({}, {}))

        for method_name in [i for i in dir(factory) if i.startswith('render')]:
            config.action(discriminator=('protectName', factory, method_name),
                          callable=protect_getattr,
                          args=(factory, method_name, permission))

        return True
开发者ID:AsherBond,项目名称:opennode-management,代码行数:11,代码来源:grokkers.py


示例18: test_w_existing_like_unto_checker_wo_existing_checker

 def test_w_existing_like_unto_checker_wo_existing_checker(self):
     from zope.security.checker import Checker
     from zope.security.checker import CheckerPublic
     from zope.security.checker import defineChecker
     from zope.security.checker import _checkers
     permission = object()
     foo_checker = Checker({'bar': CheckerPublic}, {'bar': permission})
     defineChecker(Foo, foo_checker)
     self._callFUT(Bar, Foo)
     bar_checker = _checkers[Bar]
     self.assertEqual(bar_checker.get_permissions,
                      foo_checker.get_permissions)
     self.assertEqual(bar_checker.set_permissions,
                      foo_checker.set_permissions)
开发者ID:SalesSeek,项目名称:zope.security,代码行数:14,代码来源:test_protectclass.py


示例19: make_checker

def make_checker(factory, view_factory, permission, method_names=None):
    """Make a checker for a view_factory associated with factory.

    These could be one and the same for normal views, or different
    in case we make method-based views such as for JSON and XMLRPC.
    """
    if method_names is None:
        method_names = ['__call__']
    if permission is not None:
        check_permission(factory, permission)
    if permission is None or permission == 'zope.Public':
        checker = NamesChecker(method_names)
    else:
        checker = NamesChecker(method_names, permission)
    defineChecker(view_factory, checker)
开发者ID:grodniewicz,项目名称:oship,代码行数:15,代码来源:util.py


示例20: test_locationproxy_security

    def test_locationproxy_security(self):
        from zope.security.checker import defineChecker
        from zope.security.checker import NamesChecker
        from zope.security.proxy import ProxyFactory
        class Unlocated(object):
            a = 'a'
        unlocated = Unlocated()
        located = LocationProxy(unlocated)

        # define a checker for the unlocated object, which will also be
        # used by the security proxy as the LocationProxy defines
        # __Security_checker__:
        unlocatedChecker = NamesChecker(['a'])
        defineChecker(Unlocated, unlocatedChecker)

        secure_located = ProxyFactory(located)
        self.assertEqual(secure_located.a, 'a')
开发者ID:zopefoundation,项目名称:zope.security,代码行数:17,代码来源:test_location.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python management.endInteraction函数代码示例发布时间:2022-05-27
下一篇:
Python vocabulary.SimpleVocabulary类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap