fix Image.cleanup to not do AttributeErrors
authorTero Marttila <terom@fixme.fi>
Mon, 15 Jun 2009 02:58:30 +0300
changeset 128 f66bb9f6126a
parent 127 37d19805b7ca
child 129 a4698fa2066c
fix Image.cleanup to not do AttributeErrors
degal/image.py
degal/utils.py
--- a/degal/image.py	Mon Jun 15 01:42:45 2009 +0300
+++ b/degal/image.py	Mon Jun 15 02:58:30 2009 +0300
@@ -2,7 +2,7 @@
     Per-image gallery state
 """
 
-import filesystem, format, thumbnail, exif
+import filesystem, format, thumbnail, exif, utils
 from utils import lazy_load
 
 import PIL.Image
@@ -127,8 +127,6 @@
         """
             Drop some memory-intensive cached values
         """
+        
+        utils.unload(self, 'img', 'exif', 'metadata')
 
-        del self.img
-        del self.exif
-        del self.metadata
-
--- a/degal/utils.py	Mon Jun 15 01:42:45 2009 +0300
+++ b/degal/utils.py	Mon Jun 15 02:58:30 2009 +0300
@@ -77,6 +77,15 @@
 lazy_load = LazyProperty
 lazy_load_iter = LazyIteratorProperty
 
+def unload (obj, *attrs) :
+    """
+        Un-load the named attributes from the given object.
+    """
+    
+    for attr in attrs :
+        if attr in obj.__dict__ :
+            del obj.__dict__[attr]
+
 def first (iterable) :
     """
         Returns the first item from the iterable that evaluates to True, otherwise None.
@@ -86,7 +95,6 @@
         >>> first("abc")
         'a'
         >>> first(('', list(), (), False))
-        None
     """
 
     for item in iterable :