Revision cf341da4 pithos/backends/lib/sqlalchemy/xfeatures.py

b/pithos/backends/lib/sqlalchemy/xfeatures.py
72 72
        
73 73
        s = select([self.xfeatures.c.path, self.xfeatures.c.feature_id])
74 74
        s = s.where(self.xfeatures.c.path <= path)
75
        s = s.order_by(desc(self.xfeatures.c.path)).limit(1)
75
        #s = s.where(self.xfeatures.c.path.like(self.escape_like(path) + '%', escape='\\')) # XXX: Implement reverse and escape like...
76
        s = s.order_by(desc(self.xfeatures.c.path))
76 77
        r = self.conn.execute(s)
77
        row = r.fetchone()
78
        l = r.fetchall()
78 79
        r.close()
79
        if row and path.startswith(row[0]):
80
            return row
81
        else:
82
            return None
80
        return l
83 81
    
84
    def xfeature_list(self, path):
85
        """Return the list of the (prefix, feature) pairs matching path.
86
           A prefix matches path if either the prefix includes the path,
87
           or the path includes the prefix.
88
        """
89
        
90
        inherited = self.xfeature_inherit(path)
91
        if inherited:
92
            return [inherited]
82
    def xfeature_get(self, path):
83
        """Return feature for path."""
93 84
        
94
        s = select([self.xfeatures.c.path, self.xfeatures.c.feature_id])
95
        s = s.where(and_(self.xfeatures.c.path.like(self.escape_like(path) + '%', escape='\\'),
96
                     self.xfeatures.c.path != path))
85
        s = select([self.xfeatures.c.feature_id])
86
        s = s.where(self.xfeatures.c.path == path)
97 87
        s = s.order_by(self.xfeatures.c.path)
98 88
        r = self.conn.execute(s)
99
        l = r.fetchall()
89
        row = r.fetchone()
100 90
        r.close()
101
        return l
91
        if row:
92
            return row[0]
93
        return None
102 94
    
103 95
    def xfeature_create(self, path):
104 96
        """Create and return a feature for path.
105
           If the path already inherits a feature or
106
           bestows to paths already inheriting a feature,
107
           create no feature and return None.
108 97
           If the path has a feature, return it.
109 98
        """
110 99
        
111
        prefixes = self.xfeature_list(path)
112
        pl = len(prefixes)
113
        if (pl > 1) or (pl == 1 and prefixes[0][0] != path):
114
            return None
115
        if pl == 1 and prefixes[0][0] == path:
116
            return prefixes[0][1]
100
        feature = self.xfeature_get(path)
101
        if feature is not None:
102
            return feature
117 103
        s = self.xfeatures.insert()
118 104
        r = self.conn.execute(s, path=path)
119 105
        inserted_primary_key = r.inserted_primary_key[0]

Also available in: Unified diff