Author: dmeyer
Date: Thu Feb 14 07:39:59 2008
New Revision: 3099

Log:
Move coroutine.YieldCallback to async.InProgressCallback

Modified:
   trunk/base/API_CHANGES.txt
   trunk/base/src/net/tls.py
   trunk/base/src/notifier/__init__.py
   trunk/base/src/notifier/async.py
   trunk/base/src/notifier/coroutine.py
   trunk/base/src/notifier/sockets.py
   trunk/base/test/asynctest.py

Modified: trunk/base/API_CHANGES.txt
==============================================================================
--- trunk/base/API_CHANGES.txt  (original)
+++ trunk/base/API_CHANGES.txt  Thu Feb 14 07:39:59 2008
@@ -70,5 +70,6 @@
    and WeakIOMonitor.
 
 4. Rename YieldContinue to NotFinished
+   Rename YieldCallback to InProgressCallback
    Remove YieldFunction from the API, the class is now only for
    internal use and may change without further notice.

Modified: trunk/base/src/net/tls.py
==============================================================================
--- trunk/base/src/net/tls.py   (original)
+++ trunk/base/src/net/tls.py   Thu Feb 14 07:39:59 2008
@@ -55,7 +55,7 @@
         try:
             while True:
                 n = handshake.next()
-                cb = kaa.YieldCallback()
+                cb = kaa.InProgressCallback()
                 disp = kaa.notifier.IOMonitor(cb)
                 if n == 0:
                     disp.register(self.sock.fileno(), kaa.notifier.IO_READ)

Modified: trunk/base/src/notifier/__init__.py
==============================================================================
--- trunk/base/src/notifier/__init__.py (original)
+++ trunk/base/src/notifier/__init__.py Thu Feb 14 07:39:59 2008
@@ -39,7 +39,7 @@
 from signals import Signal, Signals
 
 # InProgress class
-from async import InProgress
+from async import TimeoutException, InProgress, InProgressCallback
 
 # Thread callbacks, helper functions and decorators
 from thread import MainThreadCallback, NamedThreadCallback, ThreadCallback, \
@@ -56,7 +56,7 @@
 from event import Event, EventHandler, WeakEventHandler
 
 # coroutine decorator and helper classes
-from coroutine import NotFinished, YieldCallback, coroutine
+from coroutine import NotFinished, coroutine
 
 # process management
 from popen import Process

Modified: trunk/base/src/notifier/async.py
==============================================================================
--- trunk/base/src/notifier/async.py    (original)
+++ trunk/base/src/notifier/async.py    Thu Feb 14 07:39:59 2008
@@ -29,7 +29,7 @@
 #
 # -----------------------------------------------------------------------------
 
-__all__ = [ 'InProgress' ]
+__all__ = [ 'TimeoutException', 'InProgress', 'InProgressCallback' ]
 
 # python imports
 import sys
@@ -165,7 +165,7 @@
         """
         # This function must deal with a tricky problem.  See:
         # 
http://mail.python.org/pipermail/python-dev/2005-September/056091.html
-        # 
+        #
         # Ideally, we want to store the traceback object so we can defer the
         # exception handling until some later time.  The problem is that by
         # storing the traceback, we create some ridiculously deep circular
@@ -220,7 +220,7 @@
             cb = Callback(InProgress._log_exception, trace, value)
             self._unhandled_exception = _weakref.ref(self, cb)
 
-        # Remove traceback from stored exception.  If any waiting threads 
+        # Remove traceback from stored exception.  If any waiting threads
         # haven't gotten it by now, it's too late.
         self._exception = type, value, None
 
@@ -304,7 +304,7 @@
             # but we won't get notified of any thread completion
             # unless the thread notifier pipe is initialized.
             set_as_mainthread()
- 
+
         if is_mainthread():
             # We're waiting in the main thread, so we must keep the mainloop
             # alive by calling step() until we're finished.
@@ -351,3 +351,44 @@
         """
         self.connect(finished)
         self.exception.connect_once(exception)
+
+
+
+class InProgressCallback(InProgress):
+    """
+    InProgress object that can be used as a callback for an async
+    function. The InProgress object will be finished when it is
+    called. Special support for Signals that will finish the InProgress
+    object when the signal is emited.
+    """
+    def __init__(self, func=None):
+        InProgress.__init__(self)
+        if func is not None:
+            if isinstance(func, Signal):
+                func = func.connect_once
+            # connect self as callback
+            func(self)
+
+
+    def __call__(self, *args, **kwargs):
+        """
+        Call the InProgressCallback by the external function. This will
+        finish the InProgress object.
+        """
+        # try to get the results as the caller excepts them
+        if args and kwargs:
+            # no idea how to merge them
+            return self.finished((args, kwargs))
+        if kwargs and len(kwargs) == 1:
+            # return the value
+            return self.finished(kwargs.values()[0])
+        if kwargs:
+            # return as dict
+            return self.finished(kwargs)
+        if len(args) == 1:
+            # return value
+            return self.finished(args[0])
+        if len(args) > 1:
+            # return as list
+            return self.finished(args)
+        return self.finished(None)

