Ejemplo n.º 1
0
    def do_DELETE(self, content, user):
        """Manage DELETE request."""
        _logger.info('do_delete %s %s' % (content, user))
        if not len(write_collections):
            return NOT_ALLOWED

        collection = write_collections[0]

        if collection.path == environ["PATH_INFO"].strip("/"):
            # Path matching the collection, the collection must be deleted
            item = collection
        else:
            # Try to get an item matching the path
            name = xmlutils.name_from_path(environ["PATH_INFO"], collection)
            item = collection.items.get(name)

        if item:
            # Evolution bug workaround
            if_match = environ.get("HTTP_IF_MATCH", "*").replace("\\", "")
            if if_match in ("*", item.etag):
                # No ETag precondition or precondition verified, delete item
                answer = xmlutils.delete(environ["PATH_INFO"], collection)
                return client.OK, {}, answer
            else:
                # ETag precondition not verified, do not delete item
                return client.PRECONDITION_FAILED, {}, None

        # No item
        return client.NOT_FOUND, {}, None
Ejemplo n.º 2
0
    def delete(self, environ, read_collections, write_collections, content,
               user):
        """Manage DELETE request."""
        if not len(write_collections):
            return NOT_ALLOWED

        collection = write_collections[0]

        if collection.path == environ["PATH_INFO"].strip("/"):
            # Path matching the collection, the collection must be deleted
            item = collection
        else:
            # Try to get an item matching the path
            item = collection.get_item(
                xmlutils.name_from_path(environ["PATH_INFO"], collection))

        if item:
            # Evolution bug workaround
            etag = environ.get("HTTP_IF_MATCH", item.etag).replace("\\", "")
            if etag == item.etag:
                # No ETag precondition or precondition verified, delete item
                answer = xmlutils.delete(environ["PATH_INFO"], collection)
                return client.OK, {}, answer

        # No item or ETag precondition not verified, do not delete item
        return client.PRECONDITION_FAILED, {}, None
Ejemplo n.º 3
0
 def do_DELETE(self, environ, base_prefix, path, user):
     """Manage DELETE request."""
     if not self._access(user, path, "w"):
         return NOT_ALLOWED
     item = next(self.Collection.discover(path), None)
     if not self._access(user, path, "w", item):
         return NOT_ALLOWED
     if not item:
         return NOT_FOUND
     if_match = environ.get("HTTP_IF_MATCH", "*")
     if if_match not in ("*", item.etag):
         # ETag precondition not verified, do not delete item
         return PRECONDITION_FAILED
     if isinstance(item, storage.BaseCollection):
         xml_answer = xmlutils.delete(base_prefix, path, item)
     else:
         xml_answer = xmlutils.delete(base_prefix, path, item.collection,
                                      item.href)
     headers = {"Content-Type": "text/xml; charset=%s" % self.encoding}
     return client.OK, headers, self._write_xml_content(xml_answer)
Ejemplo n.º 4
0
 def do_DELETE(self, environ, base_prefix, path, user):
     """Manage DELETE request."""
     if not self._access(user, path, "w"):
         return NOT_ALLOWED
     with self.Collection.acquire_lock("w", user):
         item = next(self.Collection.discover(path), None)
         if not self._access(user, path, "w", item):
             return NOT_ALLOWED
         if not item:
             return NOT_FOUND
         if_match = environ.get("HTTP_IF_MATCH", "*")
         if if_match not in ("*", item.etag):
             # ETag precondition not verified, do not delete item
             return PRECONDITION_FAILED
         if isinstance(item, storage.BaseCollection):
             xml_answer = xmlutils.delete(base_prefix, path, item)
         else:
             xml_answer = xmlutils.delete(
                 base_prefix, path, item.collection, item.href)
         headers = {"Content-Type": "text/xml; charset=%s" % self.encoding}
         return client.OK, headers, self._write_xml_content(xml_answer)
Ejemplo n.º 5
0
 def delete(self, environ, calendars, content, user):
     """Manage DELETE request."""
     calendar = calendars[0]
     item = calendar.get_item(
         xmlutils.name_from_path(environ["PATH_INFO"], calendar))
     if item and environ.get("HTTP_IF_MATCH", item.etag) == item.etag:
         # No ETag precondition or precondition verified, delete item
         answer = xmlutils.delete(environ["PATH_INFO"], calendar)
         status = client.NO_CONTENT
     else:
         # No item or ETag precondition not verified, do not delete item
         answer = None
         status = client.PRECONDITION_FAILED
     return status, {}, answer
Ejemplo n.º 6
0
    def delete(self, environ, collections, content, user):
        """Manage DELETE request."""
        collection = collections[0]

        if collection.path == environ["PATH_INFO"].strip("/"):
            # Path matching the collection, the collection must be deleted
            item = collection
        else:
            # Try to get an item matching the path
            item = collection.get_item(
                xmlutils.name_from_path(environ["PATH_INFO"], collection))

        if item and environ.get("HTTP_IF_MATCH", item.etag) == item.etag:
            # No ETag precondition or precondition verified, delete item
            answer = xmlutils.delete(environ["PATH_INFO"], collection)
            status = client.NO_CONTENT
        else:
            # No item or ETag precondition not verified, do not delete item
            answer = None
            status = client.PRECONDITION_FAILED
        return status, {}, answer
Ejemplo n.º 7
0
    def delete(self, environ, collections, content, user):
        """Manage DELETE request."""
        collection = collections[0]

        if collection.path == environ["PATH_INFO"].strip("/"):
            # Path matching the collection, the collection must be deleted
            item = collection
        else:
            # Try to get an item matching the path
            item = collection.get_item(
                xmlutils.name_from_path(environ["PATH_INFO"], collection))

        if item and environ.get("HTTP_IF_MATCH", item.etag) == item.etag:
            # No ETag precondition or precondition verified, delete item
            answer = xmlutils.delete(environ["PATH_INFO"], collection)
            status = client.NO_CONTENT
        else:
            # No item or ETag precondition not verified, do not delete item
            answer = None
            status = client.PRECONDITION_FAILED
        return status, {}, answer