;ò c,ïBc@sKdklZdklZdklZdklZdfd„ƒYZdS((s Implements(s getToolByName(s PortalFolder(s listTypessAllowedTypesByIfaceMixincBs5tZdZfZd„Zed„Zdd„ZRS(sAn approach to restrict allowed content types in a container by the interfaces they implement. Notice that extending this class means surpassing allowed_content_types, filter_content_types etc in the FTI, while we are still concerned about security. ATBIFolder is an example type that uses AllowedTypesByIfaceMixin: >>> self.folder.invokeFactory('ATBIFolder', 'f') 'f' >>> f = self.folder.f f has an empty list of allowed_interfaces, so it doesn't allow anything right now: >>> f.allowedContentTypes() [] invokeFactory will fail: >>> try: ... f.invokeFactory('SimpleType', 'st') ... except ValueError: ... print 'Right' Right Now we restrict allowed_interfaces to IBaseFolder: >>> from Products.Archetypes.interfaces.base import * >>> f.allowed_interfaces = (IBaseFolder,) And try to add a SimpleType, which fails again: >>> try: ... f.invokeFactory('SimpleType', 'st') ... except ValueError: ... print 'Right' Right SimpleFolder implements IBaseFolder: >>> f.invokeFactory('SimpleFolder', 'sf') 'sf' A content object only needs to implement one of allowed_interfaces: >>> from Interface import Interface >>> class SomeInterface(Interface): pass >>> f.allowed_interfaces = (IBaseFolder, SomeInterface) >>> f.invokeFactory('SimpleFolder', 'sf2') 'sf2' >>> try: ... f.invokeFactory('SimpleType', 'sf') ... except ValueError: ... print 'Right' Right cCs#t|dƒ}|i|iƒSdS(s1Redefines CMF PortalFolder's allowedContentTypes.sarchetype_toolN(s getToolByNamesselfsatslistPortalTypesWithInterfacessallowed_interfaces(sselfsat((sM/mnt/gmirror/ports/www/zope-archetypes/work/Archetypes/AllowedTypesByIface.pysallowedContentTypesbsc Osåt|dƒ}t|dƒ}t} x-tƒD]"} | d|jo | } Pq.q.W| tjot d|‚n|i | |i ƒ ot d||i f‚n||||f|}|i||Ž}| o |}n|SdS(sMInvokes the portal_types tool. Overrides PortalFolder.invokeFactory.s portal_typessarchetype_tools portal_typesType %r not available.s%Type %r does not implement any of %s.N(s getToolByNamesselfsptsatsNonesftis listTypessts type_names ValueErrorstypeImplementsInterfacessallowed_interfacessidsRESPONSEsargssconstructContentskwargssnew_id( sselfs type_namesidsRESPONSEsargsskwargssptsnew_idsatsftist((sM/mnt/gmirror/ports/www/zope-archetypes/work/Archetypes/AllowedTypesByIface.pys invokeFactorygs$    icCsqt|dƒ}d|i}|i|iƒ}|i|igƒti |||ƒ}|i |i|ƒ|SdS(s*Overrides PortalFolder._verifyObjectPaste.s portal_typess%s_TMPN(s getToolByNamesselfspts portal_typestmp_names getTypeInfostismanage_delObjectss PortalFolders_verifyObjectPastesobjects validate_srcsvalues _setObject(sselfsobjects validate_srcstmp_namesptsvaluesti((sM/mnt/gmirror/ports/www/zope-archetypes/work/Archetypes/AllowedTypesByIface.pys_verifyObjectPastes (s__name__s __module__s__doc__sallowed_interfacessallowedContentTypessNones invokeFactorys_verifyObjectPaste(((sM/mnt/gmirror/ports/www/zope-archetypes/work/Archetypes/AllowedTypesByIface.pysAllowedTypesByIfaceMixins <  N( s Interfaces ImplementssProducts.CMFCore.utilss getToolByNamesProducts.CMFCore.PortalFolders PortalFolders!Products.Archetypes.ArchetypeTools listTypessAllowedTypesByIfaceMixin(s Implementss getToolByNames listTypess PortalFoldersAllowedTypesByIfaceMixin((sM/mnt/gmirror/ports/www/zope-archetypes/work/Archetypes/AllowedTypesByIface.pys?s