Revision 7efc9f86 snf-pithos-app/pithos/api/functions.py
b/snf-pithos-app/pithos/api/functions.py | ||
---|---|---|
54 | 54 |
SaveToBackendHandler, object_data_response, put_object_block, hashmap_md5, simple_list_response, api_method) |
55 | 55 |
from pithos.api.settings import UPDATE_MD5 |
56 | 56 |
|
57 |
from pithos.backends.base import NotAllowedError, QuotaError |
|
57 |
from pithos.backends.base import NotAllowedError, QuotaError, ContainerNotEmpty, ItemNotExists, VersionNotExists |
|
58 |
|
|
58 | 59 |
from pithos.backends.filter import parse_filters |
59 | 60 |
|
60 | 61 |
import logging |
... | ... | |
330 | 331 |
v_container) |
331 | 332 |
except NotAllowedError: |
332 | 333 |
raise Forbidden('Not allowed') |
333 |
except NameError:
|
|
334 |
except ItemNotExists:
|
|
334 | 335 |
raise ItemNotFound('Container does not exist') |
335 | 336 |
|
336 | 337 |
validate_modification_preconditions(request, meta) |
... | ... | |
365 | 366 |
v_container, policy, replace=False) |
366 | 367 |
except NotAllowedError: |
367 | 368 |
raise Forbidden('Not allowed') |
368 |
except NameError:
|
|
369 |
except ItemNotExists:
|
|
369 | 370 |
raise ItemNotFound('Container does not exist') |
370 | 371 |
except ValueError: |
371 | 372 |
raise BadRequest('Invalid policy header') |
... | ... | |
375 | 376 |
v_container, 'pithos', meta, replace=False) |
376 | 377 |
except NotAllowedError: |
377 | 378 |
raise Forbidden('Not allowed') |
378 |
except NameError:
|
|
379 |
except ItemNotExists:
|
|
379 | 380 |
raise ItemNotFound('Container does not exist') |
380 | 381 |
|
381 | 382 |
return HttpResponse(status=ret) |
... | ... | |
398 | 399 |
v_container, policy, replace) |
399 | 400 |
except NotAllowedError: |
400 | 401 |
raise Forbidden('Not allowed') |
401 |
except NameError:
|
|
402 |
except ItemNotExists:
|
|
402 | 403 |
raise ItemNotFound('Container does not exist') |
403 | 404 |
except ValueError: |
404 | 405 |
raise BadRequest('Invalid policy header') |
... | ... | |
408 | 409 |
v_container, 'pithos', meta, replace) |
409 | 410 |
except NotAllowedError: |
410 | 411 |
raise Forbidden('Not allowed') |
411 |
except NameError:
|
|
412 |
except ItemNotExists:
|
|
412 | 413 |
raise ItemNotFound('Container does not exist') |
413 | 414 |
|
414 | 415 |
content_length = -1 |
... | ... | |
443 | 444 |
until) |
444 | 445 |
except NotAllowedError: |
445 | 446 |
raise Forbidden('Not allowed') |
446 |
except NameError:
|
|
447 |
except ItemNotExists:
|
|
447 | 448 |
raise ItemNotFound('Container does not exist') |
448 |
except IndexError:
|
|
449 |
except ContainerNotEmpty:
|
|
449 | 450 |
raise Conflict('Container is not empty') |
450 | 451 |
return HttpResponse(status=204) |
451 | 452 |
|
... | ... | |
467 | 468 |
v_container) |
468 | 469 |
except NotAllowedError: |
469 | 470 |
raise Forbidden('Not allowed') |
470 |
except NameError:
|
|
471 |
except ItemNotExists:
|
|
471 | 472 |
raise ItemNotFound('Container does not exist') |
472 | 473 |
|
473 | 474 |
validate_modification_preconditions(request, meta) |
... | ... | |
524 | 525 |
until, None, public) |
525 | 526 |
except NotAllowedError: |
526 | 527 |
raise Forbidden('Not allowed') |
527 |
except NameError:
|
|
528 |
except ItemNotExists:
|
|
528 | 529 |
raise ItemNotFound('Container does not exist') |
529 | 530 |
|
530 | 531 |
if len(objects) == 0: |
... | ... | |
553 | 554 |
object_public[k[name_idx:]] = v |
554 | 555 |
except NotAllowedError: |
555 | 556 |
raise Forbidden('Not allowed') |
556 |
except NameError:
|
|
557 |
except ItemNotExists:
|
|
557 | 558 |
raise ItemNotFound('Container does not exist') |
558 | 559 |
|
559 | 560 |
object_meta = [] |
... | ... | |
610 | 611 |
public = None |
611 | 612 |
except NotAllowedError: |
612 | 613 |
raise Forbidden('Not allowed') |
613 |
except NameError:
|
|
614 |
except ItemNotExists:
|
|
614 | 615 |
raise ItemNotFound('Object does not exist') |
615 |
except IndexError:
|
|
616 |
except VersionNotExists:
|
|
616 | 617 |
raise ItemNotFound('Version does not exist') |
617 | 618 |
|
618 | 619 |
update_manifest_meta(request, v_account, meta) |
... | ... | |
679 | 680 |
public = None |
680 | 681 |
except NotAllowedError: |
681 | 682 |
raise Forbidden('Not allowed') |
682 |
except NameError:
|
|
683 |
except ItemNotExists:
|
|
683 | 684 |
raise ItemNotFound('Object does not exist') |
684 |
except IndexError:
|
|
685 |
except VersionNotExists:
|
|
685 | 686 |
raise ItemNotFound('Version does not exist') |
686 | 687 |
|
687 | 688 |
update_manifest_meta(request, v_account, meta) |
... | ... | |
712 | 713 |
raise Forbidden('Not allowed') |
713 | 714 |
except ValueError: |
714 | 715 |
raise BadRequest('Invalid X-Object-Manifest header') |
715 |
except NameError:
|
|
716 |
except ItemNotExists:
|
|
716 | 717 |
raise ItemNotFound('Container does not exist') |
717 | 718 |
|
718 | 719 |
try: |
... | ... | |
723 | 724 |
hashmaps.append(h) |
724 | 725 |
except NotAllowedError: |
725 | 726 |
raise Forbidden('Not allowed') |
726 |
except NameError:
|
|
727 |
except ItemNotExists:
|
|
727 | 728 |
raise ItemNotFound('Object does not exist') |
728 |
except IndexError:
|
|
729 |
except VersionNotExists:
|
|
729 | 730 |
raise ItemNotFound('Version does not exist') |
730 | 731 |
else: |
731 | 732 |
try: |
... | ... | |
735 | 736 |
hashmaps.append(h) |
736 | 737 |
except NotAllowedError: |
737 | 738 |
raise Forbidden('Not allowed') |
738 |
except NameError:
|
|
739 |
except ItemNotExists:
|
|
739 | 740 |
raise ItemNotFound('Object does not exist') |
740 |
except IndexError:
|
|
741 |
except VersionNotExists:
|
|
741 | 742 |
raise ItemNotFound('Version does not exist') |
742 | 743 |
|
743 | 744 |
# Reply with the hashmap. |
... | ... | |
877 | 878 |
raise Forbidden('Not allowed') |
878 | 879 |
except IndexError, e: |
879 | 880 |
raise Conflict(simple_list_response(request, e.data)) |
880 |
except NameError:
|
|
881 |
except ItemNotExists:
|
|
881 | 882 |
raise ItemNotFound('Container does not exist') |
882 | 883 |
except ValueError: |
883 | 884 |
raise BadRequest('Invalid sharing header') |
... | ... | |
897 | 898 |
v_container, v_object, public) |
898 | 899 |
except NotAllowedError: |
899 | 900 |
raise Forbidden('Not allowed') |
900 |
except NameError:
|
|
901 |
except ItemNotExists:
|
|
901 | 902 |
raise ItemNotFound('Object does not exist') |
902 | 903 |
|
903 | 904 |
response = HttpResponse(status=201) |
... | ... | |
926 | 927 |
file.hashmap, checksum, 'pithos', {}, True) |
927 | 928 |
except NotAllowedError: |
928 | 929 |
raise Forbidden('Not allowed') |
929 |
except NameError:
|
|
930 |
except ItemNotExists:
|
|
930 | 931 |
raise ItemNotFound('Container does not exist') |
931 | 932 |
except QuotaError: |
932 | 933 |
raise RequestEntityTooLarge('Quota exceeded') |
... | ... | |
964 | 965 |
v_container, v_object, 'pithos', src_version) |
965 | 966 |
except NotAllowedError: |
966 | 967 |
raise Forbidden('Not allowed') |
967 |
except (NameError, IndexError):
|
|
968 |
except (ItemNotExists, VersionNotExists):
|
|
968 | 969 |
raise ItemNotFound('Container or object does not exist') |
969 | 970 |
validate_matching_preconditions(request, meta) |
970 | 971 |
|
... | ... | |
1002 | 1003 |
v_container, v_object, 'pithos') |
1003 | 1004 |
except NotAllowedError: |
1004 | 1005 |
raise Forbidden('Not allowed') |
1005 |
except NameError:
|
|
1006 |
except ItemNotExists:
|
|
1006 | 1007 |
raise ItemNotFound('Container or object does not exist') |
1007 | 1008 |
validate_matching_preconditions(request, meta) |
1008 | 1009 |
|
... | ... | |
1030 | 1031 |
v_container, v_object, 'pithos') |
1031 | 1032 |
except NotAllowedError: |
1032 | 1033 |
raise Forbidden('Not allowed') |
1033 |
except NameError:
|
|
1034 |
except ItemNotExists:
|
|
1034 | 1035 |
raise ItemNotFound('Object does not exist') |
1035 | 1036 |
|
1036 | 1037 |
# Evaluate conditions. |
... | ... | |
1053 | 1054 |
v_account, v_container, v_object, permissions) |
1054 | 1055 |
except NotAllowedError: |
1055 | 1056 |
raise Forbidden('Not allowed') |
1056 |
except NameError:
|
|
1057 |
except ItemNotExists:
|
|
1057 | 1058 |
raise ItemNotFound('Object does not exist') |
1058 | 1059 |
except ValueError: |
1059 | 1060 |
raise BadRequest('Invalid sharing header') |
... | ... | |
1063 | 1064 |
v_container, v_object, public) |
1064 | 1065 |
except NotAllowedError: |
1065 | 1066 |
raise Forbidden('Not allowed') |
1066 |
except NameError:
|
|
1067 |
except ItemNotExists:
|
|
1067 | 1068 |
raise ItemNotFound('Object does not exist') |
1068 | 1069 |
if meta or replace: |
1069 | 1070 |
try: |
... | ... | |
1071 | 1072 |
v_account, v_container, v_object, 'pithos', meta, replace) |
1072 | 1073 |
except NotAllowedError: |
1073 | 1074 |
raise Forbidden('Not allowed') |
1074 |
except NameError:
|
|
1075 |
except ItemNotExists:
|
|
1075 | 1076 |
raise ItemNotFound('Object does not exist') |
1076 | 1077 |
response['X-Object-Version'] = version_id |
1077 | 1078 |
|
... | ... | |
1092 | 1093 |
v_account, v_container, v_object) |
1093 | 1094 |
except NotAllowedError: |
1094 | 1095 |
raise Forbidden('Not allowed') |
1095 |
except NameError:
|
|
1096 |
except ItemNotExists:
|
|
1096 | 1097 |
raise ItemNotFound('Object does not exist') |
1097 | 1098 |
|
1098 | 1099 |
offset, length, total = ranges |
... | ... | |
1111 | 1112 |
src_account, src_container, src_name, src_version) |
1112 | 1113 |
except NotAllowedError: |
1113 | 1114 |
raise Forbidden('Not allowed') |
1114 |
except NameError:
|
|
1115 |
except ItemNotExists:
|
|
1115 | 1116 |
raise ItemNotFound('Source object does not exist') |
1116 | 1117 |
|
1117 | 1118 |
if length is None: |
... | ... | |
1197 | 1198 |
hashmap, checksum, 'pithos', meta, replace, permissions) |
1198 | 1199 |
except NotAllowedError: |
1199 | 1200 |
raise Forbidden('Not allowed') |
1200 |
except NameError:
|
|
1201 |
except ItemNotExists:
|
|
1201 | 1202 |
raise ItemNotFound('Container does not exist') |
1202 | 1203 |
except ValueError: |
1203 | 1204 |
raise BadRequest('Invalid sharing header') |
... | ... | |
1209 | 1210 |
v_container, v_object, public) |
1210 | 1211 |
except NotAllowedError: |
1211 | 1212 |
raise Forbidden('Not allowed') |
1212 |
except NameError:
|
|
1213 |
except ItemNotExists:
|
|
1213 | 1214 |
raise ItemNotFound('Object does not exist') |
1214 | 1215 |
|
1215 | 1216 |
response = HttpResponse(status=204) |
... | ... | |
1233 | 1234 |
v_object, until, delimiter=delimiter) |
1234 | 1235 |
except NotAllowedError: |
1235 | 1236 |
raise Forbidden('Not allowed') |
1236 |
except NameError:
|
|
1237 |
except ItemNotExists:
|
|
1237 | 1238 |
raise ItemNotFound('Object does not exist') |
1238 | 1239 |
return HttpResponse(status=204) |
1239 | 1240 |
|
Also available in: Unified diff