Make the smart device cache return instances of USBMS.Book instead of Book.Metadata.

This commit is contained in:
Charles Haley 2013-11-24 09:33:18 +01:00
parent 984c29c1e2
commit f97ae35cc5
2 changed files with 7 additions and 4 deletions

View File

@ -688,7 +688,7 @@ class SMART_DEVICE_APP(DeviceConfig, DevicePlugin):
lastmod = parse_date(lastmod)
if key in self.known_uuids and self.known_uuids[key]['book'].last_modified == lastmod:
self.known_uuids[key]['last_used'] = now()
return self.known_uuids[key]['book'].deepcopy()
return self.known_uuids[key]['book'].deepcopy(lambda : SDBook('', ''))
except:
traceback.print_exc()
return None

View File

@ -184,11 +184,14 @@ class Metadata(object):
def has_key(self, key):
return key in object.__getattribute__(self, '_data')
def deepcopy(self):
def deepcopy(self, class_generator=lambda : Metadata(None)):
''' Do not use this method unless you know what you are doing, if you
want to create a simple clone of this object, use :meth:`deepcopy_metadata`
instead. '''
m = Metadata(None)
instead. Class_generator must be a function that returns an instance
of Metadata or a subclass of it.'''
m = class_generator()
if not isinstance(m, Metadata):
return None
object.__setattr__(m, '__dict__', copy.deepcopy(self.__dict__))
return m