# HG changeset patch # User Tero Marttila # Date 1245023910 -10800 # Node ID f66bb9f6126a8b17b1905921f846087c0e6701f0 # Parent 37d19805b7ca694459bef335023a2de5a741856a fix Image.cleanup to not do AttributeErrors diff -r 37d19805b7ca -r f66bb9f6126a degal/image.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 - diff -r 37d19805b7ca -r f66bb9f6126a degal/utils.py --- 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 :