Simplify with built-in functions where possible. e.g.

change [x for x in y if x] to filter(None, y)
change [f(x) for x in y] to map(f, x)
change [x for x in y] to list(y)

These changes reduce source code size and complexity and produce some minor performance gains

svn: r14104
This commit is contained in:
Gerald Britton 2010-01-21 18:42:53 +00:00
parent fdfb1b48b0
commit 1f2469b09f
38 changed files with 81 additions and 101 deletions

View File

@ -62,7 +62,7 @@ class HasPlace(Rule):
return False
# If no location data was given then we're done: match
if not [item for item in self.list[1:] if item]:
if not any(self.list[1:]):
return True
# Something was given, so checking for location until we match

View File

@ -28,8 +28,8 @@ class RotateHandler(logging.Handler):
Return the buffer with the records in the correct order.
"""
return [record for record in self._buffer[self._index:] + self._buffer[:self._index]
if record is not None]
return filter(None,
self._buffer[self._index:] + self._buffer[:self._index])
def get_formatted_log(self, remove_tail_duplicate=None):
"""

View File

@ -472,8 +472,7 @@ class ScratchPadSourceRef(ScratchPadGrampsTypeWrapper):
base = self._db.get_source_from_handle(self._obj.get_reference_handle())
self._title = base.get_title()
notelist = [ self._db.get_note_from_handle(hndl)
for hndl in self._obj.get_note_list() ]
notelist = map(self._db.get_note_from_handle, self._obj.get_note_list())
srctxtlist = [ note for note in notelist
if note.get_type() == gen.lib.NoteType.SOURCE_TEXT]

View File

@ -683,7 +683,7 @@ class SimpleAccess(object):
if obj:
handles = [ ref.ref for ref in obj.get_source_references() ]
return [ self.dbase.get_source_from_handle(h) for h in handles ]
return map(self.dbase.get_source_from_handle, handles)
else:
return []

View File

@ -100,7 +100,7 @@ class SimpleTable(object):
columns.append(col)
# end of unicode fix
self.__columns = list(copy.copy(columns))
self.__sort_vals = [[] for i in range(len(self.__columns))]
self.__sort_vals = [[]]*len(self.__columns)
def set_callback(self, which, callback):
"""

View File

@ -221,7 +221,7 @@ class UndoHistory(ManagedWindow.ManagedWindow):
self.model.append(row=[time_text,mod_text,fg,bg])
# Get the not-None portion of transaction list
translist = [item for item in self.undodb.translist if item]
translist = filter(None, self.undodb.translist)
for transaction in translist:
time_text = time.ctime(transaction.timestamp)
mod_text = transaction.get_description()

View File

@ -1103,7 +1103,7 @@ def get_referents(handle, db, primary_objects):
"""
# Use one pass through the reference map to grab all the references
object_list = [item for item in db.find_backlink_handles(handle)]
object_list = db.find_backlink_handles(handle)
# Then form the object-specific lists
the_lists = ()
@ -1267,8 +1267,8 @@ def relative_path(original, base):
target_list = (orig_name).split(os.sep)
# make sure '/home/person' and 'c:/home/person' both give
# list ['home', 'person']
base_list = [word for word in base_list if word]
target_list = [word for word in target_list if word]
base_list = filter(None, base_list)
target_list = filter(None, target_list)
i = -1
for i in range(min(len(base_list), len(target_list))):
if base_list[i] <> target_list[i]: break
@ -1419,8 +1419,8 @@ def get_participant_from_event(db, event_handle):
"""
participant = ""
ellipses = False
result_list = [i for i in db.find_backlink_handles(event_handle,
include_classes=['Person', 'Family'])]
result_list = list(db.find_backlink_handles(event_handle,
include_classes=['Person', 'Family']))
#obtain handles without duplicates
people = set([x[1] for x in result_list if x[0] == 'Person'])
families = set([x[1] for x in result_list if x[0] == 'Family'])

View File

@ -149,7 +149,7 @@ class TextBufDoc(BaseDoc, TextDoc):
tab_array = pango.TabArray(len(new_tabs)+1,True)
index = 0
for tab in [ pixels(x) for x in new_tabs ]:
for tab in map(pixels, new_tabs):
tab_array.set_tab(index, pango.TAB_LEFT, tab)
index += 1
tag.set_property("tabs", tab_array)

View File

@ -1601,7 +1601,7 @@ class DbWriteBase(object):
self.set_default_person_handle(None)
# loop through the family list
for family_handle in [ f for f in person.get_family_handle_list() if f ]:
for family_handle in filter(None, person.get_family_handle_list()):
family = self.get_family_from_handle(family_handle)

View File

@ -51,10 +51,7 @@ class AddressBase(object):
:param source: Object used to initialize the new object
:type source: AddressBase
"""
if source:
self.address_list = [Address(addr) for addr in source.address_list]
else:
self.address_list = []
self.address_list = map(Address, source.address_list) if source else []
def serialize(self):
"""
@ -66,7 +63,7 @@ class AddressBase(object):
"""
Convert a serialized tuple of data to an object.
"""
self.address_list = [Address().unserialize(item) for item in data]
self.address_list = map(Address().unserialize, data)
def add_address(self, address):
"""

