Author: dmeyer
Date: Wed Mar 19 11:59:39 2008
New Revision: 3203

Log:
rename class InProgressExecution to def execute (similar to twisted)

Modified:
   trunk/base/src/notifier/__init__.py
   trunk/base/src/notifier/async.py
   trunk/beacon/src/db.py
   trunk/popcorn/src/generic.py

Modified: trunk/base/src/notifier/__init__.py
==============================================================================
--- trunk/base/src/notifier/__init__.py (original)
+++ trunk/base/src/notifier/__init__.py Wed Mar 19 11:59:39 2008
@@ -40,7 +40,7 @@
 
 # InProgress class
 from async import TimeoutException, InProgress, InProgressCallback, 
InProgressSignals, \
-     InProgressExecution
+     execute
 
 # Thread callbacks, helper functions and decorators
 from thread import MainThreadCallback, NamedThreadCallback, ThreadCallback, \

Modified: trunk/base/src/notifier/async.py
==============================================================================
--- trunk/base/src/notifier/async.py    (original)
+++ trunk/base/src/notifier/async.py    Wed Mar 19 11:59:39 2008
@@ -29,9 +29,8 @@
 #
 # -----------------------------------------------------------------------------
 
-__all__ = [ 'TimeoutException', 'InProgress', 'InProgressCallback',
-            'InProgressSignals', 'InProgressExecution', 'AsyncException',
-            'AsyncExceptionBase', 'make_exception_class' ]
+__all__ = [ 'TimeoutException', 'InProgress', 'InProgressCallback', 
'InProgressSignals',
+            'execute', 'AsyncException', 'AsyncExceptionBase', 
'make_exception_class' ]
 
 # python imports
 import sys
@@ -458,22 +457,19 @@
         return self.finish(None)
 
 
-class InProgressExecution(InProgress):
+def execute(func, *args, **kwargs):
     """
-    This class can be used to wrap a function to call to an InProgress object.
-    The result or exception will be stored inside the InProgressExecution
-    object. This is usefull when an InProgress object is expected but the 
function
-    to be called does not provide this.
-    """
-    def __init__(self, func, *args, **kwargs):
-        super(InProgressExecution, self).__init__()
-        try:
-            result = func(*args, **kwargs)
-        except:
-            self.throw(*sys.exc_info())
-        else:
-            self.finish(result)
-
+    Execute the given function and return the result or exception in an
+    InProgress object.
+    """
+    async = InProgress()
+    try:
+        result = func(*args, **kwargs)
+    except:
+        async.throw(*sys.exc_info())
+    else:
+        async.finish(result)
+    return async
 
     
 class InProgressSignals(InProgress):

Modified: trunk/beacon/src/db.py
==============================================================================
--- trunk/beacon/src/db.py      (original)
+++ trunk/beacon/src/db.py      Wed Mar 19 11:59:39 2008
@@ -173,9 +173,9 @@
         # do query based on type
         if 'filename' in query and qlen == 1:
             fname = os.path.realpath(query['filename'])
-            return kaa.InProgressExecution(self.query_filename, fname)
+            return kaa.execute(self.query_filename, fname)
         if 'id' in query and qlen == 1:
-            return kaa.InProgressExecution(self._db_query_id, query['id'])
+            return kaa.execute(self._db_query_id, query['id'])
         if 'parent' in query and 'recursive' in query and qlen == 2:
             if not query['parent']._beacon_isdir:
                 raise AttributeError('parent is no directory')
@@ -186,9 +186,9 @@
                     return self._db_query_dir(query['parent'])
             query['parent'] = query['parent']._beacon_id
         if 'attr' in query:
-            return kaa.InProgressExecution(self._db_query_attr, query)
+            return kaa.execute(self._db_query_attr, query)
         if 'type' in query and query['type'] == 'media':
-            return kaa.InProgressExecution(self._db.query, **query)
+            return kaa.execute(self._db.query, **query)
         return self._db_query_raw(query)
 
 

Modified: trunk/popcorn/src/generic.py
==============================================================================
--- trunk/popcorn/src/generic.py        (original)
+++ trunk/popcorn/src/generic.py        Wed Mar 19 11:59:39 2008
@@ -62,7 +62,7 @@
             # always return an InProgress object
             if self._get_state() in states and not self._pending:
                 # already finished
-                return kaa.InProgressExecution(func, self, *args, **kwargs)
+                return kaa.execute(func, self, *args, **kwargs)
             # add callback to list of pending calls
             async = kaa.InProgress()
             callback = kaa.Callback(func, self, *args, **kwargs)

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog

Reply via email to