def test_ObjectSpecification(self):
        c = C()
        directlyProvides(c, I4)
        self.assertEqual([i.getName() for i in providedBy(c)],
                         ['I4', 'I31', 'I1', 'I2'])
        self.assertEqual([i.getName() for i in providedBy(c).flattened()],
                         ['I4', 'I31', 'I3', 'I1', 'I2', 'Interface'])
        self.failUnless(I1 in providedBy(c))
        self.failIf(I3 in providedBy(c))
        self.failUnless(providedBy(c).extends(I3))
        self.failUnless(providedBy(c).extends(I31))
        self.failIf(providedBy(c).extends(I5))

        class COnly(A, B):
            pass

        classImplementsOnly(COnly, I31)

        class D(COnly):
            pass

        classImplements(D, I5)

        classImplements(D, I5)

        c = D()
        directlyProvides(c, I4)
        self.assertEqual([i.getName() for i in providedBy(c)],
                         ['I4', 'I5', 'I31'])
        self.assertEqual([i.getName() for i in providedBy(c).flattened()],
                         ['I4', 'I5', 'I31', 'I3', 'Interface'])
        self.failIf(I1 in providedBy(c))
        self.failIf(I3 in providedBy(c))
        self.failUnless(providedBy(c).extends(I3))
        self.failIf(providedBy(c).extends(I1))
        self.failUnless(providedBy(c).extends(I31))
        self.failUnless(providedBy(c).extends(I5))

        class COnly(A, B):
            __implemented__ = I31

        class D(COnly):
            pass

        classImplements(D, I5)

        classImplements(D, I5)
        c = D()
        directlyProvides(c, I4)
        self.assertEqual([i.getName() for i in providedBy(c)],
                         ['I4', 'I5', 'I31'])
        self.assertEqual([i.getName() for i in providedBy(c).flattened()],
                         ['I4', 'I5', 'I31', 'I3', 'Interface'])
        self.failIf(I1 in providedBy(c))
        self.failIf(I3 in providedBy(c))
        self.failUnless(providedBy(c).extends(I3))
        self.failIf(providedBy(c).extends(I1))
        self.failUnless(providedBy(c).extends(I31))
        self.failUnless(providedBy(c).extends(I5))
Пример #2
0
def uninstallSiteHooks():
    for class_ in _localsite_monkies:
        _localsite_monkies.remove(class_)
        delattr(class_, 'getSiteManager')
        delattr(class_, 'setSiteManager')
        classImplementsOnly(class_, implementedBy(class_) - IPossibleSite)
        if getattr(class_, '_localsite_marker', False):
            delattr(class_, '_localsite_marker')
Пример #3
0
def uninstallSiteHooks():
    for class_ in _localsite_monkies:
        _localsite_monkies.remove(class_)
        delattr(class_, 'getSiteManager')
        delattr(class_, 'setSiteManager')
        classImplementsOnly(class_, implementedBy(class_)-IPossibleSite)
        if getattr(class_, '_localsite_marker', False):
            delattr(class_, '_localsite_marker')
