Changeset 381
- Timestamp:
- 06/25/05 15:01:48
- Files:
-
- trunk/cherrypy/_cputil.py (modified) (2 diffs)
- trunk/cherrypy/lib/cptools.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/cherrypy/_cputil.py
r377 r381 65 65 66 66 def getSpecialAttribute(name): 67 """ Return the special attribute """ 67 """ Return the special attribute. A special attribute is 68 one that applies to all of the children from where it is 69 defined, such as _cpFilterList.""" 68 70 69 71 # First, we look in the right-most object if this special attribute is implemented. … … 86 88 % repr(name)) 87 89 90 def getSpecialAttributePath(name): 91 """ Return the path to the special attribute """ 92 objectList = getObjectTrail() 93 if objectList: 94 pathList = (cpg.request.objectPath or cpg.request.path).split("/")[1:] 95 for i in xrange(len(objectList) - 1, -1, -1): 96 if hasattr(objectList[i], name): 97 return "/" + "/".join(pathList[:i] + [name]) 98 raise cperror.InternalError("Special attribute %s could not be found" 99 % repr(name)) 88 100 89 101 def _cpLogMessage(msg, context = '', severity = 0): trunk/cherrypy/lib/cptools.py
r376 r381 28 28 29 29 """ 30 Just a few convenient functions 30 Just a few convenient functions and classes. 31 31 """ 32 33 import inspect 34 35 def decorate(func, decorator): 36 """ 37 Return the decorated func. This will automatically copy all 38 non-standard attributes (like exposed) to the newly decorated function. 39 """ 40 newfunc = decorator(func) 41 for (k,v) in inspect.getmembers(func): 42 if not hasattr(newfunc, k): 43 setattr(newfunc, k, v) 44 return newfunc 45 46 def decorateAll(obj, decorator): 47 """ 48 Recursively decorate all exposed functions of obj and all of its children, 49 grandchildren, etc. If you used to use aspects, you might want to look 50 into these. This function modifies obj; there is no return value. 51 """ 52 obj_type = type(obj) 53 for (k,v) in inspect.getmembers(obj): 54 if hasattr(obj_type, k): # only deal with user-defined attributes 55 continue 56 if callable(v) and getattr(v, "exposed", False): 57 setattr(obj, k, decorate(v, decorator)) 58 decorateAll(v, decorator) 32 59 33 60 class ExposeItems:

