def _setUpWidgets(self): adapted = self.schema(self.context) if adapted is not self.context: if not ILocation.providedBy(adapted): adapted = LocationProxy(adapted) adapted.__parent__ = self.context self.adapted = adapted setUpEditWidgets(self, self.schema, source=self.adapted, names=self.fieldNames)
def __init__(self, authplugin, pau): if ILocation.providedBy(authplugin): self.__parent__ = authplugin.__parent__ self.__name__ = authplugin.__name__ else: self.__parent__ = pau self.__name__ = "" self.authplugin = authplugin self.pau = pau self.schema = authplugin.schema
def __init__(self, _context, class_): if not ILocation.implementedBy(class_) and \ not hasattr(class_, '__parent__'): raise ConfigurationError('Class `%s` does not implement ' '`ILocation`.' % class_.__name__) if not IPersistent.implementedBy(class_): raise ConfigurationError('Class `%s` does not implement ' '`IPersistent`.' % class_.__name__) classImplements(class_, IAttributeAnnotatable) classImplements(class_, ILocalUtility) super(LocalUtilityDirective, self).__init__(_context, class_)
def publishTraverse(self, request, name): subob = self.context.get(name, None) if subob is None: view = zapi.queryMultiAdapter((self.context, request), name=name) if view is not None: if ILocation.providedBy(view): view.__parent__ = self.context view.__name__ = name return view raise NotFound(self.context, name, request) return subob
def id(self, object): if ILocation.providedBy(object): if not inside(object, self.location): if id(object) in self.pids_by_id: return self.pids_by_id[id(object)] pid = len(self.others_by_pid) # The following is needed to overcome a bug # in pickle.py. The pickle checks the boolean value # of the id, rather than whether it is None. pid += 1 self.pids_by_id[id(object)] = pid self.others_by_pid[pid] = object return pid return None
def id(self, object): if ILocation.providedBy(object): if not inside(object, self.location): return LocationPhysicallyLocatable(object).getPath() return None
def containedEvent(object, container, name=None): """Establish the containment of the object in the container The object and necessary event are returned. The object may be a `ContainedProxy` around the original object. The event is an added event, a moved event, or None. If the object implements `IContained`, simply set its `__parent__` and `__name__` attributes: >>> container = {} >>> item = Contained() >>> x, event = containedEvent(item, container, u'foo') >>> x is item True >>> item.__parent__ is container True >>> item.__name__ u'foo' We have an added event: >>> event.__class__.__name__ 'ObjectAddedEvent' >>> event.object is item True >>> event.newParent is container True >>> event.newName u'foo' >>> event.oldParent >>> event.oldName Now if we call contained again: >>> x2, event = containedEvent(item, container, u'foo') >>> x2 is item True >>> item.__parent__ is container True >>> item.__name__ u'foo' We don't get a new added event: >>> event If the object already had a parent but the parent or name was different, we get a moved event: >>> x, event = containedEvent(item, container, u'foo2') >>> event.__class__.__name__ 'ObjectMovedEvent' >>> event.object is item True >>> event.newParent is container True >>> event.newName u'foo2' >>> event.oldParent is container True >>> event.oldName u'foo' If the `object` implements `ILocation`, but not `IContained`, set it's `__parent__` and `__name__` attributes *and* declare that it implements `IContained`: >>> from zope.app.location import Location >>> item = Location() >>> IContained.providedBy(item) False >>> x, event = containedEvent(item, container, 'foo') >>> x is item True >>> item.__parent__ is container True >>> item.__name__ 'foo' >>> IContained.providedBy(item) True If the `object` doesn't even implement `ILocation`, put a `ContainedProxy` around it: >>> item = [] >>> x, event = containedEvent(item, container, 'foo') >>> x is item False >>> x.__parent__ is container True >>> x.__name__ 'foo' Make sure we don't lose existing directly provided interfaces. >>> from zope.interface import Interface, directlyProvides >>> class IOther(Interface): ... pass >>> from zope.app.location import Location >>> item = Location() >>> directlyProvides(item, IOther) >>> IOther.providedBy(item) True >>> x, event = containedEvent(item, container, 'foo') >>> IOther.providedBy(item) True """ if not IContained.providedBy(object): if ILocation.providedBy(object): zope.interface.directlyProvides( object, IContained, zope.interface.directlyProvidedBy(object)) else: object = ContainedProxy(object) oldparent = object.__parent__ oldname = object.__name__ if oldparent is container and oldname == name: # No events return object, None object.__parent__ = container object.__name__ = name if oldparent is None or oldname is None: event = ObjectAddedEvent(object, container, name) else: event = ObjectMovedEvent(object, oldparent, oldname, container, name) return object, event