Modified: trunk/base/src/notifier/coroutine.py
==============================================================================
--- trunk/base/src/notifier/coroutine.py        (original)
+++ trunk/base/src/notifier/coroutine.py        Thu Feb 14 07:39:59 2008
@@ -20,12 +20,8 @@
 # statement. In that case, the function call continues at this point in the
 # next notifier iteration. If the function itself has to wait for a result of
 # a function call (either another yield function are something else working
-# async), it can create a 'YieldCallback' object, add this as callback to the
-# function it is calling and return this object using yield. In this case, the
-# function will continue at this point when the other async call is finished.
-# The function can use the 'get' function of the 'YieldCallback' to get the
-# result of the async call. It is also possible to yield an InProgress object
-# and call it later to get the results (or the exception).
+# async with an InProgress object) and it can create a 'InProgressCallback'
+# object and use this as callback.
 #
 # The 'coroutine' decorator has a parameter interval. This is the
 # interval used to schedule when the function should continue after a yield.
@@ -56,7 +52,7 @@
 #
 # -----------------------------------------------------------------------------
 
-__all__ = [ 'NotFinished', 'YieldCallback', 'coroutine' ]
+__all__ = [ 'NotFinished', 'coroutine' ]
 
 # python imports
 import sys
@@ -70,45 +66,6 @@
 NotFinished = object()
 
 
-class YieldCallback(InProgress):
-    """
-    Callback class that can be used as a callback for a function that is
-    async. Return this object using 'yield' and use get_result() later.
-    You can also use result = yield YieldCallback object for Python 2.5.
-    """
-    def __init__(self, func=None):
-        InProgress.__init__(self)
-        if func is not None:
-            if isinstance(func, Signal):
-                func = func.connect_once
-            # connect self as callback
-            func(self)
-
-
-    def __call__(self, *args, **kwargs):
-        """
-        Call the YieldCallback by the external function. This will resume
-        the calling YieldFunction.
-        """
-        # try to get the results as the caller excepts them
-        if args and kwargs:
-            # no idea how to merge them
-            return self.finished((args, kwargs))
-        if kwargs and len(kwargs) == 1:
-            # return the value
-            return self.finished(kwargs.values()[0])
-        if kwargs:
-            # return as dict
-            return self.finished(kwargs)
-        if len(args) == 1:
-            # return value
-            return self.finished(args[0])
-        if len(args) > 1:
-            # return as list
-            return self.finished(args)
-        return self.finished(None)
-
-
 # variable to detect if send is possible with a generator
 _python25 = sys.version.split()[0] > '2.4'
 

Modified: trunk/base/src/notifier/sockets.py
==============================================================================
--- trunk/base/src/notifier/sockets.py  (original)
+++ trunk/base/src/notifier/sockets.py  Thu Feb 14 07:39:59 2008
@@ -39,8 +39,7 @@
 from callback import Callback, WeakCallback
 from signals import Signals, Signal
 from thread import MainThreadCallback, ThreadCallback, is_mainthread, threaded
-from async import InProgress
-from coroutine import YieldCallback
+from async import InProgress, InProgressCallback
 from kaa.utils import property
 from timer import OneShotTimer, timed, POLICY_ONCE
 
@@ -281,7 +280,7 @@
         if self._listening:
             raise RuntimeError("Can't read on a listening socket.")
 
-        return YieldCallback(signal)
+        return InProgressCallback(signal)
 
 
     def read(self):

Modified: trunk/base/test/asynctest.py
==============================================================================
--- trunk/base/test/asynctest.py        (original)
+++ trunk/base/test/asynctest.py        Thu Feb 14 07:39:59 2008
@@ -107,27 +107,27 @@
     # call some async function with different types of
     # results (given as parameter)
     
-    callback = kaa.YieldCallback()
+    callback = kaa.InProgressCallback()
     async(callback, 7, 8)
     yield callback
     print callback.get_result()                # (7, 8)
 
-    callback = kaa.YieldCallback()
+    callback = kaa.InProgressCallback()
     async(callback)
     yield callback
     print callback.get_result()                # None
 
-    callback = kaa.YieldCallback()
+    callback = kaa.InProgressCallback()
     async(callback, 9)
     yield callback
     print callback.get_result()                # 9
 
-    callback = kaa.YieldCallback()
+    callback = kaa.InProgressCallback()
     async(callback, foo=10)
     yield callback
     print callback.get_result()                # 10
 
-    callback = kaa.YieldCallback()
+    callback = kaa.InProgressCallback()
     async(callback, foo=11, bar=12)
     yield callback
     print callback.get_result()                # {'foo': 11, 'bar': 12}

-------------------------------------------------------------------------
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