Revision 7efc9f86 snf-pithos-backend/pithos/backends/modular.py

b/snf-pithos-backend/pithos/backends/modular.py
39 39
import hashlib
40 40
import binascii
41 41

  
42
from base import DEFAULT_QUOTA, DEFAULT_VERSIONING, NotAllowedError, QuotaError, BaseBackend
42
from base import DEFAULT_QUOTA, DEFAULT_VERSIONING, NotAllowedError, QuotaError, BaseBackend, \
43
    AccountExists, ContainerExists, AccountNotEmpty, ContainerNotEmpty, ItemNotExists, VersionNotExists
43 44

  
44 45
# Stripped-down version of the HashMap class found in tools.
45 46
class HashMap(list):
......
292 293
            raise NotAllowedError
293 294
        node = self.node.node_lookup(account)
294 295
        if node is not None:
295
            raise NameError('Account already exists')
296
            raise AccountExists('Account already exists')
296 297
        if policy:
297 298
            self._check_policy(policy)
298 299
        node = self._put_path(user, self.ROOTNODE, account)
......
309 310
        if node is None:
310 311
            return
311 312
        if not self.node.node_remove(node):
312
            raise IndexError('Account is not empty')
313
            raise AccountNotEmpty('Account is not empty')
313 314
        self.permissions.group_destroy(account)
314 315
    
315 316
    @backend_method
......
434 435
        except NameError:
435 436
            pass
436 437
        else:
437
            raise NameError('Container already exists')
438
            raise ContainerExists('Container already exists')
438 439
        if policy:
439 440
            self._check_policy(policy)
440 441
        path = '/'.join((account, container))
......
459 460
            return
460 461
        
461 462
        if self._get_statistics(node)[0] > 0:
462
            raise IndexError('Container is not empty')
463
            raise ContainerNotEmpty('Container is not empty')
463 464
        hashes, size = self.node.node_purge_children(node, inf, CLUSTER_HISTORY)
464 465
        for h in hashes:
465 466
            self.store.map_delete(h)
......
601 602
            except NameError: # Object may be deleted.
602 603
                del_props = self.node.version_lookup(node, inf, CLUSTER_DELETED)
603 604
                if del_props is None:
604
                    raise NameError('Object does not exist')
605
                    raise ItemNotExists('Object does not exist')
605 606
                modified = del_props[self.MTIME]
606 607
        
607 608
        meta = {}
......
919 920
        logger.debug("get_block: %s", hash)
920 921
        block = self.store.block_get(binascii.unhexlify(hash))
921 922
        if not block:
922
            raise NameError('Block does not exist')
923
            raise ItemNotExists('Block does not exist')
923 924
        return block
924 925
    
925 926
    @backend_method(autocommit=0)
......
966 967
        path = '/'.join((account, container))
967 968
        node = self.node.node_lookup(path)
968 969
        if node is None:
969
            raise NameError('Container does not exist')
970
            raise ItemNotExists('Container does not exist')
970 971
        return path, node
971 972
    
972 973
    def _lookup_object(self, account, container, name):
973 974
        path = '/'.join((account, container, name))
974 975
        node = self.node.node_lookup(path)
975 976
        if node is None:
976
            raise NameError('Object does not exist')
977
            raise ItemNotExists('Object does not exist')
977 978
        return path, node
978 979
    
979 980
    def _lookup_objects(self, paths):
980
    	nodes = self.node.node_lookup_bulk(paths)
981
        if nodes is None:
982
            raise NameError('Object does not exist')
981
        nodes = self.node.node_lookup_bulk(paths)
983 982
        return paths, nodes
984 983
    
985 984
    def _get_properties(self, node, until=None):
......
990 989
        if props is None and until is not None:
991 990
            props = self.node.version_lookup(node, before, CLUSTER_HISTORY)
992 991
        if props is None:
993
            raise NameError('Path does not exist')
992
            raise ItemNotExists('Path does not exist')
994 993
        return props
995 994
    
996 995
    def _get_statistics(self, node, until=None):
......
1008 1007
        if version is None:
1009 1008
            props = self.node.version_lookup(node, inf, CLUSTER_NORMAL)
1010 1009
            if props is None:
1011
                raise NameError('Object does not exist')
1010
                raise ItemNotExists('Object does not exist')
1012 1011
        else:
1013 1012
            try:
1014 1013
                version = int(version)
1015 1014
            except ValueError:
1016
                raise IndexError('Version does not exist')
1015
                raise VersionNotExists('Version does not exist')
1017 1016
            props = self.node.version_get_properties(version)
1018 1017
            if props is None or props[self.CLUSTER] == CLUSTER_DELETED:
1019
                raise IndexError('Version does not exist')
1018
                raise VersionNotExists('Version does not exist')
1020 1019
        return props
1021 1020

  
1022
    def _get_versions(self, nodes, version=None):
1023
        if version is None:
1024
            props = self.node.version_lookup_bulk(nodes, inf, CLUSTER_NORMAL)
1025
            if not props:
1026
                raise NameError('Object does not exist')
1027
        else:
1028
            try:
1029
                version = int(version)
1030
            except ValueError:
1031
                raise IndexError('Version does not exist')
1032
            props = self.node.version_get_properties(version)
1033
            if props is None or props[self.CLUSTER] == CLUSTER_DELETED:
1034
                raise IndexError('Version does not exist')
1035
        return props
1021
    def _get_versions(self, nodes):
1022
        return self.node.version_lookup_bulk(nodes, inf, CLUSTER_NORMAL)
1036 1023
    
1037 1024
    def _put_version_duplicate(self, user, node, src_node=None, size=None, type=None, hash=None, checksum=None, cluster=CLUSTER_NORMAL, is_copy=False):
1038 1025
        """Create a new version of the node."""

Also available in: Unified diff