Пример #4
0
    def test_ObjectSpecification(self):
        c = C()
        directlyProvides(c, I4)
        self.assertEqual([i.getName() for i in providedBy(c)],
                         ['I4', 'I31', 'I1', 'I2']
                         )
        self.assertEqual([i.getName() for i in providedBy(c).flattened()],
                         ['I4', 'I31', 'I3', 'I1', 'I2', 'Interface']
                         )
        self.assertTrue(I1 in providedBy(c))
        self.assertFalse(I3 in providedBy(c))
        self.assertTrue(providedBy(c).extends(I3))
        self.assertTrue(providedBy(c).extends(I31))
        self.assertFalse(providedBy(c).extends(I5))

        class COnly(A, B):
            pass
        classImplementsOnly(COnly, I31)

        class D(COnly):
            pass
        classImplements(D, I5)

        classImplements(D, I5)

        c = D()
        directlyProvides(c, I4)
        self.assertEqual([i.getName() for i in providedBy(c)],
                         ['I4', 'I5', 'I31'])
        self.assertEqual([i.getName() for i in providedBy(c).flattened()],
                         ['I4', 'I5', 'I31', 'I3', 'Interface'])
        self.assertFalse(I1 in providedBy(c))
        self.assertFalse(I3 in providedBy(c))
        self.assertTrue(providedBy(c).extends(I3))
        self.assertFalse(providedBy(c).extends(I1))
        self.assertTrue(providedBy(c).extends(I31))
        self.assertTrue(providedBy(c).extends(I5))

        class COnly(A, B): __implemented__ = I31
        class D(COnly):
            pass
        classImplements(D, I5)

        classImplements(D, I5)
        c = D()
        directlyProvides(c, I4)
        self.assertEqual([i.getName() for i in providedBy(c)],
                         ['I4', 'I5', 'I31'])
        self.assertEqual([i.getName() for i in providedBy(c).flattened()],
                         ['I4', 'I5', 'I31', 'I3', 'Interface'])
        self.assertFalse(I1 in providedBy(c))
        self.assertFalse(I3 in providedBy(c))
        self.assertTrue(providedBy(c).extends(I3))
        self.assertFalse(providedBy(c).extends(I1))
        self.assertTrue(providedBy(c).extends(I31))
        self.assertTrue(providedBy(c).extends(I5))
    def test_ObjectSpecification(self):
        c = C()
        directlyProvides(c, I4)
        self.assertEqual([i.getName() for i in providedBy(c)], ["I4", "I31", "I1", "I2"])
        self.assertEqual([i.getName() for i in providedBy(c).flattened()], ["I4", "I31", "I3", "I1", "I2", "Interface"])
        self.assert_(I1 in providedBy(c))
        self.failIf(I3 in providedBy(c))
        self.assert_(providedBy(c).extends(I3))
        self.assert_(providedBy(c).extends(I31))
        self.failIf(providedBy(c).extends(I5))

        class COnly(A, B):
            pass

        classImplementsOnly(COnly, I31)

        class D(COnly):
            pass

        classImplements(D, I5)

        classImplements(D, I5)

        c = D()
        directlyProvides(c, I4)
        self.assertEqual([i.getName() for i in providedBy(c)], ["I4", "I5", "I31"])
        self.assertEqual([i.getName() for i in providedBy(c).flattened()], ["I4", "I5", "I31", "I3", "Interface"])
        self.failIf(I1 in providedBy(c))
        self.failIf(I3 in providedBy(c))
        self.assert_(providedBy(c).extends(I3))
        self.failIf(providedBy(c).extends(I1))
        self.assert_(providedBy(c).extends(I31))
        self.assert_(providedBy(c).extends(I5))

        class COnly(A, B):
            __implemented__ = I31

        class D(COnly):
            pass

        classImplements(D, I5)

        classImplements(D, I5)
        c = D()
        directlyProvides(c, I4)
        self.assertEqual([i.getName() for i in providedBy(c)], ["I4", "I5", "I31"])
        self.assertEqual([i.getName() for i in providedBy(c).flattened()], ["I4", "I5", "I31", "I3", "Interface"])
        self.failIf(I1 in providedBy(c))
        self.failIf(I3 in providedBy(c))
        self.assert_(providedBy(c).extends(I3))
        self.failIf(providedBy(c).extends(I1))
        self.assert_(providedBy(c).extends(I31))
        self.assert_(providedBy(c).extends(I5))
    def test_classImplementsOnly(self):
        class A(Odd):
            implements(I3)

        class B(Odd):
            implements(I4)

        class C(A, B):
            pass

        classImplementsOnly(C, I1, I2)
        self.assertEqual([i.__name__ for i in implementedBy(C)], ['I1', 'I2'])
Пример #7
0
    def test_classImplementsOnly(self):
        class A(Odd):
            implements(I3)

        class B(Odd):
            implements(I4)

        class C(A, B):
          pass
        classImplementsOnly(C, I1, I2)
        self.assertEqual([i.__name__ for i in implementedBy(C)],
                         ['I1', 'I2'])
Пример #8
0
    def test_classImplementsOnly(self):
        @implementer(I3)
        class A(Odd):
            pass

        @implementer(I4)
        class B(Odd):
            pass

        class C(A, B):
            pass

        classImplementsOnly(C, I1, I2)
        self.assertEqual([i.__name__ for i in implementedBy(C)], ["I1", "I2"])