View File

@ -67,7 +67,7 @@ class AttributeBase(object):
"""
Convert a serialized tuple of data to an object.
"""
self.attribute_list = [Attribute().unserialize(item) for item in data]
self.attribute_list = map(Attribute().unserialize, data)
def add_attribute(self, attribute):
"""

View File

@ -241,7 +241,7 @@ class Family(SourceBase, NoteBase, MediaBase, AttributeBase, LdsOrdBase,
:returns: Returns the list of child objects that may carry textual data.
:rtype: list
"""
add_list = [item for item in self.lds_ord_list if item]
add_list = filter(None, self.lds_ord_list)
return self.media_list + self.attribute_list + \
self.source_list + add_list

View File

@ -68,7 +68,7 @@ class LdsOrdBase(object):
"""
Convert a serialized tuple of data to an object
"""
self.lds_ord_list = [LdsOrd().unserialize(item) for item in data]
self.lds_ord_list = map(LdsOrd().unserialize, data)
def add_lds_ord(self, lds_ord):
"""

View File

@ -48,11 +48,7 @@ class MediaBase(object):
:param source: Object used to initialize the new object
:type source: MediaBase
"""
if source:
self.media_list = [ MediaRef(mref) for mref in source.media_list ]
else:
self.media_list = []
self.media_list = map(MediaRef, source.media_list) if source else []
def serialize(self):
"""
@ -64,7 +60,7 @@ class MediaBase(object):
"""
Convert a serialized tuple of data to an object.
"""
self.media_list = [MediaRef().unserialize(item) for item in data]
self.media_list = map(MediaRef().unserialize, data)
def add_media_reference(self, media_ref):
"""

View File

@ -44,11 +44,7 @@ class NoteBase(object):
:param source: Object used to initialize the new object
:type source: NoteBase
"""
if source:
self.note_list = [handle for handle in source.note_list]
else:
self.note_list = []
self.note_list = list(source.note_list) if source else []
def serialize(self):
"""
@ -60,7 +56,7 @@ class NoteBase(object):
"""
Convert a serialized tuple of data to an object.
"""
self.note_list = [handle for handle in data]
self.note_list = list(data)
def add_note(self, handle):
"""

View File

@ -309,7 +309,7 @@ class Person(SourceBase, NoteBase, AttributeBase, MediaBase,
:rtype: list
"""
check_list = self.lds_ord_list
add_list = [item for item in check_list if item]
add_list = filter(None, check_list)
return [self.primary_name] + self.media_list + \
self.alternate_names + self.address_list + \
self.attribute_list + self.urls + \

View File

