diff options
author | Robert Brewer <fumanchu@aminus.org> | 2005-06-25 20:37:39 +0000 |
---|---|---|
committer | Robert Brewer <fumanchu@aminus.org> | 2005-06-25 20:37:39 +0000 |
commit | 931880f918dc3d056640a521b2cab4ff7f0894e7 (patch) | |
tree | f73ee8133eba3d4540dd531e13ade80aa5d2e101 /cherrypy/lib/cptools.py | |
parent | 95b1f7e9c51fde72758e60bd69c0875719ab2117 (diff) | |
download | cherrypy-git-931880f918dc3d056640a521b2cab4ff7f0894e7.tar.gz |
Implements ticket #195.
1. cpg module removed, all content moved into cherrypy.__init__.
2. Removed some circular imports in sessionfilter by moving sessionfilter.sessionfilter and _sessionTypes into sessionfilter.__init__.
3. renamed _cpconfig to "config".
4. renamed _cpserver to "server".
5. renamed cperror to _cperror; cherrypy.__init__ now imports * from _cperror.
Diffstat (limited to 'cherrypy/lib/cptools.py')
-rw-r--r-- | cherrypy/lib/cptools.py | 67 |
1 files changed, 34 insertions, 33 deletions
diff --git a/cherrypy/lib/cptools.py b/cherrypy/lib/cptools.py index 295a4f7e..99515be2 100644 --- a/cherrypy/lib/cptools.py +++ b/cherrypy/lib/cptools.py @@ -27,35 +27,36 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. """ """ -Just a few convenient functions and classes. +Just a few convenient functions and classes """ -
-import inspect
-
-def decorate(func, decorator):
- """
- Return the decorated func. This will automatically copy all
- non-standard attributes (like exposed) to the newly decorated function.
- """
- newfunc = decorator(func)
- for (k,v) in inspect.getmembers(func):
- if not hasattr(newfunc, k):
- setattr(newfunc, k, v)
- return newfunc
-
-def decorateAll(obj, decorator):
- """
- Recursively decorate all exposed functions of obj and all of its children,
- grandchildren, etc. If you used to use aspects, you might want to look
- into these. This function modifies obj; there is no return value.
- """
- obj_type = type(obj)
- for (k,v) in inspect.getmembers(obj):
- if hasattr(obj_type, k): # only deal with user-defined attributes
- continue
- if callable(v) and getattr(v, "exposed", False):
- setattr(obj, k, decorate(v, decorator))
- decorateAll(v, decorator)
+ +import inspect + +def decorate(func, decorator): + """ + Return the decorated func. This will automatically copy all + non-standard attributes (like exposed) to the newly decorated function. + """ + newfunc = decorator(func) + for (k,v) in inspect.getmembers(func): + if not hasattr(newfunc, k): + setattr(newfunc, k, v) + return newfunc + +def decorateAll(obj, decorator): + """ + Recursively decorate all exposed functions of obj and all of its children, + grandchildren, etc. If you used to use aspects, you might want to look + into these. This function modifies obj; there is no return value. + """ + obj_type = type(obj) + for (k,v) in inspect.getmembers(obj): + if hasattr(obj_type, k): # only deal with user-defined attributes + continue + if callable(v) and getattr(v, "exposed", False): + setattr(obj, k, decorate(v, decorator)) + decorateAll(v, decorator) + class ExposeItems: """ @@ -68,8 +69,8 @@ class ExposeItems: from cherrypy.lib.cptools import ExposeItems ... - cpg.root.foo = ExposeItems(mylist) - cpg.root.bar = ExposeItems(mydict) + cherrypy.root.foo = ExposeItems(mylist) + cherrypy.root.bar = ExposeItems(mydict) """ exposed = True def __init__(self, items): @@ -85,13 +86,13 @@ class PositionalParametersAware(object): Use case: from cherrypy.lib import cptools - from cherrypy import cpg + import cherrypy class Root(cptools.PositionalParametersAware): def something(self, name): return "hello, " + name something.exposed - cpg.root = Root() - cpg.server.start() + cherrypy.root = Root() + cherrypy.server.start() Now, fetch http://localhost:8080/something/name_is_here """ |