Revision e8886082 pithos/api/util.py

b/pithos/api/util.py
174 174

  
175 175
def format_permissions(permissions):
176 176
    ret = []
177
    if 'public' in permissions:
178
        ret.append('public')
179 177
    if 'private' in permissions:
180 178
        ret.append('private')
181 179
    r = ','.join(permissions.get('read', []))
......
234 232
    
235 233
    meta = get_object_meta(request)
236 234
    permissions = get_sharing(request)
237
    # Keep previous values of 'Content-Type' (if a new one is absent) and 'hash'.
235
    src_version = request.META.get('HTTP_X_SOURCE_VERSION')
236
    
238 237
    try:
239
        src_meta = backend.get_object_meta(request.user, v_account, src_container, src_name)
240
    except NameError:
238
        if move:
239
            src_meta = backend.get_object_meta(request.user, v_account, src_container, src_name)
240
        else:
241
            src_meta = backend.get_object_meta(request.user, v_account, src_container, src_name, src_version)
242
    except NameError, IndexError:
241 243
        raise ItemNotFound('Container or object does not exist')
244
    
245
    # Keep previous values of 'Content-Type' (if a new one is absent) and 'hash'.
242 246
    if 'Content-Type' in meta and 'Content-Type' in src_meta:
243 247
        del(src_meta['Content-Type'])
244 248
    for k in ('Content-Type', 'hash'):
......
249 253
        if move:
250 254
            backend.move_object(request.user, v_account, src_container, src_name, dest_container, dest_name, meta, True, permissions)
251 255
        else:
252
            src_version = request.META.get('HTTP_X_SOURCE_VERSION')
253 256
            backend.copy_object(request.user, v_account, src_container, src_name, dest_container, dest_name, meta, True, permissions, src_version)
254
    except NameError:
257
    except NameError, IndexError:
255 258
        raise ItemNotFound('Container or object does not exist')
256 259
    except ValueError:
257 260
        raise BadRequest('Invalid sharing header')
......
370 373
    
371 374
    ret = {}
372 375
    for perm in (x.replace(' ','') for x in permissions.split(';')):
373
        if perm == 'public':
374
            ret['public'] = True
375
            continue
376
        elif perm == 'private':
376
        if perm == 'private':
377 377
            ret['private'] = True
378 378
            continue
379 379
        elif perm.startswith('read='):
380 380
            ret['read'] = [v.replace(' ','') for v in perm[5:].split(',')]
381
            if '*' in ret['read']:
382
                ret['read'] = ['*']
381 383
            if len(ret['read']) == 0:
382 384
                raise BadRequest('Bad X-Object-Sharing header value')
383 385
        elif perm.startswith('write='):
384 386
            ret['write'] = [v.replace(' ','') for v in perm[6:].split(',')]
387
            if '*' in ret['write']:
388
                ret['write'] = ['*']
385 389
            if len(ret['write']) == 0:
386 390
                raise BadRequest('Bad X-Object-Sharing header value')
387 391
        else:
388 392
            raise BadRequest('Bad X-Object-Sharing header value')
393
    if 'private' in ret:
394
        if 'read' in ret:
395
            del(ret['read'])
396
        if 'write' in ret:
397
            del(ret['write'])
389 398
    return ret
390 399

  
391 400
def raw_input_socket(request):

Also available in: Unified diff