Exemple #1
0
    def put(self, environ, read_collections, write_collections, content, user):
        """Manage PUT request."""
        if not len(write_collections):
            return NOT_ALLOWED

        collection = write_collections[0]

        collection.set_mimetype(environ.get("CONTENT_TYPE"))
        headers = {}
        item_name = xmlutils.name_from_path(environ["PATH_INFO"], collection)
        item = collection.get_item(item_name)

        # Evolution bug workaround
        etag = environ.get("HTTP_IF_MATCH", "").replace("\\", "")
        match = environ.get("HTTP_IF_NONE_MATCH", "") == "*"
        if (not item and not etag) or (
                item and ((etag or item.etag) == item.etag) and not match):
            # PUT allowed in 3 cases
            # Case 1: No item and no ETag precondition: Add new item
            # Case 2: Item and ETag precondition verified: Modify item
            # Case 3: Item and no Etag precondition: Force modifying item
            xmlutils.put(environ["PATH_INFO"], content, collection)
            status = client.CREATED
            # Try to return the etag in the header.
            # If the added item doesn't have the same name as the one given
            # by the client, then there's no obvious way to generate an
            # etag, we can safely ignore it.
            new_item = collection.get_item(item_name)
            if new_item:
                headers["ETag"] = new_item.etag
        else:
            # PUT rejected in all other cases
            status = client.PRECONDITION_FAILED
        return status, headers, None
Exemple #2
0
 def put(self, environ, calendars, content, user):
     """Manage PUT request."""
     calendar = calendars[0]
     headers = {}
     item_name = xmlutils.name_from_path(environ["PATH_INFO"], calendar)
     item = calendar.get_item(item_name)
     if (not item and not environ.get("HTTP_IF_MATCH")) or (
         item and environ.get("HTTP_IF_MATCH", item.etag) == item.etag):
         # PUT allowed in 3 cases
         # Case 1: No item and no ETag precondition: Add new item
         # Case 2: Item and ETag precondition verified: Modify item
         # Case 3: Item and no Etag precondition: Force modifying item
         xmlutils.put(environ["PATH_INFO"], content, calendar)
         status = client.CREATED
         headers["ETag"] = calendar.get_item(item_name).etag
     else:
         # PUT rejected in all other cases
         status = client.PRECONDITION_FAILED
     return status, headers, None
Exemple #3
0
 def put(self, environ, collections, content, user):
     """Manage PUT request."""
     collection = collections[0]
     collection.set_mimetype(environ.get("CONTENT_TYPE"))
     headers = {}
     item_name = xmlutils.name_from_path(environ["PATH_INFO"], collection)
     item = collection.get_item(item_name)
     if (not item and not environ.get("HTTP_IF_MATCH")) or (
             item and environ.get("HTTP_IF_MATCH", item.etag) == item.etag):
         # PUT allowed in 3 cases
         # Case 1: No item and no ETag precondition: Add new item
         # Case 2: Item and ETag precondition verified: Modify item
         # Case 3: Item and no Etag precondition: Force modifying item
         xmlutils.put(environ["PATH_INFO"], content, collection)
         status = client.CREATED
         headers["ETag"] = collection.get_item(item_name).etag
     else:
         # PUT rejected in all other cases
         status = client.PRECONDITION_FAILED
     return status, headers, None
Exemple #4
0
    def do_PUT(self, environ, read_collections, write_collections, content,
               user):
        """Manage PUT request."""
        _logger.info('do_PUT %s %s' % (content, user))

        if not len(write_collections):
            return NOT_ALLOWED

        collection = write_collections[0]

        collection.set_mimetype(environ.get("CONTENT_TYPE"))
        headers = {}
        item_name = xmlutils.name_from_path(environ["PATH_INFO"], collection)
        item = collection.items.get(item_name)

        # Evolution bug workaround
        etag = environ.get("HTTP_IF_MATCH", "").replace("\\", "")
        match = environ.get("HTTP_IF_NONE_MATCH", "") == "*"
        if (not item and not etag) or (item and
                                       ((etag or item.etag) == item.etag)
                                       and not match):
            # PUT allowed in 3 cases
            # Case 1: No item and no ETag precondition: Add new item
            # Case 2: Item and ETag precondition verified: Modify item
            # Case 3: Item and no Etag precondition: Force modifying item
            xmlutils.put(environ["PATH_INFO"], content, collection)
            status = client.CREATED
            # Try to return the etag in the header.
            # If the added item doesn't have the same name as the one given
            # by the client, then there's no obvious way to generate an
            # etag, we can safely ignore it.
            new_item = collection.items.get(item_name)
            if new_item:
                headers["ETag"] = new_item.etag
        else:
            # PUT rejected in all other cases
            status = client.PRECONDITION_FAILED
        return status, headers, None
Exemple #5
0
    def put(self, environ, collections, content, user):
        """Manage PUT request."""
        collection = collections[0]
        collection.set_mimetype(environ.get("CONTENT_TYPE"))
        headers = {}
        item_name = xmlutils.name_from_path(environ["PATH_INFO"], collection)
        item = collection.get_item(item_name)

        # Evolution bug workaround
        etag = environ.get("HTTP_IF_MATCH", "").replace("\\", "")
        if (not item and not etag) or (
            item and ((etag or item.etag) == item.etag)):
            # PUT allowed in 3 cases
            # Case 1: No item and no ETag precondition: Add new item
            # Case 2: Item and ETag precondition verified: Modify item
            # Case 3: Item and no Etag precondition: Force modifying item
            xmlutils.put(environ["PATH_INFO"], content, collection)
            status = client.CREATED
            headers["ETag"] = collection.get_item(item_name).etag
        else:
            # PUT rejected in all other cases
            status = client.PRECONDITION_FAILED
        return status, headers, None