Changeset 01d3cf in indico
- Timestamp:
- 03/26/12 16:49:50 (14 months ago)
- Branches:
- master, hello-world-walkthrough, ipv6, v0.98-series, v0.98.2, v0.98.3, v0.99, 051b2622c51afb171a1dedb46a0df4fbb0cbd02e, 0da0c1403bae8e51d8229f460181c71b9e6dda72
- Children:
- 13903d
- Parents:
- 6a90d1
- File:
-
- 1 edited
-
indico/util/fossilize/__init__.py (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
indico/util/fossilize/__init__.py
r4fd80c r01d3cf 95 95 __methodNameCache = {} 96 96 __fossilNameCache = {} 97 __fossilInterfaceCache = {} 97 98 __fossilAttrsCache = {} # Attribute Cache for Fossils with 98 99 # fields that are repeated … … 272 273 result = {} 273 274 274 for method in interface: 275 276 tags = interface[method].getTaggedValueTags() 275 # cache method names for each interface 276 names = cls.__fossilInterfaceCache.get(interface) 277 if names is None: 278 names = interface.names(all=True) 279 cls.__fossilInterfaceCache[interface] = names 280 ### 281 282 for methodName in names: 283 284 method = interface[methodName] 285 286 tags = method.getTaggedValueTags() 277 287 isAttribute = False 278 288 … … 282 292 if useAttrCache: 283 293 try: 284 methodResult = cls.__fossilAttrsCache[obj._p_oid][method ]294 methodResult = cls.__fossilAttrsCache[obj._p_oid][methodName] 285 295 cacheUsed = True 286 296 except KeyError: … … 290 300 # there is almost always a more elegant and modular solution! 291 301 if 'produce' in tags: 292 methodResult = interface[method].getTaggedValue('produce')(obj)302 methodResult = method.getTaggedValue('produce')(obj) 293 303 else: 294 attr = getattr(obj, method )304 attr = getattr(obj, methodName) 295 305 if callable(attr): 296 306 try: … … 305 315 306 316 if hasattr(obj, "_p_oid"): 307 try: 308 cls.__fossilAttrsCache[obj._p_oid] 309 except KeyError: 310 cls.__fossilAttrsCache[obj._p_oid] = {} 311 cls.__fossilAttrsCache[obj._p_oid][method] = methodResult 317 cls.__fossilAttrsCache.setdefault(obj._p_oid, {})[methodName] = methodResult 312 318 313 319 if 'filterBy' in tags: 314 320 if 'filters' not in kwargs: 315 321 raise Exception('No filters defined!') 316 filterName = interface[method].getTaggedValue('filterBy')322 filterName = method.getTaggedValue('filterBy') 317 323 318 324 if filterName in kwargs['filters']: … … 325 331 # Result conversion 326 332 if 'result' in tags: 327 targetInterface = interface[method].getTaggedValue('result')333 targetInterface = method.getTaggedValue('result') 328 334 #targetInterface = globals()[targetInterfaceName] 329 335 … … 333 339 # Conversion function 334 340 if 'convert' in tags: 335 convertFunction = interface[method].getTaggedValue('convert')341 convertFunction = method.getTaggedValue('convert') 336 342 converterArgNames = inspect.getargspec(convertFunction)[0] 337 343 converterArgs = dict((name, kwargs[name]) … … 342 348 except: 343 349 logging.getLogger('indico.fossilize').error("Problem fossilizing '%r' with '%s' (%s)" % 344 (obj, interfaceArg, method ))350 (obj, interfaceArg, methodName)) 345 351 raise 346 352 … … 348 354 # Re-name the attribute produced by the method 349 355 if 'name' in tags: 350 attrName = interface[method].getTaggedValue('name')356 attrName = method.getTaggedValue('name') 351 357 elif isAttribute: 352 attrName = method 353 else: 354 attrName = cls.__extractName(method )358 attrName = methodName 359 else: 360 attrName = cls.__extractName(methodName) 355 361 356 362 # In case the name contains dots, each of the 'domains' but the … … 367 373 while len(attrList) > 1: 368 374 attr = attrList.pop(0) 369 try: 370 current = current[attr] 371 except KeyError: 375 if attr not in current: 372 376 current[attr] = {} 373 current = current[attr]377 current = current[attr] 374 378 375 379 # For the last attribute level
Note: See TracChangeset
for help on using the changeset viewer.