Пример #9
0
    def registerImplementation(self,klass,adapter=NO_ADAPTER_NEEDED,depth=1):

        if adapter is NO_ADAPTER_NEEDED:
            zi.classImplements(klass, self.subject)

        elif adapter is DOES_NOT_SUPPORT:
            ifaces = zi.Declaration(
                [i.__iro__ for i in zi.implementedBy(klass)]
            ) - self.subject
            zi.classImplementsOnly(klass, ifaces)

        return supermeta(ZopeInterfaceAsProtocol,self).registerImplementation(
            klass,adapter,depth
        )
Пример #10
0
    def registerImplementation(self,
                               klass,
                               adapter=NO_ADAPTER_NEEDED,
                               depth=1):

        if adapter is NO_ADAPTER_NEEDED:
            zi.classImplements(klass, self.subject)

        elif adapter is DOES_NOT_SUPPORT:
            ifaces = zi.Declaration(
                [i.__iro__ for i in zi.implementedBy(klass)]) - self.subject
            zi.classImplementsOnly(klass, ifaces)

        return supermeta(ZopeInterfaceAsProtocol,
                         self).registerImplementation(klass, adapter, depth)
Пример #11
0
def GenerateDomainInterface( ctx, interface_name=None ):

    # when called from zcml, most likely we'll get a class not an instance
    # if it is a class go ahead and call instantiate it
    if isinstance( ctx.descriptor, type):
        ctx.descriptor = ctx.descriptor()
                             
    # if the interface module is none, then use the nearest one to the domain class
    if ctx.interface_module is None:
        ispec = ctx.domain_model.__module__.rsplit('.',1)[0]+'.interfaces'
        ctx.interface_module = resolve( ispec )
    
    # interface for domain model
    if not interface_name:
        interface_name = "I%s"%( ctx.domain_model.__name__)
    
    msg = ( ctx.domain_model.__name__,
            ctx.interface_module.__name__,
            interface_name )
    
    if ctx.echo:
        ctx.logger.debug("%s: generated interface %s.%s"%msg )
    
    bases, implements = getDomainInterfaces( ctx.domain_model )
    
    # use the class's mapper select table as input for the transformation
    domain_mapper = orm.class_mapper( ctx.domain_model )
    # 0.4 and 0.5 compatibility, 0.5 has the table as local_table (select_table) is none lazy gen?
    domain_table  = getattr( domain_mapper, 'local_table', domain_mapper.select_table )
    domain_interface = sa2zs.transmute( domain_table,
                                        annotation=ctx.descriptor,
                                        interface_name = interface_name,
                                        __module__ = ctx.interface_module.__name__,
                                        bases=bases
                                        )

    implements.insert(0, domain_interface)

    # if we're replacing an existing interface, make sure the new
    # interface implements it
    old = getattr( ctx.interface_module, interface_name, None)
    if old is not None:
        implements.append(old)
    
    interface.classImplementsOnly( ctx.domain_model, *implements )
    setattr( ctx.interface_module, interface_name, domain_interface )    
    
    ctx.domain_interface = domain_interface
Пример #12
0
def unextendSecurityControlPanel(portal=None):
    out = StringIO()

    # re-register adapter with original interface
    _decl = implementedBy(security.SecurityControlPanelAdapter)
    _decl -= IDoormanSettings
    _decl += security.ISecuritySchema
    classImplementsOnly(security.SecurityControlPanelAdapter, _decl.interfaces())
    del _decl

    getGlobalSiteManager().registerAdapter(security.SecurityControlPanelAdapter)

    # re-instanciate form
    security.SecurityControlPanel.form_fields = FormFields(security.ISecuritySchema)

    print >> out, "security control panel restauriert"
    print out.getvalue()