@ -82,7 +82,7 @@ class Source(MediaBase, NoteBase, PrimaryObject):
self.marker.unserialize(marker)
NoteBase.unserialize(self, note_list)
MediaBase.unserialize(self, media_list)
self.reporef_list = [RepoRef().unserialize(rr) for rr in reporef_list]
self.reporef_list = map(RepoRef().unserialize, reporef_list)
def _has_handle_reference(self, classname, handle):
"""

View File

@ -48,10 +48,8 @@ class SourceBase(object):
:param source: Object used to initialize the new object
:type source: SourceBase
"""
if source:
self.source_list = [SourceRef(sref) for sref in source.source_list]
else:
self.source_list = []
self.source_list = map(SourceRef, source.source_list) if source else []
def serialize(self):
"""
@ -63,7 +61,7 @@ class SourceBase(object):
"""
Convert a serialized tuple of data to an object.
"""
self.source_list = [SourceRef().unserialize(item) for item in data]
self.source_list = map(SourceRef().unserialize, data)
def add_source_reference(self, src_ref) :
"""

View File

@ -51,11 +51,7 @@ class UrlBase(object):
:param source: Object used to initialize the new object
:type source: UrlBase
"""
if source:
self.urls = [ Url(url) for url in source.urls ]
else:
self.urls = []
self.urls = map(Url, source.urls) if source else []
def serialize(self):
"""
@ -67,7 +63,7 @@ class UrlBase(object):
"""
Convert a serialized tuple of data to an object.
"""
self.urls = [Url().unserialize(item) for item in data]
self.urls = map(Url().unserialize, data)
def get_url_list(self):
"""

View File

@ -377,7 +377,7 @@ class PrivateProxyDb(ProxyDbBase):
Note that this is a generator function, it returns a iterator for
use in loops. If you want a list of the results use:
> result_list = [i for i in find_backlink_handles(handle)]
> result_list = list(find_backlink_handles(handle))
"""
# This isn't done yet because it doesn't check if references are

View File

@ -250,7 +250,7 @@ class ChildEmbedList(EmbeddedList):
self.call_edit_childref(ref.ref)
def run(self, skip):
skip_list = [ x for x in skip if x]
skip_list = filter(None, skip)
SelectPerson(self.dbstate, self.uistate, self.track,
_("Select Child"), skip=skip_list)
@ -655,7 +655,7 @@ class EditFamily(EditPrimary):
self.phandles = [mhandle, fhandle] + \
[ x.ref for x in self.obj.get_child_ref_list()]
self.phandles = [handle for handle in self.phandles if handle]
self.phandles = filter(None, self.phandles)
def _create_tabbed_pages(self):

View File

@ -114,8 +114,7 @@ class GuiPluginManager(gen.utils.Callback):
Note that config will then emit a signal
"""
self.__hidden_plugins.add(id)
hideset = [x for x in self.__hidden_plugins]
config.set('plugin.hiddenplugins', hideset)
config.set('plugin.hiddenplugins', list(self.__hidden_plugins))
config.save()
self.__hidden_changed()
@ -124,8 +123,7 @@ class GuiPluginManager(gen.utils.Callback):
return it again, and write this change to the config
"""
self.__hidden_plugins.remove(id)
hideset = [x for x in self.__hidden_plugins]
config.set('plugin.hiddenplugins', hideset)
config.set('plugin.hiddenplugins', list(self.__hidden_plugins))
config.save()
self.__hidden_changed()

View File

@ -129,7 +129,7 @@ class FamilyModel(FlatBaseModel):
return unicode(gen.lib.FamilyRelType(data[5]))
def column_marriage(self, data):
erlist = [ gen.lib.EventRef().unserialize(d) for d in data[6] ]
erlist = map(gen.lib.EventRef().unserialize, data[6])
erlist = [x for x in erlist if x.get_role()==EventRoleType.FAMILY or
x.get_role()==EventRoleType.PRIMARY]
event = self.db.marriage_from_eventref_list(erlist)
@ -139,7 +139,7 @@ class FamilyModel(FlatBaseModel):
return u''
def sort_marriage(self, data):
erlist = [ gen.lib.EventRef().unserialize(d) for d in data[6] ]
erlist = map(gen.lib.EventRef().unserialize, data[6])
event = self.db.marriage_from_eventref_list(erlist)
if event:
return "%09d" % event.date.get_sort_value()

View File

