def __init__(self, context): super(PathIndexable, self).__init__(context) physical_path = IPhysicallyLocatable(context).getPath() steps = physical_path.split('/') paths = [] for i in range(1, len(steps) + 1): paths.append('/'.join(steps[:i])) self.paths = paths
def _getUndoInfo(self, context, principal, first, last): specification = {} if context is not None: locatable = IPhysicallyLocatable(context, None) if locatable is not None: location = Prefix(locatable.getPath()) specification.update({'location': location}) if principal is not None: # TODO: The 'user' in the transactions is a concatenation # of 'path' and 'user' (id). 'path' used to be the path # of the user folder in Zope 2. ZopePublication currently # does not set a path, so ZODB lets the path default to # '/'. We should change ZODB3 to set no default path at # some point path = '/' # default for now specification.update({'user_name': path + ' ' + principal.id}) try: if specification: def flt(info): try: return bool(reduce(operator.and_, map(lambda (x,y): info.get(x) is not None and y== info.get(x) or False, specification.items()))) except TypeError: return False else: flt = None entries = self.__db.undoInfo(first, last, specification) except: import logging logging.getLogger('zojax.undo').exception('error') raise # We walk through the entries, augmenting the dictionaries # with some additional items we have promised in the interface for entry in entries: entry['datetime'] = datetime.fromtimestamp(entry['time']) entry['principal'] = None user_name = entry['user_name'] if user_name: # TODO: This is because of ZODB3/Zope2 cruft regarding # the user path (see comment above). This 'if' block # should go away. split = user_name.split() if len(split) == 2: user_name = split[1] if user_name: try: principal = zope.component.getUtility( IAuthentication).getPrincipal(user_name) entry['principal'] = principal except PrincipalLookupError: # principals might have passed away pass return entries
def _visitSublocations(self) : """Restricts the access to the objects that live within the nearest site if the catalog itself is locatable. """ locatable = IPhysicallyLocatable(self, None) if locatable is not None : uidutil = getUtility(IQreatureIntIds, context=self) site = locatable.getNearestSite() for uid in uidutil: obj = uidutil.getObject(uid) if location.inside(obj, site) : yield uid, obj else : uidutil = getUtility(IQreatureIntIds) for uid in uidutil: yield uid, uidutil.getObject(uid)
def annotateTransaction(self, txn, request, ob): """Set some useful meta-information on the transaction. This information is used by the undo framework, for example. This method is not part of the `IPublication` interface, since it's specific to this particular implementation. """ if request.principal is not None: principal_id = six.text_type(request.principal.id) txn.setUser(principal_id) # Work around methods that are usually used for views bare = removeSecurityProxy(ob) if isinstance(bare, MethodType): ob = bare.__self__ # set the location path path = None locatable = IPhysicallyLocatable(ob, None) if locatable is not None: # Views are made children of their contexts, but that # doesn't necessarily mean that we can fully resolve the # path. E.g. the family tree of a resource cannot be # resolved completely, as the site manager is a dead end. try: path = locatable.getPath() except (AttributeError, TypeError): pass if path is not None: txn.setExtendedInfo('location', path) # set the request type iface = IRequest for iface in providedBy(request): if iface.extends(IRequest): break iface_dotted = iface.__module__ + '.' + iface.getName() txn.setExtendedInfo('request_type', iface_dotted) return txn
def annotateTransaction(self, txn, request, ob): """Set some useful meta-information on the transaction. This information is used by the undo framework, for example. This method is not part of the `IPublication` interface, since it's specific to this particular implementation. """ if request.principal is not None: txn.setUser(request.principal.id) # Work around methods that are usually used for views bare = removeSecurityProxy(ob) if isinstance(bare, instancemethod): ob = bare.im_self # set the location path path = None locatable = IPhysicallyLocatable(ob, None) if locatable is not None: # Views are made children of their contexts, but that # doesn't necessarily mean that we can fully resolve the # path. E.g. the family tree of a resource cannot be # resolved completely, as the site manager is a dead end. try: path = locatable.getPath() except (AttributeError, TypeError): pass if path is not None: txn.setExtendedInfo('location', path) # set the request type iface = IRequest for iface in providedBy(request): if iface.extends(IRequest): break iface_dotted = iface.__module__ + '.' + iface.getName() txn.setExtendedInfo('request_type', iface_dotted) return txn
def traverse(self, name): new_obj = None # Try to get name as dict entry... keygetter = getattr(self.obj, 'keys', None) if inspect.ismethod(keygetter): if name in keygetter(): new_obj = self.obj[name] # Try to get name as sequence entry... if not new_obj: # This is not the appropriate way to handle iterators. We # must find somehing to handle them too. try: name_int = int(name) if name_int in range(0, len(self.obj)): new_obj = self.obj[name_int] except ValueError: pass # Get name as obj attribute... if not new_obj and hasattr(self.obj, name): new_obj = getattr(self.obj, name, None) # Get name as annotation... if not new_obj: naked = zope.security.proxy.removeSecurityProxy(self.obj) try: annotations = IAnnotations(naked) new_obj = name and name in annotations and annotations[name] if not new_obj: new_obj = annotations except TypeError: pass # Give obj a location... if new_obj: if not IPhysicallyLocatable(new_obj, False): new_obj = location.LocationProxy( new_obj, self.obj, name) new_info = ZopeObjectInfo(new_obj) new_info.__parent__ = self new_info.__name__ = name return new_info # name not found... return
def traverse(self, path): namespace = 'anno' print "TRAVERSE", path if path.startswith(namespace): name = path[len(namespace):] naked = removeSecurityProxy(self.context) annotations = IAnnotations(naked) print annotations.items() #obj = name and annotations[name] or annotations #obj = path and annotations[name] or annotations obj = ObjectInfo("Hello") if not IPhysicallyLocatable(obj, False): #obj = LocationProxy( # obj, self.context, namespace + name) obj = LocationProxy(obj, self.context, 'anno' + name) return obj return