Revision a8326bef pithos/api/util.py

b/pithos/api/util.py
228 228
def validate_matching_preconditions(request, meta):
229 229
    """Check that the ETag conforms with the preconditions set."""
230 230
    
231
    if 'hash' not in meta:
232
        return # TODO: Always return?
231
    hash = meta.get('hash', None)
233 232
    
234 233
    if_match = request.META.get('HTTP_IF_MATCH')
235
    if if_match is not None and if_match != '*':
236
        if meta['hash'] not in [x.lower() for x in parse_etags(if_match)]:
237
            raise PreconditionFailed('Resource Etag does not match')
234
    if if_match is not None:
235
        if hash is None:
236
            raise PreconditionFailed('Resource does not exist')
237
        if if_match != '*' and hash not in [x.lower() for x in parse_etags(if_match)]:
238
            raise PreconditionFailed('Resource ETag does not match')
238 239
    
239 240
    if_none_match = request.META.get('HTTP_IF_NONE_MATCH')
240 241
    if if_none_match is not None:
241
        if if_none_match == '*' or meta['hash'] in [x.lower() for x in parse_etags(if_none_match)]:
242
            raise NotModified('Resource Etag matches')
242
        # TODO: If this passes, must ignore If-Modified-Since header.
243
        if hash is not None:
244
            if if_none_match == '*' or hash in [x.lower() for x in parse_etags(if_none_match)]:
245
                # TODO: Continue if an If-Modified-Since header is present.
246
                if request.method in ('HEAD', 'GET'):
247
                    raise NotModified('Resource ETag matches')
248
                raise PreconditionFailed('Resource exists or ETag matches')
243 249

  
244 250
def split_container_object_string(s):
245 251
    if not len(s) > 0 or s[0] != '/':
......
262 268
            backend.copy_object(request.user, v_account, src_container, src_name, dest_container, dest_name, meta, False, permissions, src_version)
263 269
    except NotAllowedError:
264 270
        raise Unauthorized('Access denied')
265
    except NameError, IndexError:
271
    except (NameError, IndexError):
266 272
        raise ItemNotFound('Container or object does not exist')
267 273
    except ValueError:
268 274
        raise BadRequest('Invalid sharing header')

Also available in: Unified diff