示例#1
0
 def __call__(self, content):
     if IContainer.providedBy(content):
         path = list(content.getPhysicalPath()) + [
             'index.' + self.extension]
     elif IPublishable.providedBy(content):
         path = list(aq_parent(content).getPhysicalPath()) + [
             content.getId() + '.' + self.extension]
     elif IAsset.providedBy(content):
         path = list(aq_parent(content).getPhysicalPath()) + [
             content.get_filename()]
     else:
         path = content.getPhysicalPath()
     return '/'.join(relative_path(self._origin, path))
示例#2
0
 def export_assets(self):
     seen = set()
     root = self.settings.root
     for reference in self.references:
         target = reference.target
         if target is None or not IAsset.providedBy(target):
             continue
         if not reference.is_target_inside_container(root):
             raise ExternalReferenceError(
                 _(u"External references"), root, reference.target, root)
         path = self.get_archive_name(target)
         if path in seen:
             continue
         seen.add(path)
         payload = IAssetPayload(target).get_payload()
         if payload is not None:
             self.archive.writestr(path, payload)
示例#3
0
    def _validate(self):
        """ test if the given id is valid, returning a status code
            about its validity or reason of invalidity
        """
        folder = self._context
        maybe_id = self._maybe_id
        allow_dup = self._allow_dup
        if self._valid_id.match(maybe_id) is None:
            return self.CONTAINS_BAD_CHARS
        if maybe_id.endswith('__'):
            # ugly, but Zope explicitely checks this ...
            return self.RESERVED_POSTFIX
        prefixing = maybe_id.split('_')
        if (len(prefixing) > 1) and (prefixing[0] in self._reserved_prefixes):
            return self.RESERVED_PREFIX

        if maybe_id in self._reserved_ids:
            return self.RESERVED

        if self._interface is not None:
            for interface, prefixes in \
                    list(self._reserved_ids_for_interface.items()):
                if self._interface.isOrExtends(interface):
                    if maybe_id in prefixes:
                        return self.RESERVED_FOR_CONTENT

        attr = getattr(aq_inner(folder), maybe_id, _marker)
        if attr is not _marker:
            if ISilvaObject.providedBy(attr):
                # there is a silva object with the same id
                if allow_dup: return self.OK
                attr = getattr(folder.aq_base, maybe_id, _marker)
                if attr is _marker:
                    # shadowing a content object is ok (hopefully)
                    return self.OK
                if IAsset.providedBy(attr):
                    return self.IN_USE_ASSET
                # else it must be a content object (?)
                return self.IN_USE_CONTENT

            # check if object with this id is acquired; if not, it cannot be
            # allowed
            attr2 = getattr(folder.aq_base, maybe_id, _marker)
            if attr2 is not _marker:
                #either it is an attribute/method (self.RESERVED)
                #or it is an object within the container (self.IN_USE_ZOPE)
                if maybe_id in folder.objectIds():
                    return self.IN_USE_ZOPE
                else:
                    return self.RESERVED

            # object using wanted id is acquried
            # now it may be a Zope object, which is allowed (for now)
            # or it is an attribute (which is disallowed)
            if not hasattr(attr, 'meta_type'):
                # not a zope object (guessing ...)
                return self.RESERVED
        try:
            # Call Zope verification function
            checkValidId(folder, str(maybe_id), allow_dup)
        except BadRequest:
            return self.CONTAINS_BAD_CHARS

        return self.OK
示例#4
0
 def validate(self, target, adding=False):
     error = super(GhostAssetManager, self).validate(target, adding)
     if error is None:
         if not IAsset.providedBy(target):
             return AssetInvalidTarget()
     return error
示例#5
0
 def need_update(self):
     if IGhostAsset.providedBy(self.manager.ghost):
         return self.target != self.manager.ghost.get_haunted()
     # Only update if the invalid ghost is an asset.
     return IAsset.providedBy(self.manager.ghost)
示例#6
0
    def _validate(self):
        """ test if the given id is valid, returning a status code
            about its validity or reason of invalidity
        """
        folder = self._context
        maybe_id = self._maybe_id
        allow_dup = self._allow_dup
        if self._valid_id.match(maybe_id) is None:
            return self.CONTAINS_BAD_CHARS
        if maybe_id.endswith('__'):
            # ugly, but Zope explicitely checks this ...
            return self.RESERVED_POSTFIX
        prefixing = maybe_id.split('_')
        if (len(prefixing) >1) and (prefixing[0] in self._reserved_prefixes):
            return self.RESERVED_PREFIX

        if maybe_id in self._reserved_ids:
            return self.RESERVED

        if self._interface is not None:
            for interface, prefixes in \
                    self._reserved_ids_for_interface.items():
                if self._interface.isOrExtends(interface):
                    if maybe_id in prefixes:
                        return self.RESERVED_FOR_CONTENT

        attr = getattr(aq_inner(folder), maybe_id, _marker)
        if attr is not _marker:
            if ISilvaObject.providedBy(attr):
                # there is a silva object with the same id
                if allow_dup: return self.OK
                attr = getattr(folder.aq_base, maybe_id, _marker)
                if attr is _marker:
                    # shadowing a content object is ok (hopefully)
                    return self.OK
                if IAsset.providedBy(attr):
                    return self.IN_USE_ASSET
                # else it must be a content object (?)
                return self.IN_USE_CONTENT

            # check if object with this id is acquired; if not, it cannot be
            # allowed
            attr2 = getattr(folder.aq_base, maybe_id, _marker)
            if attr2 is not _marker:
                #either it is an attribute/method (self.RESERVED)
                #or it is an object within the container (self.IN_USE_ZOPE)
                if maybe_id in folder.objectIds():
                    return self.IN_USE_ZOPE
                else:
                    return self.RESERVED

            # object using wanted id is acquried
            # now it may be a Zope object, which is allowed (for now)
            # or it is an attribute (which is disallowed)
            if not hasattr(attr, 'meta_type'):
                # not a zope object (guessing ...)
                return self.RESERVED
        try:
            # Call Zope verification function
            checkValidId(folder, str(maybe_id), allow_dup)
        except BadRequest:
            return self.CONTAINS_BAD_CHARS

        return self.OK
示例#7
0
 def validate(self, target, adding=False):
     error = super(GhostAssetManager, self).validate(target, adding)
     if error is None:
         if not IAsset.providedBy(target):
             return AssetInvalidTarget()
     return error
示例#8
0
 def need_update(self):
     if IGhostAsset.providedBy(self.manager.ghost):
         return self.target != self.manager.ghost.get_haunted()
     # Only update if the invalid ghost is an asset.
     return IAsset.providedBy(self.manager.ghost)