From dc5e452649dbc0d452c64f32875d38e25d018367 Mon Sep 17 00:00:00 2001 From: Greg Price Date: Wed, 30 Jul 2008 21:05:33 -0400 Subject: [PATCH] expand with_* docstrings in invirt.common svn path=/trunk/packages/sipb-xen-base/; revision=786 --- .../python-support/sipb-xen-base/invirt/common.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/files/usr/share/python-support/sipb-xen-base/invirt/common.py b/files/usr/share/python-support/sipb-xen-base/invirt/common.py index ca90714..b193ecc 100644 --- a/files/usr/share/python-support/sipb-xen-base/invirt/common.py +++ b/files/usr/share/python-support/sipb-xen-base/invirt/common.py @@ -26,7 +26,15 @@ def dicts2struct(x): # def with_closing(rsrc): - "Utility to emulate Python 2.5's `with closing(rsrc)` context manager." + """ + Utility to emulate Python 2.5's `with closing(rsrc)` context manager. + + E.g., + @with_closing(file('/tmp/foo')) + def contents(f): + return f.read() + # now 'contents' is the contents of /tmp/foo + """ def wrapper(func): try: return func(rsrc) finally: rsrc.close() @@ -40,8 +48,8 @@ def with_lock_file(path): def input(): print 'locked' return raw_input() - # decorator is executed immediately - print input # prints the input text + # prints 'locked' + print input # prints what raw_input() returned """ def wrapper(func): @with_closing(file(path, 'w')) -- 1.7.9.5