@ -873,7 +873,7 @@ class GedcomWriter(UpdateCallback):
event to discover the event type.
"""
for event_ref in [ ref for ref in family.get_event_ref_list()]:
for event_ref in family.get_event_ref_list():
event = self.dbase.get_event_from_handle(event_ref.ref)
etype = int(event.get_type())
val = libgedcom.familyConstantEvents.get(etype)

View File

@ -83,9 +83,9 @@ class AgeStatsGramplet(Gramplet):
age_dict = {}
mother_dict = {}
father_dict = {}
age_handles = [[] for age in range(self.max_age)]
mother_handles = [[] for age in range(self.max_mother_diff)]
father_handles = [[] for age in range(self.max_father_diff)]
age_handles = [[]] * self.max_age
mother_handles = [[]] * self.max_mother_diff
father_handles = [[]] * self.max_father_diff
text = ""
count = 0
for p in self.dbstate.db.iter_people():

View File

@ -143,7 +143,7 @@ class FanChartWidget(gtk.Widget):
self.data = {}
for i in range(self.generations):
# name, person, parents?, children?
self.data[i] = [(None, None, None, None) for j in range(2 ** i)]
self.data[i] = [(None,) * 4] * 2 ** i
self.angle[i] = []
angle = 0
slice = 360.0 / (2 ** i)

View File

@ -747,7 +747,7 @@ class GrampsBSDDB(DbGrdb, UpdateCallback):
Note that this is a generator function, it returns a iterator for
use in loops. If you want a list of the results use:
> result_list = [i for i in find_backlink_handles(handle)]
> result_list = list(find_backlink_handles(handle))
"""
# Use the secondary index to locate all the reference_map entries

View File

