def test_fromZ2Interface_methods(self): from Products.Five.bridge import fromZ2Interface class IMethods(Z2_Interface): def one(): """One method.""" def another(arg1, arg2): """Another method, taking arguments.""" converted = fromZ2Interface(IMethods) self.failUnless(Z3_Interface.isEqualOrExtendedBy(converted)) self.assertEqual(len(converted.names()), 2) self.failUnless('one' in converted.names()) self.failUnless('another' in converted.names()) one = converted.getDescriptionFor('one') self.failUnless(isinstance(one, Z3_Method)) self.assertEqual(one.getName(), 'one') self.assertEqual(one.getDoc(), 'One method.') another = converted.getDescriptionFor('another') self.failUnless(isinstance(another, Z3_Method)) self.assertEqual(another.getName(), 'another') self.assertEqual(another.getDoc(), 'Another method, taking arguments.')
def directlyProvides(obj, *interfaces): # convert any Zope 2 interfaces to Zope 3 using fromZ2Interface normalized_interfaces = [] for i in interfaces: try: i = fromZ2Interface(i) except ValueError: # already a Zope 3 interface pass normalized_interfaces.append(i) return interface.directlyProvides(obj, *normalized_interfaces)
def classImplements(class_, *interfaces): # convert any Zope 2 interfaces to Zope 3 using fromZ2Interface normalized_interfaces = [] for i in interfaces: try: i = fromZ2Interface(i) except ValueError: # already a Zope 3 interface pass normalized_interfaces.append(i) return interface.classImplements(class_, *normalized_interfaces)
def createZope2Bridge(zope2, package, name): # Map a Zope 2 interface into a Zope3 interface, seated within 'package' # as 'name'. z3i = fromZ2Interface(zope2) if name is not None: z3i.__dict__['__name__'] = name z3i.__dict__['__module__'] = package.__name__ setattr(package, z3i.getName(), z3i)
def test_fromZ2Interface_empty(self): from Products.Five.bridge import fromZ2Interface class IEmpty(Z2_Interface): pass converted = fromZ2Interface(IEmpty) self.failUnless(Z3_Interface.isEqualOrExtendedBy(converted)) self.assertEqual(len(converted.names()), 0)
def classImplements(class_, *interfaces): # convert any Zope 2 interfaces to Zope 3 using fromZ2Interface interfaces = flatten(interfaces) normalized_interfaces = [] for i in interfaces: try: i = fromZ2Interface(i) except ValueError: # already a Zope 3 interface pass assert issubclass(i, zope.interface.Interface) normalized_interfaces.append(i) return zope.interface.classImplements(class_, *normalized_interfaces)
def classDoesNotImplement(class_, *interfaces): # convert any Zope 2 interfaces to Zope 3 using fromZ2Interface interfaces = flatten(interfaces) normalized_interfaces = [] for i in interfaces: try: i = fromZ2Interface(i) except ValueError: # already a Zope 3 interface pass assert issubclass(i, zope.interface.Interface) normalized_interfaces.append(i) implemented = implementedBy(class_) for iface in normalized_interfaces: implemented = implemented - iface return zope.interface.classImplementsOnly(class_, implemented)
def test_fromZ2Interface_attributes(self): from Products.Five.bridge import fromZ2Interface class IAttributes(Z2_Interface): one = Z2_Attribute('one', 'One attribute') another = Z2_Attribute('another', 'Another attribute') converted = fromZ2Interface(IAttributes) self.failUnless(Z3_Interface.isEqualOrExtendedBy(converted)) self.assertEqual(len(converted.names()), 2) self.failUnless('one' in converted.names()) self.failUnless('another' in converted.names()) one = converted.getDescriptionFor('one') self.failUnless(isinstance(one, Z3_Attribute)) self.assertEqual(one.getName(), 'one') self.assertEqual(one.getDoc(), 'One attribute') another = converted.getDescriptionFor('another') self.failUnless(isinstance(another, Z3_Attribute)) self.assertEqual(another.getName(), 'another') self.assertEqual(another.getDoc(), 'Another attribute')
from Products.CMFCore.utils import getToolByName from Products.CMFCore.permissions import ModifyPortalContent from Products.Five.bridge import fromZ2Interface from Products.Archetypes.public import BaseBTreeFolderSchema, Schema, TextField, LinesField from Products.Archetypes.public import BaseBTreeFolder, registerType from Products.Archetypes.public import TextAreaWidget, LinesWidget from Products.CMFDynamicViewFTI.browserdefault import BrowserDefaultMixin from Products.CMFDynamicViewFTI.interfaces \ import ISelectableBrowserDefault as ZopeTwoISelectableBrowserDefault try: from Products.CMFDynamicViewFTI.interface import ISelectableBrowserDefault except ImportError: ISelectableBrowserDefault = fromZ2Interface(ZopeTwoISelectableBrowserDefault) from Products.Ploneboard.config import PROJECTNAME from Products.Ploneboard.permissions import ViewBoard, SearchBoard, \ AddBoard, AddForum, ManageBoard, AddAttachment, ModerateForum from Products.Ploneboard.content.PloneboardForum import PloneboardForum from Products.Ploneboard.interfaces import IPloneboard schema = BaseBTreeFolderSchema + Schema(( TextField('description', searchable = 1, default_content_type = 'text/html', default_output_type = 'text/plain', widget = TextAreaWidget(description = "Enter a brief description of the board.", description_msgid = "help_description_board",
from Products.Archetypes.public import BaseBTreeFolder, registerType from Products.Archetypes.public import TextAreaWidget, BooleanWidget, MultiSelectionWidget, IntegerWidget, SelectionWidget from Products.Archetypes.public import DisplayList from Products.Ploneboard.config import PROJECTNAME, HAS_SIMPLEATTACHMENT from Products.Ploneboard.permissions import ViewBoard, SearchBoard, \ AddForum, ManageForum, ManageBoard, AddConversation, ModerateForum from PloneboardConversation import PloneboardConversation from Products.Ploneboard.interfaces import IPloneboard, IForum, IConversation from Products.CMFPlone.interfaces.NonStructuralFolder \ import INonStructuralFolder as ZopeTwoINonStructuralFolder try: from Products.CMFPlone.interfaces.structure import INonStructuralFolder except ImportError: INonStructuralFolder = fromZ2Interface(ZopeTwoINonStructuralFolder) schema = BaseBTreeFolderSchema + Schema(( TextField('description', searchable = 1, default_content_type = 'text/html', default_output_type = 'text/plain', widget = TextAreaWidget( description = "Brief description of the forum topic.", description_msgid = "help_description_forum", label = "Description", label_msgid = "label_description_forum", i18n_domain = "ploneboard", rows = 5)),
from _schema import ISchema, ISchemata, ICompositeSchema, IBindableSchema, IManagedSchema, IMultiPageSchema from _storage import IStorage, ISQLStorage from _templatemixin import ITemplateMixin from _vocabulary import IVocabulary from _athistoryaware import IATHistoryAware from _archetypetool import IArchetypeTool from _edit import IEditForm from _validator import IObjectPreValidation, IObjectPostValidation # BBB from Interface.bridge import createZope3Bridge # metadata will follow style of other interfaces come CMF 1.6 from metadata import IExtensibleMetadata from Products.Five.bridge import fromZ2Interface IExtensibleMetadata=fromZ2Interface(IExtensibleMetadata) import annotations import base import field import layer import marshall import metadata import orderedfolder import referenceable import referenceengine import schema import storage import vocabulary import templatemixin import athistoryaware
This module contains all content types used in PloneArticle product """ __docformat__ = 'restructuredtext' # Inner content interfaces from innercontentproxy import IBaseInnerContentProxy, IFileInnerContentProxy, \ IImageInnerContentProxy, ILinkInnerContentProxy from innercontentfield import IBaseInnerContentField, IFileInnerContentField, \ IImageInnerContentField, ILinkInnerContentField, IBaseInnerContent, \ IInnerContentContainer from innercontentwidget import IBaseInnerContentWidget, \ IFileInnerContentWidget, IImageInnerContentWidget, ILinkInnerContentWidget from article import IPloneArticle, IPloneArticleMultiPage, IPloneArticleTool from smartlistfield import ISmartListField # We need this as long as we will support both Plone 2.1 & 2.5 : 2.1 does not # provide a Z3 interface for INonStructuralFolder, but Plone 2.5 require that it # is implemented with a Z3 one to take it into account (see implement.zcml) try: from Products.CMFPlone.interfaces.structure import INonStructuralFolder except ImportError: from Products.CMFPlone.interfaces.NonStructuralFolder import \ INonStructuralFolder as z2_INonStructuralFolder from Products.Five.bridge import fromZ2Interface INonStructuralFolder = fromZ2Interface(z2_INonStructuralFolder)