Пример #13
0
    def _check_wrapping_builtin_returns_correct_provided_by(self, proxy_class, builtin_type):
        # We get the __implemented__ (fallback) of the type, not our own
        from zope.interface import Interface
        from zope.interface import classImplements
        from zope.interface import classImplementsOnly
        from zope.interface import implementedBy
        from zope.interface import providedBy
        from zope.interface import implementedBy

        # Set up the builtin interface
        class IFoo(Interface):
            pass
        impl_before = list(implementedBy(builtin_type))

        classImplements(builtin_type, IFoo)

        builtin = builtin_type()
        self.assertTrue(IFoo in list(providedBy(builtin)))
        self.assertTrue(IFoo in list(implementedBy(builtin_type)))

        try:
            # The asserts must be before we remove the interface
            # because there's a single object that gets mutated

            proxy_instance = proxy_class(builtin)
            provided_instance = providedBy(proxy_instance)
            self.assertTrue(IFoo in list(provided_instance))

            # XXX: PyPy 2.5.0 has a bug where proxys around types
            # aren't correctly hashable, which breaks this part of the
            # test. This is fixed in 2.5.1, but as of 2015-05-28,
            # TravisCI still uses 2.5.0.
            proxy_type = proxy_class(builtin_type)
            from zope.interface.declarations import BuiltinImplementationSpecifications
            if proxy_type in BuiltinImplementationSpecifications \
               and BuiltinImplementationSpecifications.get(proxy_type, self) is not self:
                provided_type = implementedBy(proxy_type)
                self.assertTrue(IFoo in list(provided_type))
            else:
                import sys
                self.assertEqual((2,5,0), sys.pypy_version_info[:3])
        finally:
            classImplementsOnly(builtin_type, *impl_before)
Пример #14
0
def extendSecurityControlPanel(portal=None):
    out = StringIO()

    security.SecurityControlPanelAdapter.get_password_policies = get_password_policies
    security.SecurityControlPanelAdapter.set_password_policies = set_password_policies
    security.SecurityControlPanelAdapter.password_policies = property(
        security.SecurityControlPanelAdapter.get_password_policies,
        security.SecurityControlPanelAdapter.set_password_policies,
    )
    security.SecurityControlPanelAdapter.get_password_duration = get_password_duration
    security.SecurityControlPanelAdapter.set_password_duration = set_password_duration
    security.SecurityControlPanelAdapter.password_duration = property(
        security.SecurityControlPanelAdapter.get_password_duration,
        security.SecurityControlPanelAdapter.set_password_duration,
    )
    security.SecurityControlPanelAdapter.get_reject_non_members = get_reject_non_members
    security.SecurityControlPanelAdapter.set_reject_non_members = set_reject_non_members
    security.SecurityControlPanelAdapter.reject_non_members = property(
        security.SecurityControlPanelAdapter.get_reject_non_members,
        security.SecurityControlPanelAdapter.set_reject_non_members,
    )
    security.SecurityControlPanelAdapter.get_do_basic_auth_paths = get_do_basic_auth_paths
    security.SecurityControlPanelAdapter.set_do_basic_auth_paths = set_do_basic_auth_paths
    security.SecurityControlPanelAdapter.do_basic_auth_paths = property(
        security.SecurityControlPanelAdapter.get_do_basic_auth_paths,
        security.SecurityControlPanelAdapter.set_do_basic_auth_paths,
    )

    # re-register adapter with new interface
    _decl = implementedBy(security.SecurityControlPanelAdapter)
    _decl -= security.ISecuritySchema
    _decl += IDoormanSettings
    classImplementsOnly(security.SecurityControlPanelAdapter, _decl.interfaces())
    del _decl

    getGlobalSiteManager().registerAdapter(security.SecurityControlPanelAdapter)

    # re-instanciate form
    security.SecurityControlPanel.form_fields = FormFields(IDoormanSettings)

    print >> out, "rohberg.doorman: security control panel extended"
    print out.getvalue()
    def _check_wrapping_builtin_returns_correct_provided_by(
            self, proxy_class, builtin_type):
        # We get the __implemented__ (fallback) of the type, not our own
        from zope.interface import Interface
        from zope.interface import classImplements
        from zope.interface import classImplementsOnly
        from zope.interface import implementedBy
        from zope.interface import providedBy
        from zope.interface import implementedBy

        # Set up the builtin interface
        class IFoo(Interface):
            pass

        impl_before = list(implementedBy(builtin_type))

        classImplements(builtin_type, IFoo)

        builtin = builtin_type()
        self.assertTrue(IFoo in list(providedBy(builtin)))
        self.assertTrue(IFoo in list(implementedBy(builtin_type)))

        try:
            # The asserts must be before we remove the interface
            # because there's a single object that gets mutated

            proxy_instance = proxy_class(builtin)
            provided_instance = providedBy(proxy_instance)
            self.assertTrue(IFoo in list(provided_instance))

            proxy_type = proxy_class(builtin_type)
            from zope.interface.declarations import BuiltinImplementationSpecifications
            self.assertIn(proxy_type, BuiltinImplementationSpecifications)
            self.assertIsNot(
                BuiltinImplementationSpecifications.get(proxy_type, self),
                self)
            provided_type = implementedBy(proxy_type)
            self.assertTrue(IFoo in list(provided_type))
        finally:
            classImplementsOnly(builtin_type, *impl_before)
Пример #16
0
    def setUp(self):
        super(BulkScriptTest, self).setUp()
        # setup a fake security module if we're running out
        # of a z2 environment.
        access_control = new.module(self.manager_module_key)
        security_manager = new.module(self.manager_module_key)
        security_manager.newSecurityManager = lambda x, y: None

        if not self.manager_module_key in sys.modules:
            sys.modules["AccessControl"] = access_control
            sys.modules[self.module_key] = security_manager

            def cleanup(self):
                del sys.modules[self.manager_module_key]
                del sys.modules[self.access_module_key]
            self.addCleanup(cleanup, self)

        snippet = """
        <ore:mirror content='%s'/>
        """ % (self.sample_content)
        self._load(snippet)
        schema.metadata.create_all()
        interface.classImplementsOnly(CustomContent, ())
Пример #17
0
def GenerateDomainInterface(ctx, interface_name=None):

    # when called from zcml, most likely we'll get a class not an instance
    # if it is a class go ahead and call instantiate it
    if isinstance(ctx.descriptor, type):
        ctx.descriptor = ctx.descriptor()

    # if the interface module is none, then use the nearest one to the domain class
    if ctx.interface_module is None:
        ispec = ctx.domain_model.__module__.rsplit(".", 1)[0] + ".interfaces"
        ctx.interface_module = resolve(ispec)

    # interface for domain model
    if not interface_name:
        interface_name = "I%s" % (ctx.domain_model.__name__)

    if ctx.echo:
        ctx.logger.debug("%s: generated interface %s.%s " %
                         (ctx.domain_model.__name__,
                          ctx.interface_module.__name__, interface_name))

    from alchemist.catalyst.domain import getDomainInterfaces
    bases, implements = getDomainInterfaces(ctx.domain_model)

    # use the class"s mapper select table as input for the transformation
    domain_mapper = orm.class_mapper(ctx.domain_model)
    ## 0.4 and 0.5 compatibility, 0.5 has the table as local_table (select_table) is none lazy gen?
    #domain_table  = getattr(domain_mapper, "local_table", domain_mapper.select_table)
    # The 0.6 has no attribute select_table attribute. We still have 0.4
    # compitability thought
    domain_table = (domain_mapper.local_table
                    if sa_version[1] >= 5 else domain_mapper.select_table)

    # if the domain model already implements a model interface, use it
    # instead of generating a new one
    for iface in interface.implementedBy(ctx.domain_model):
        if (interfaces.IIModelInterface.providedBy(iface)
                and iface.__name__ == interface_name):
            domain_interface = iface
            break
    else:
        domain_interface = sa2zs.transmute(
            domain_table,
            annotation=ctx.descriptor,
            interface_name=interface_name,
            __module__=ctx.interface_module.__name__,
            bases=bases)

    # if we're replacing an existing interface, make sure the new
    # interface implements it
    old = getattr(ctx.interface_module, interface_name, None)
    if old is not None:
        implements.append(old)

    implements.insert(0, domain_interface)
    # ensure interfaces are unique, preserving the order
    #implements = [ ifc for i,ifc in enumerate(implements)
    #               if implements.index(ifc)==i ]
    #
    # XXX: Oooh, strangely the above does not work... it turns out that
    # implements contains seemingly repeated interfaces e.g. the first and last
    # interfaces are both "<InterfaceClass bungeni.models.interfaces.IReport>"
    # but, they are not the same! So, to compare unique we use the string
    # representation of each interface:
    # str_implements = map(str, implements)
    # implements = [ ifc for i,ifc in enumerate(implements)
    #                if str_implements.index(str(ifc))==i ]
    # Ooops making the interfaces unique breaks other things downstream :(

    interface.classImplementsOnly(ctx.domain_model, *implements)

    setattr(ctx.interface_module, interface_name, domain_interface)
    ctx.domain_interface = domain_interface