@ -814,7 +814,7 @@ class ProgenParser(object):
per_klad = recflds[per_klad_ix]
per_info = recflds[per_info_ix]
note_txt = [x for x in [per_info, per_klad] if x]
note_txt = filter(None, [per_info, per_klad])
if note_txt:
note = gen.lib.Note()
note.set('\n'.join(note_txt))
@ -860,7 +860,7 @@ class ProgenParser(object):
source_text = recflds[birth_source_text_ix]
info = recflds[birth_info_ix]
if date or place or info or srcref:
desc = [x for x in [info, time, source_text] if x]
desc = filter(None, [info, time, source_text])
desc = desc and '; '.join(desc) or None
event, birth_ref = self.__create_event_and_ref(gen.lib.EventType.BIRTH, desc, date, place, srcref)
person.set_birth_ref(birth_ref)
@ -883,7 +883,7 @@ class ProgenParser(object):
source_text = recflds[bapt_source_text_ix]
info = recflds[bapt_info_ix]
if date or place or info or srcref or reli or witness:
desc = [x for x in [reli, info, source_text] if x]
desc = filter(None, [reli, info, source_text])
desc = desc and '; '.join(desc) or None
event, bapt_ref = self.__create_event_and_ref(gen.lib.EventType.BAPTISM, desc, date, place, srcref)
person.add_event_ref(bapt_ref)
@ -919,7 +919,7 @@ class ProgenParser(object):
source_text = recflds[death_source_text_ix]
info = recflds[death_info_ix]
if date or place or info or srcref:
desc = [x for x in [info, time, source_text] if x]
desc = filter(None, [info, time, source_text])
desc = desc and '; '.join(desc) or None
event, death_ref = self.__create_event_and_ref(gen.lib.EventType.DEATH, desc, date, place, srcref)
person.set_death_ref(death_ref)
@ -940,7 +940,7 @@ class ProgenParser(object):
source_text = recflds[bur_source_text_ix]
info = recflds[bur_info_ix]
if date or place or info or srcref:
desc = [x for x in [info, source_text] if x]
desc = filter(None, [info, source_text])
desc = desc and '; '.join(desc) or None
event, burial_ref = self.__create_event_and_ref(gen.lib.EventType.BURIAL, desc, date, place, srcref)
person.add_event_ref(burial_ref)
@ -962,7 +962,7 @@ class ProgenParser(object):
info = recflds[crem_info_ix]
if date or place or info or srcref:
# TODO. Check that not both burial and cremation took place.
desc = [x for x in [info, source_text] if x]
desc = filter(None, [info, source_text])
desc = desc and '; '.join(desc) or None
event, cremation_ref = self.__create_event_and_ref(gen.lib.EventType.CREMATION, desc, date, place, srcref)
person.add_event_ref(cremation_ref)
@ -1074,7 +1074,7 @@ class ProgenParser(object):
rel_klad = recflds[rel_klad_ix]
rel_info = recflds[rel_info_ix]
note_txt = [x for x in [rel_info, rel_klad] if x]
note_txt = filter(None, [rel_info, rel_klad])
if note_txt:
note = gen.lib.Note()
note.set('\n'.join(note_txt))
@ -1095,7 +1095,7 @@ class ProgenParser(object):
source_text = recflds[mar_source_text_ix]
info = recflds[mar_info_ix]
if date or place or info or srcref:
desc = [x for x in [info, source_text] if x]
desc = filter(None, [info, source_text])
desc = desc and '; '.join(desc) or None
event, mar_ref = self.__create_event_and_ref(gen.lib.EventType.MARRIAGE, desc, date, place, srcref)
fam.add_event_ref(mar_ref)
@ -1127,7 +1127,7 @@ class ProgenParser(object):
source_text = recflds[marc_source_text_ix]
info = recflds[marc_info_ix]
if date or place or info or srcref:
desc = [x for x in [reli, info, source_text] if x]
desc = filter(None, [reli, info, source_text])
desc.insert(0, 'Kerkelijk huwelijk')
desc = desc and '; '.join(desc) or None
event, marc_ref = self.__create_event_and_ref(gen.lib.EventType.MARRIAGE, desc, date, place, srcref)
@ -1159,7 +1159,7 @@ class ProgenParser(object):
source_text = recflds[marl_source_text_ix]
info = recflds[marl_info_ix]
if date or place or info or srcref:
desc = [x for x in [info, source_text] if x]
desc = filter(None, [info, source_text])
desc.insert(0, 'Ondertrouw')
desc = desc and '; '.join(desc) or None
event, marl_ref = self.__create_event_and_ref(gen.lib.EventType.MARR_LIC, desc, date, place, srcref)
@ -1187,7 +1187,7 @@ class ProgenParser(object):
source_text = recflds[civu_source_text_ix]
info = recflds[civu_info_ix]
if date or place or info or srcref:
desc = [x for x in [info, source_text] if x]
desc = filter(None, [info, source_text])
desc.insert(0, 'Samenwonen')
desc = desc and '; '.join(desc) or None
event, civu_ref = self.__create_event_and_ref(gen.lib.EventType.UNKNOWN, desc, date, place, srcref)
@ -1211,7 +1211,7 @@ class ProgenParser(object):
source_text = recflds[div_source_text_ix]
info = recflds[div_info_ix]
if date or place or info or srcref:
desc = [x for x in [info, source_text] if x]
desc = filter(None, [info, source_text])
desc = desc and '; '.join(desc) or None
event, div_ref = self.__create_event_and_ref(gen.lib.EventType.DIVORCE, desc, date, place, srcref)
fam.add_event_ref(div_ref)

View File

@ -1248,7 +1248,7 @@ class DbGrdb(Callback):
"""
Return the defined names that have been assigned to a default grouping.
"""
return [unicode(k) for k in self.name_group.keys()]
return map(unicode, self.name_group.keys())
def has_name_group_key(self, name):
"""
@ -2504,7 +2504,7 @@ class DbGrdb(Callback):
Note that this is a generator function, it returns a iterator for
use in loops. If you want a list of the results use:
> result_list = [i for i in find_backlink_handles(handle)]
> result_list = list(find_backlink_handles(handle))
"""
# Make a dictionary of the functions and classes that we need for

View File

@ -219,7 +219,7 @@ class ChangeNames(Tool.BatchTool, ManagedWindow.ManagedWindow):
self.show()
def toggled(self,cell,path_string):
path = tuple([int (i) for i in path_string.split(':')])
path = tuple(map(int, path_string.split(':')))
row = self.model[path]
row[0] = not row[0]

View File

