def sizeForDisplay(self): """See `ISized`. """ num_items = len(self._container) if num_items == 1: return _('1 item') return _('${items} items', mapping={'items': str(num_items)})
def checkName(self, name, object): if isinstance(name, str): name = unicode(name) elif not isinstance(name, unicode): raise TypeError("Invalid name type", type(name)) if not name: raise ValueError( _("An empty name was provided. Names cannot be empty.")) if name[:1] in '+@' or '/' in name: raise ValueError( _("Names cannot begin with '+' or '@' or contain '/'")) reserved = IReservedNames(self.context, None) if reserved is not None: if name in reserved.reservedNames: raise NameReserved(name) if name in self.context: raise KeyError( _("The given name is already being used")) return True
def checkObject(container, name, object): """Check containment constraints for an object and container. """ # check __setitem__ precondition containerProvided = providedBy(container) __setitem__ = containerProvided.get('__setitem__') if __setitem__ is not None: precondition = __setitem__.queryTaggedValue('precondition') if precondition is not None: precondition(container, name, object) # check that object is not being pasted into itself or its children. target = container while target is not None: if target is object: raise TypeError("Cannot add an object to itself or its children.") if zope.location.interfaces.ILocation.providedBy(target): target = target.__parent__ else: target = None # check the constraint on __parent__ __parent__ = providedBy(object).get('__parent__') if __parent__ is not None: try: validate = __parent__.validate except AttributeError: pass else: validate(container) if not containerProvided.extends(IContainer): # If it doesn't implement IContainer, it can't contain stuff. raise TypeError( _('Container is not a valid Zope container.'))