Пример #18
0
    def _uncatalogRefs(self, *args, **kwargs):
        pass

    # catalog methods
    def indexObject(self, *args, **kwargs):
        pass

    def unindexObject(self, *args, **kwargs):
        pass

    def reindexObject(self, *args, **kwargs):
        pass


classImplementsOnly(
    NonRefCatalogContent, *(iface for iface in implementedBy(NonRefCatalogContent) if iface is not IReferenceable)
)


class ATBaseCriterion(NonRefCatalogContent):
    """A basic criterion"""

    security = ClassSecurityInfo()

    implements(IATTopicCriterion)

    schema = ATBaseCriterionSchema
    meta_type = "ATBaseCriterion"
    archetype_name = "Base Criterion"

    def __init__(self, id=None, field=None, oid=None):
# add accessors to adapter
def get_private_site(self):
    return IPrivateSite.providedBy(self.portal)


security.SecurityControlPanelAdapter.get_private_site = get_private_site


def set_private_site(self, value):
    operator = value and alsoProvides or noLongerProvides
    operator(self.portal, IPrivateSite)


security.SecurityControlPanelAdapter.set_private_site = set_private_site

security.SecurityControlPanelAdapter.private_site = property(
    security.SecurityControlPanelAdapter.get_private_site, security.SecurityControlPanelAdapter.set_private_site
)

# re-register adapter with new interface
_decl = implementedBy(security.SecurityControlPanelAdapter)
_decl -= security.ISecuritySchema
_decl += IPrivateSiteSchema
classImplementsOnly(security.SecurityControlPanelAdapter, _decl.interfaces())
del _decl

getGlobalSiteManager().registerAdapter(security.SecurityControlPanelAdapter)

