Revision 6f4bce7b pithos/backends/lib/xfeatures.py

b/pithos/backends/lib/xfeatures.py
31 31
# interpreted as representing official policies, either expressed
32 32
# or implied, of GRNET S.A.
33 33

  
34
from collections import defaultdict
35

  
34 36
from dbworker import DBWorker
35 37

  
36 38

  
......
91 93
           If the path already inherits a feature or
92 94
           bestows to paths already inheriting a feature,
93 95
           create no feature and return None.
96
           If the path has a feature, return it.
94 97
        """
95 98
        
96 99
        prefixes = self.xfeature_list(path)
97 100
        pl = len(prefixes)
98 101
        if (pl > 1) or (pl == 1 and prefixes[0][0] != path):
99 102
            return None
103
        if pl == 1 and prefixes[0][0] == path:
104
            return prefixes[0][1]
100 105
        q = "insert into xfeatures (path) values (?)"
101 106
        id = self.execute(q, (path,)).lastrowid
102 107
        return id
......
107 112
        q = "delete from xfeatures where path = ?"
108 113
        self.execute(q, (path,))
109 114
    
110
    def feature_list(self, feature):
111
        """Return the list of all key, value pairs
112
           associated with a feature.
113
        """
115
    def feature_dict(self, feature):
116
        """Return a dict mapping keys to list of values for feature."""
114 117
        
115 118
        q = "select key, value from xfeaturevals where feature = ?"
116 119
        self.execute(q, (feature,))
117
        return self.fetchall()
120
        d = defaultdict(list)
121
        for key, value in self.fetchall():
122
            d[key].append(value)
123
        return d
118 124
    
119 125
    def feature_set(self, feature, key, value):
120 126
        """Associate a key, value pair with a feature."""

Also available in: Unified diff