@ -578,7 +578,7 @@ class ExtractCity(Tool.BatchTool, ManagedWindow.ManagedWindow):
return
def toggled(self, cell, path_string):
path = tuple([int (i) for i in path_string.split(':')])
path = tuple(map(int, path_string.split(':')))
row = self.model[path]
row[0] = not row[0]

View File

@ -190,7 +190,7 @@ class PatchNames(Tool.BatchTool, ManagedWindow.ManagedWindow):
return (self.label, None)
def toggled(self, cell, path_string):
path = tuple([int (i) for i in path_string.split(':')])
path = tuple(map(int, path_string.split(':')))
row = self.model[path]
row[0] = not row[0]
self.model.row_changed(path, row.iter)

View File

@ -309,7 +309,7 @@ class RemoveUnused(Tool.Tool, ManagedWindow.ManagedWindow, UpdateCallback):
self.db.request_rebuild()
def selection_toggled(self, cell, path_string):
sort_path = tuple([int (i) for i in path_string.split(':')])
sort_path = tuple(map(int, path_string.split(':')))
real_path = self.sort_model.convert_path_to_child_path(sort_path)
row = self.real_model[real_path]
row[RemoveUnused.MARK_COL] = not row[RemoveUnused.MARK_COL]

View File

@ -254,7 +254,7 @@ class Verify(Tool.Tool, ManagedWindow, UpdateCallback):
self.top.connect_signals({
"destroy_passed_object" : self.close,
"on_help_clicked" : self.on_help_clicked,
"on_verify_ok_clicked" : self.on_apply_clicked
"on_verify_ok_clicked" : self.on_apply_clicked,
"on_delete_event" : self.close,
})
@ -562,7 +562,7 @@ class VerifyResults(ManagedWindow):
button.set_label(_("_Hide marked"))
def selection_toggled(self,cell,path_string):
sort_path = tuple([int (i) for i in path_string.split(':')])
sort_path = tuple(map(int, path_string.split(':')))
filt_path = self.sort_model.convert_path_to_child_path(sort_path)
real_path = self.filt_model.convert_path_to_child_path(filt_path)
row = self.real_model[real_path]

View File

@ -158,7 +158,7 @@ class FanChartWidget(gtk.Widget):
self.data = {}
for i in range(self.generations):
# name, person, parents?, children?
self.data[i] = [(None, None, None, None) for j in range(2 ** i)]
self.data[i] = [(None,) * 4] * 2 ** i
self.angle[i] = []
angle = 0
slice = 360.0 / (2 ** i)

View File

@ -171,7 +171,7 @@ class DjangoInterface(object):
else:
return gen.lib.Name().serialize()
else:
return [self.pack_name(name) for name in names]
return map(self.pack_name, names)
def get_datamap(self, obj): # obj is source
datamap_dict = {}
@ -202,10 +202,10 @@ class DjangoInterface(object):
obj_type = ContentType.objects.get_for_model(obj)
reporefs = models.RepositoryRef.objects.filter(object_id=obj.id,
object_type=obj_type)
return [self.pack_repository_ref(repo) for repo in reporefs]
return map(self.pack_repository_ref, reporefs)
def get_url_list(self, obj):
return [self.pack_url(url) for url in obj.url_set.all().order_by("order")]
return map(self.pack_url, obj.url_set.all().order_by("order"))
def get_address_list(self, obj, with_parish): # person or repository
addresses = obj.address_set.all().order_by("order")
@ -257,12 +257,12 @@ class DjangoInterface(object):
def get_person_ref_list(self, person):
obj_type = ContentType.objects.get_for_model(person)
return [self.pack_person_ref(x) for x in
return map(self.pack_person_ref,
models.PersonRef.objects.filter(object_id=person.id,
object_type=obj_type)]
object_type=obj_type))
def get_lds_list(self, obj): # person or family
return [self.pack_lds(lds) for lds in obj.lds_set.all().order_by("order")]
return map(self.pack_lds, obj.lds_set.all().order_by("order"))
def get_place_handle(self, obj): # obj is event
if obj.place:

View File