# re-instanciate form
security.SecurityControlPanel.form_fields = FormFields(IPrivateSiteSchema)
Пример #20
0
        otherwise - single service

        :return: if service is multi will return the AutobahnDefaultFactory instance otherwise
        twisted application instance
        """

        adf = self.factory.run(WampDefaultComponent)

        if self.factory.belong_to is False:

            adf.setServiceParent(self.service_collection)

            return self.__application

        else:

            adf.setServiceParent(self.factory.belong_to)
            return adf


classImplementsOnly(DefaultAutobahnService, IDefaultAutobahnService)

gsm = getGlobalSiteManager()
gsm.registerAdapter(DefaultAutobahnService)


__all__ = [
    'DefaultAutobahnService',
    'DefaultWSService'
]
Пример #21
0
    def updateIndexes(self, ignore_persistence_exceptions=False):
        """
        Update all indexes in this catalog.
        """
        # avoid the btree iterator for each object
        indexes = list(self.values())
        to_catch = self._PERSISTENCE_EXCEPTIONS if ignore_persistence_exceptions else (
        )
        for uid, obj in self._visitSublocations():
            for index in indexes:
                try:
                    index.index_doc(uid, obj)
                except to_catch as e:
                    logger.error("Error indexing object %s(%s); %s", type(obj),
                                 uid, e)


class DeferredCatalog(Catalog):
    """
    An implementation of :class:`nti.zope_catalog.interfaces.IDeferredCatalog`.
    """


_implemented_by = list(interface.implementedBy(DeferredCatalog).interfaces())
_implemented_by.remove(ICatalog)
_implemented_by.insert(0, IDeferredCatalog)

interface.classImplementsOnly(DeferredCatalog, *_implemented_by)

del _implemented_by
Пример #22
0
class TimeProtocol(TimeProtocolImplementer, RequestSubscriber):

    def __init__(self, **kwargs):

        super(TimeProtocol, self).__init__(**kwargs)


@implementer(IJSONResource)
class TimeConvertProtocol(BaseProtocolActions, RequestSubscriber):
    def __init__(self, **kwargs):

        super(TimeConvertProtocol, self).__init__(**kwargs)
        self.__convert = TimeProtocolImplementer()

    @property
    def convert(self):
        return self.__convert

    @convert.setter
    def convert(self, conv):
        self.__convert = conv


class TimeConvertXMLProtocol(TimeConvertProtocol, RequestSubscriber):

    def __init__(self, **kwargs):
        super(TimeConvertXMLProtocol, self).__init__(**kwargs)


classImplementsOnly(TimeConvertXMLProtocol, IXMLResource)

def get_private_site(self):
    return utils.get_private_site(self.portal)


def set_private_site(self, value):
    utils.set_private_site(self.portal, value)


SecurityControlPanelAdapter.get_private_site = get_private_site

SecurityControlPanelAdapter.set_private_site = set_private_site

SecurityControlPanelAdapter.private_site = property(
    SecurityControlPanelAdapter.get_private_site,
    SecurityControlPanelAdapter.set_private_site
)

# re-register adapter with new interface
_decl = implementedBy(SecurityControlPanelAdapter)
_decl -= ISecuritySchema
_decl += IPrivateSiteSchema
classImplementsOnly(SecurityControlPanelAdapter, _decl.interfaces())
del _decl

getGlobalSiteManager().registerAdapter(SecurityControlPanelAdapter)

# re-instanciate form
SecurityControlPanel.form_fields = FormFields(IPrivateSiteSchema)
Пример #24
0
            _self = self._get_all_keys(self.protocol.to_dict(), validate=False)
            _self.sort()

            other = self._get_all_keys(self.adapter.response, validate=False)
            other.sort()

            if _self == other:
                return self.protocol.to_object(self.adapter.response)

        else:

            return False


class DProtocolSubscriber(BaseProtocolSubscriber):
    """
    This class is designed to be sub classed not for directly usage
    """

    adapts(IValidatorResponse)

    def __init__(self, adapter):
        """
        :param adapter IJSONResource
        """

        super(DProtocolSubscriber, self).__init__(adapter)


classImplementsOnly(DProtocolSubscriber, IJSONResourceSubscriber)
Пример #25
0
    def _uncatalogRefs(self, *args, **kwargs):
        pass

    # catalog methods
    def indexObject(self, *args, **kwargs):
        pass

    def unindexObject(self, *args, **kwargs):
        pass

    def reindexObject(self, *args, **kwargs):
        pass

classImplementsOnly(NonRefCatalogContent,
                    *(iface for iface in implementedBy(NonRefCatalogContent)\
                    if iface is not IReferenceable))


class ATBaseCriterion(NonRefCatalogContent):
    """A basic criterion"""

    security = ClassSecurityInfo()

    implements(IATTopicCriterion)

    schema = ATBaseCriterionSchema
    meta_type = 'ATBaseCriterion'
    archetype_name = 'Base Criterion'

    def __init__(self, id=None, field=None, oid=None):
Пример #26
0
    def start(self):
        """
        Will attach WampDefaultComponent component through AutobahnDefaultFactory
        to our service parent, if self.factory.belong_to is not False will be multi service,
        otherwise - single service

        :return: if service is multi will return the AutobahnDefaultFactory instance otherwise
        twisted application instance
        """

        adf = self.factory.run(WampDefaultComponent)

        if self.factory.belong_to is False:

            adf.setServiceParent(self.service_collection)

            return self.__application

        else:

            adf.setServiceParent(self.factory.belong_to)
            return adf


classImplementsOnly(DefaultAutobahnService, IDefaultAutobahnService)

gsm = getGlobalSiteManager()
gsm.registerAdapter(DefaultAutobahnService)

__all__ = ['DefaultAutobahnService', 'DefaultWSService']
Пример #27
0
def GenerateDomainInterface(ctx, interface_name=None):

    # when called from zcml, most likely we'll get a class not an instance
    # if it is a class go ahead and call instantiate it
    if isinstance(ctx.descriptor, type):
        ctx.descriptor = ctx.descriptor()
                             
    # if the interface module is none, then use the nearest one to the domain class
    if ctx.interface_module is None:
        ispec = ctx.domain_model.__module__.rsplit(".",1)[0]+".interfaces"
        ctx.interface_module = resolve(ispec)
    
    # interface for domain model
    if not interface_name:
        interface_name = "I%s"%(ctx.domain_model.__name__)
    
    if ctx.echo:
        ctx.logger.debug("%s: generated interface %s.%s " % (
            ctx.domain_model.__name__, ctx.interface_module.__name__,
            interface_name))
    
    from alchemist.catalyst.domain import getDomainInterfaces
    bases, implements = getDomainInterfaces(ctx.domain_model)
    
    # use the class"s mapper select table as input for the transformation
    domain_mapper = orm.class_mapper(ctx.domain_model)
    ## 0.4 and 0.5 compatibility, 0.5 has the table as local_table (select_table) is none lazy gen?
    #domain_table  = getattr(domain_mapper, "local_table", domain_mapper.select_table)
    # The 0.6 has no attribute select_table attribute. We still have 0.4 
    # compitability thought
    domain_table  = (domain_mapper.local_table if sa_version[1] >= 5 
                                    else  domain_mapper.select_table)
    
    # if the domain model already implements a model interface, use it
    # instead of generating a new one
    for iface in interface.implementedBy(ctx.domain_model):
        if (interfaces.IIModelInterface.providedBy(iface) and 
            iface.__name__ == interface_name):
            domain_interface = iface
            break
    else:
        domain_interface = sa2zs.transmute(
            domain_table,
            annotation=ctx.descriptor,
            interface_name = interface_name,
            __module__ = ctx.interface_module.__name__,
            bases=bases)
    
    # if we're replacing an existing interface, make sure the new
    # interface implements it
    old = getattr(ctx.interface_module, interface_name, None)
    if old is not None:
        implements.append(old)
    
    implements.insert(0, domain_interface)
    # ensure interfaces are unique, preserving the order
    #implements = [ ifc for i,ifc in enumerate(implements) 
    #               if implements.index(ifc)==i ]
    #
    # XXX: Oooh, strangely the above does not work... it turns out that 
    # implements contains seemingly repeated interfaces e.g. the first and last 
    # interfaces are both "<InterfaceClass bungeni.models.interfaces.IReport>"
    # but, they are not the same! So, to compare unique we use the string
    # representation of each interface:
    # str_implements = map(str, implements)
    # implements = [ ifc for i,ifc in enumerate(implements) 
    #                if str_implements.index(str(ifc))==i ]
    # Ooops making the interfaces unique breaks other things downstream :(
    
    interface.classImplementsOnly(ctx.domain_model, *implements)
    
    setattr(ctx.interface_module, interface_name, domain_interface)
    ctx.domain_interface = domain_interface
Пример #28
0
        base = BaseWebMethods()
        self.__logger = Logger()

        for meth in factory.config.http_methods:

            try:

                name = 'render_{}'.format(meth)
                web_resource = getattr(base, name)

            except AttributeError as e:

                allow_methods = [
                    render.replace('render_', '') for render in base.__class__.__dict__ if render.startswith('render')
                ]

                print('[ !!!!! Warning: ] Ivalid web methods was provided, available are: {}, error: {}'.format(
                    ', '.join(allow_methods), e
                ))

            else:
                setattr(DefaultWebResource, name, web_resource)

        Resource.__init__(self)


classImplementsOnly(DefaultWebResource, IDefaultWebResource)

gsm = getGlobalSiteManager()
gsm.registerAdapter(DefaultWebResource)
Пример #29
0
            other = self._get_all_keys(self.adapter.response, validate=False)
            other.sort()

            if _self == other:
                return self.protocol.to_object(self.adapter.response)

        else:

            return False


class DProtocolSubscriber(BaseProtocolSubscriber):

    """
    This class is designed to be sub classed not for directly usage
    """

    adapts(IValidatorResponse)

    def __init__(self, adapter):

        """
        :param adapter IJSONResource
        """

        super(DProtocolSubscriber, self).__init__(adapter)


classImplementsOnly(DProtocolSubscriber, IJSONResourceSubscriber)
Пример #30
0
def uinstallSiteHook(class_):
    delattr(class_, 'getSiteManager')
    delattr(class_, 'setSiteManager')
    classImplementsOnly(class_, implementedBy(class_)-ISite)
    _localsite_monkies.remove(class_)
Пример #31
0
        :return: service_application
        """
        self.setServiceParent(self.service_collection)

        if self.factory.belong_to is False:
            return self.__application

    def stopService(self):

        """
        A stop service method

        :return: void
        """
        self.factory.ws_server_factory.stopFactory()

        # if is not meaning wss server
        if self.listener is not None:
            self.listener.stopListening()

classImplementsOnly(DefaultWSService, IDefaultWSService)

gsm = getGlobalSiteManager()
gsm.registerAdapter(DefaultWSService)


__all__ = [
    'DefaultWSService'
]