Author: dmeyer
Date: Wed Mar 19 11:54:47 2008
New Revision: 3202
Log:
move execute from InProgress into new InProgressExecution class
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:54:47 2008
@@ -39,7 +39,8 @@
from signals import Signal, Signals
# InProgress class
-from async import TimeoutException, InProgress, InProgressCallback,
InProgressSignals
+from async import TimeoutException, InProgress, InProgressCallback,
InProgressSignals, \
+ InProgressExecution
# 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:54:47 2008
@@ -29,8 +29,9 @@
#
# -----------------------------------------------------------------------------
-__all__ = [ 'TimeoutException', 'InProgress', 'InProgressCallback',
'InProgressSignals',
- 'AsyncException', 'AsyncExceptionBase', 'make_exception_class' ]
+__all__ = [ 'TimeoutException', 'InProgress', 'InProgressCallback',
+ 'InProgressSignals', 'InProgressExecution', 'AsyncException',
+ 'AsyncExceptionBase', 'make_exception_class' ]
# python imports
import sys
@@ -312,21 +313,6 @@
log.error('Unhandled %s exception:\n%s', cls.__name__, trace)
- def execute(self, func, *args, **kwargs):
- """
- Execute the function and store the result or exception inside the
- InProgress object. Returns self to support yield in a coroutine.
- To yield a finished object call yield InProgress().execute(...)
- """
- try:
- result = func(*args, **kwargs)
- except:
- self.throw(*sys.exc_info())
- else:
- self.finish(result)
- return self
-
-
def is_finished(self):
"""
Return if the InProgress is finished.
@@ -472,6 +458,24 @@
return self.finish(None)
+class InProgressExecution(InProgress):
+ """
+ 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)
+
+
+
class InProgressSignals(InProgress):
"""
InProgress object that will be finished if one of the provided
Modified: trunk/beacon/src/db.py
==============================================================================
--- trunk/beacon/src/db.py (original)
+++ trunk/beacon/src/db.py Wed Mar 19 11:54:47 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.InProgress().execute(self.query_filename, fname)
+ return kaa.InProgressExecution(self.query_filename, fname)
if 'id' in query and qlen == 1:
- return kaa.InProgress().execute(self._db_query_id, query['id'])
+ return kaa.InProgressExecution(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.InProgress().execute(self._db_query_attr, query)
+ return kaa.InProgressExecution(self._db_query_attr, query)
if 'type' in query and query['type'] == 'media':
- return kaa.InProgress().execute(self._db.query, **query)
+ return kaa.InProgressExecution(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:54:47 2008
@@ -60,14 +60,13 @@
def newfunc(self, *args, **kwargs):
# always return an InProgress object
- async = kaa.InProgress()
if self._get_state() in states and not self._pending:
# already finished
- async.execute(func, self, *args, **kwargs)
- else:
- # add callback to list of pending calls
- callback = kaa.Callback(func, self, *args, **kwargs)
- self._pending.append((states, async, callback))
+ return kaa.InProgressExecution(func, self, *args, **kwargs)
+ # add callback to list of pending calls
+ async = kaa.InProgress()
+ callback = kaa.Callback(func, self, *args, **kwargs)
+ self._pending.append((states, async, callback))
return async
try:
newfunc.func_name = func.func_name
-------------------------------------------------------------------------
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