@ -162,7 +162,7 @@ class Table(object):
self.table.columns(*args)
def row(self, *args):
self.table.row(*[nbsp(arg) for arg in args])
self.table.row(*map(nbsp, args))
def link(self, object_type_name, handle):
self.table.set_link_col((object_type_name, handle))

View File

@ -33,7 +33,7 @@ class ReferenceMapTest (GrampsDbBaseTest):
source = self._add_source()
person = self._add_person_with_sources([source])
references = [ ref for ref in self._db.find_backlink_handles(source.get_handle()) ]
references = list(self._db.find_backlink_handles(source.get_handle()))
assert len(references) == 1
assert references[0] == (gen.lib.Person.__name__,person.get_handle())
@ -44,7 +44,7 @@ class ReferenceMapTest (GrampsDbBaseTest):
repos = self._add_repository()
source = self._add_source(repos=repos)
references = [ ref for ref in self._db.find_backlink_handles(repos.get_handle()) ]
references = list(self._db.find_backlink_handles(repos.get_handle()))
assert len(references) == 1
assert references[0] == (gen.lib.Source.__name__,source.get_handle())
@ -61,7 +61,7 @@ class ReferenceMapTest (GrampsDbBaseTest):
self._add_media_object_with_sources([source])
# make sure that we have the correct number of references (one for each object)
references = [ ref for ref in self._db.find_backlink_handles(source.get_handle()) ]
references = list(self._db.find_backlink_handles(source.get_handle()))
assert len(references) == 5, "len(references) == %s " % str(len(references))
@ -71,8 +71,8 @@ class ReferenceMapTest (GrampsDbBaseTest):
assert references[0][0] == gen.lib.Person.__name__, "references = %s" % repr(references)
# should just return the person and event reference
references = [ ref for ref in self._db.find_backlink_handles(source.get_handle(),(gen.lib.Person.__name__,
gen.lib.Event.__name__)) ]
references = list(self._db.find_backlink_handles(source.get_handle(),
(gen.lib.Person.__name__, gen.lib.Event.__name__)))
assert len(references) == 2, "len(references) == %s " % str(len(references))
assert references[0][0] == gen.lib.Person.__name__, "references = %s" % repr(references)
assert references[1][0] == gen.lib.Event.__name__, "references = %s" % repr(references)
@ -94,7 +94,7 @@ class ReferenceMapTest (GrampsDbBaseTest):
assert self._db.get_person_from_handle(person.get_handle()) is None
references = [ ref for ref in self._db.find_backlink_handles(source.get_handle()) ]
references = list(self._db.find_backlink_handles(source.get_handle()))
assert len(references) == 0, "len(references) == %s " % str(len(references))
@ -115,7 +115,7 @@ class ReferenceMapTest (GrampsDbBaseTest):
person = self._add_person_with_sources([source])
# Check that the reference map does not contain the reference.
references = [ ref for ref in self._db.find_backlink_handles(source.get_handle()) ]
references = list(self._db.find_backlink_handles(source.get_handle()))
assert len(references) == 0, "len(references) == %s " % str(len(references))
@ -124,7 +124,7 @@ class ReferenceMapTest (GrampsDbBaseTest):
self._db.reindex_reference_map(cb)
# Check that the reference now appears in the reference_map
references = [ ref for ref in self._db.find_backlink_handles(source.get_handle()) ]
references = list(self._db.find_backlink_handles(source.get_handle()))
assert len(references) == 1, "len(references) == %s " % str(len(references))
@ -155,7 +155,7 @@ class ReferenceMapTest (GrampsDbBaseTest):
cur.close()
start = time.time()
references = [ ref for ref in self._db.find_backlink_handles(handle) ]
references = list(self._db.find_backlink_handles(handle))
end = time.time()
with_reference_map = end - start
@ -165,7 +165,7 @@ class ReferenceMapTest (GrampsDbBaseTest):
self._db.__class__.find_backlink_handles = self._db.__class__.__base__.find_backlink_handles
start = time.time()
references = [ ref for ref in self._db.find_backlink_handles(handle) ]
references = list(self._db.find_backlink_handles(handle))
end = time.time()
without_reference_map = end - start