[kupfer] objects: Return a self-deleting token from FilesystemWatchMixin



commit 9e238ab3196a4d8f43020eebaee3a0acca70bdd8
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date:   Tue Sep 8 17:51:27 2009 +0200

    objects: Return a self-deleting token from FilesystemWatchMixin
    
    FilesystemWatchMixin now returns a monitoring token that will delete
    itself on pickling, since the actual monitor object is not pickleable.

 kupfer/objects.py |   14 ++++++++++++--
 1 files changed, 12 insertions(+), 2 deletions(-)
---
diff --git a/kupfer/objects.py b/kupfer/objects.py
index 9167185..8c7b92f 100644
--- a/kupfer/objects.py
+++ b/kupfer/objects.py
@@ -854,6 +854,15 @@ class Source (KupferObject, pretty.OutputMixin):
 		"""
 		return ()
 
+class _nonpersistent_token (PicklingHelperMixin):
+	"""A token will keep a reference until pickling, when it is deleted"""
+	def __init__(self, data):
+		self.data = data
+	def __nonzero__(self):
+		return self.data
+	def pickle_prepare(self):
+		self.data = None
+
 class FilesystemWatchMixin (object):
 	"""A mixin for Sources watching directories"""
 
@@ -862,7 +871,8 @@ class FilesystemWatchMixin (object):
 
 		On changes, the Source will be marked for update.
 		This method returns a monitor token that has to be
-		stored for the monitor to be active; and it can not be pickled.
+		stored for the monitor to be active.
+
 		The token will be a false value if nothing could be monitored.
 
 		Nonexisting directories are skipped.
@@ -876,7 +886,7 @@ class FilesystemWatchMixin (object):
 			if monitor:
 				monitor.connect("changed", self.__directory_changed)
 				tokens.append(monitor)
-		return tokens
+		return _nonpersistent_token(tokens)
 
 	def monitor_include_file(self, gfile):
 		"""Return whether @gfile should trigger an update event



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]