Changeset 76
- Timestamp:
- 06/27/05 05:24:59
- Files:
-
- trunk/__init__.py (modified) (previous)
- trunk/engines.py (modified) (previous)
- trunk/storage/__init__.py (modified) (previous)
- trunk/storage/db.py (modified) (3 diffs)
- trunk/storage/sockets.py (modified) (previous)
- trunk/storage/storeado.py (modified) (previous)
- trunk/storage/storeshelve.py (modified) (1 diff)
- trunk/storage/zoo_fixture.py (modified) (previous)
- trunk/zoo.py (modified) (previous)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/storage/db.py
r75 r76 47 47 import warnings 48 48 import threading 49 50 51 def getCoerceName(value, valuetype=None): 52 mod = valuetype.__module__ 53 if mod == "__builtin__": 54 xform = "coerce_%s" % valuetype.__name__ 55 else: 56 xform = "coerce_%s_%s" % (mod, valuetype.__name__) 57 xform = xform.replace(".", "_") 58 return xform 59 60 def getCoerceMethod(obj, value, valuetype=None): 61 if valuetype is None: 62 valuetype = type(value) 63 64 meth = getCoerceName(value, valuetype) 65 if hasattr(obj, meth): 66 return getattr(obj, meth) 67 68 methods = [] 69 for base in valuetype.__bases__: 70 meth = getCoerceName(value, base) 71 methods.append(meth) 72 if hasattr(obj, meth): 73 return getattr(obj, meth) 74 75 raise TypeError("'%s' is not handled by %s. Looked for: %s " % 76 (valuetype, obj.__class__, ",".join(methods))) 49 77 50 78 … … 200 228 def coerce(self, value, valuetype=None): 201 229 """coerce(value, valuetype=None) -> value, coerced by valuetype.""" 202 if valuetype is None: 203 valuetype = type(value) 204 205 mod = valuetype.__module__ 206 if mod == "__builtin__": 207 xform = "coerce_%s" % valuetype.__name__ 208 else: 209 xform = "coerce_%s_%s" % (mod, valuetype.__name__) 210 xform = xform.replace(".", "_") 211 try: 212 xform = getattr(self, xform) 213 except AttributeError: 214 raise TypeError("'%s' is not handled by %s." % 215 (valuetype, self.__class__)) 216 return xform(value) 230 meth = getCoerceMethod(self, value, valuetype) 231 return meth(value) 217 232 218 233 def tostr(self, value): … … 288 303 return None 289 304 290 if valuetype is None: 291 valuetype = type(value) 292 293 mod = valuetype.__module__ 294 if mod == "__builtin__": 295 xform = "coerce_%s" % valuetype.__name__ 296 else: 297 xform = "coerce_%s_%s" % (mod, valuetype.__name__) 298 xform = xform.replace(".", "_") 299 try: 300 xform = getattr(self, xform) 301 except AttributeError: 302 raise TypeError("'%s' is not handled by %s." % 303 (valuetype, self.__class__)) 304 return xform(value, coltype) 305 meth = getCoerceMethod(self, value, valuetype) 306 return meth(value, coltype) 305 307 306 308 def consume(self, unit, key, value, coltype): trunk/storage/storeshelve.py
r75 r76 135 135 def multirecall(self, *pairs): 136 136 """multirecall(*pairs) -> Full inner join units for each (cls, expr) pair.""" 137 raise NotImplementedError("This method doesn't yet work for shelve.") 138 unitsets = [] 137 ## raise NotImplementedError("This method doesn't yet work for shelve.") 138 pairs = list(pairs) 139 firstcls, firstexpr = pairs.pop(0) 140 masterset = [[x] for x in self.recall(firstcls, firstexpr)] 139 141 140 firstcls = pairs[0][0]141 142 for cls, expr in pairs: 142 if cls is not firstcls: 143 spath = self.arena.associations.shortest_path(firstcls, cls) 144 # This should be firstcls in every case. 145 cls1 = spath.pop(0) 146 for cls2 in spath: 147 leftkey, rightkey = cls1._associations[cls2] 148 wheres.append("(%s.%s = %s.%s)" % 149 (t(cls1), i(leftkey), 150 t(cls2), i(rightkey))) 151 cls1 = cls2 152 join = logic.Expression() 153 expr = expr + join 143 tests = [] 144 spath = self.arena.associations.shortest_path(firstcls, cls) 145 cls1 = spath.pop(0) # This should be firstcls in every case. 146 for cls2 in spath: 147 subset = [x for x in self.recall(cls2, expr)] 148 leftkey, rightkey = cls1._associations[cls2] 149 tests.append((subset, leftkey, rightkey)) 150 cls1 = cls2 154 151 155 unitset = [unit for unit in self.recall(cls, expr)] 156 unitsets.append(unitset) 152 newmasterset = [] 153 for row in masterset: 154 list1 = [row[0]] 155 for subset, leftkey, rightkey in tests: 156 matches = [] 157 for unit1 in list1: 158 matches.extend([unit2 for unit2 in subset 159 if getattr(unit1, leftkey) 160 == getattr(unit2, rightkey)]) 161 list1 = matches 162 163 # Take the final matches and join each with the current row. 164 for unit in matches: 165 newmasterset.append(row + [unit]) 166 masterset = newmasterset 157 167 158 for unitset in unitsets: 159 yield unitset 168 return masterset 160 169
