Bug 3018: remove calls to keys() dictionary method where possible

svn: r12562
This commit is contained in:
Gerald Britton 2009-05-22 18:43:40 +00:00
parent 5c9d8ab7ff
commit fc90d5fce2
16 changed files with 45 additions and 47 deletions

View File

@ -204,7 +204,7 @@ class StandardCustomSelector(object):
int_val = self.custom_key int_val = self.custom_key
str_val = self.selector.child.get_text().strip() str_val = self.selector.child.get_text().strip()
if str_val in self.mapping.values(): if str_val in self.mapping.values():
for key in self.mapping.keys(): for key in self.mapping:
if str_val == self.mapping[key]: if str_val == self.mapping[key]:
int_val = key int_val = key
break break
@ -220,7 +220,7 @@ class StandardCustomSelector(object):
@type val: tuple @type val: tuple
""" """
key, text = val key, text = val
if key in self.mapping.keys() and key != self.custom_key: if key in self.mapping and key != self.custom_key:
self.store.foreach(self.set_int_value, key) self.store.foreach(self.set_int_value, key)
elif self.custom_key is not None: elif self.custom_key is not None:
self.selector.child.set_text(text) self.selector.child.set_text(text)

View File

@ -1248,8 +1248,7 @@ class GrampletView(PageView.PersonNavView):
def save(self, *args): def save(self, *args):
if debug: print "saving" if debug: print "saving"
if len(self.frame_map.keys() + if len(self.frame_map) + len(self.detached_gramplets) == 0:
self.detached_gramplets) == 0:
return # something is the matter return # something is the matter
filename = GRAMPLET_FILENAME filename = GRAMPLET_FILENAME
try: try:
@ -1581,7 +1580,7 @@ class GrampletView(PageView.PersonNavView):
qr_menu = ag_menu.get_submenu() qr_menu = ag_menu.get_submenu()
qr_menu = gtk.Menu() qr_menu = gtk.Menu()
names = [AVAILABLE_GRAMPLETS[key]["tname"] for key names = [AVAILABLE_GRAMPLETS[key]["tname"] for key
in AVAILABLE_GRAMPLETS.keys()] in AVAILABLE_GRAMPLETS]
names.sort() names.sort()
for name in names: for name in names:
Utils.add_menuitem(qr_menu, name, Utils.add_menuitem(qr_menu, name,

View File

@ -59,7 +59,7 @@ class FilterList(object):
def add(self, namespace, filt): def add(self, namespace, filt):
assert(isinstance(namespace, basestring)) assert(isinstance(namespace, basestring))
if namespace not in self.filter_namespaces.keys(): if namespace not in self.filter_namespaces:
self.filter_namespaces[namespace] = [] self.filter_namespaces[namespace] = []
self.filter_namespaces[namespace].append(filt) self.filter_namespaces[namespace].append(filt)
@ -88,7 +88,7 @@ class FilterList(object):
f.write("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n") f.write("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n")
f.write('<filters>\n') f.write('<filters>\n')
for namespace in self.filter_namespaces.keys(): for namespace in self.filter_namespaces:
f.write('<object type="%s">\n' % namespace) f.write('<object type="%s">\n' % namespace)
filter_list = self.filter_namespaces[namespace] filter_list = self.filter_namespaces[namespace]
for the_filter in filter_list: for the_filter in filter_list:

View File

@ -82,7 +82,7 @@ class FilterParser(handler.ContentHandler):
self.gfilter_list.add(self.namespace, self.f) self.gfilter_list.add(self.namespace, self.f)
elif tag == "rule": elif tag == "rule":
save_name = attrs['class'] save_name = attrs['class']
if save_name in old_names_2_class.keys(): if save_name in old_names_2_class:
self.r = old_names_2_class[save_name] self.r = old_names_2_class[save_name]
else: else:
try: try:

View File

@ -393,7 +393,7 @@ class ListModel(object):
""" """
Selects the item associated with the pass information. Selects the item associated with the pass information.
""" """
if info in self.idmap.keys(): if info in self.idmap:
node = self.idmap[str(info)] node = self.idmap[str(info)]
self.selection.select_iter(node) self.selection.select_iter(node)

View File

@ -174,18 +174,18 @@ class CommandLineTool(object):
return return
# Add tool-specific options # Add tool-specific options
for key in self.option_class.handler.options_dict.keys(): for key in self.option_class.handler.options_dict:
if key not in self.options_dict.keys(): if key not in self.options_dict:
self.options_dict[key] = self.option_class.handler.options_dict[key] self.options_dict[key] = self.option_class.handler.options_dict[key]
# Add help for tool-specific options # Add help for tool-specific options
for key in self.option_class.options_help.keys(): for key in self.option_class.options_help:
if key not in self.options_help.keys(): if key not in self.options_help:
self.options_help[key] = self.option_class.options_help[key] self.options_help[key] = self.option_class.options_help[key]
def parse_option_str(self): def parse_option_str(self):
for opt in self.options_str_dict.keys(): for opt in self.options_str_dict:
if opt in self.options_dict.keys(): if opt in self.options_dict:
converter = Utils.get_type_converter(self.options_dict[opt]) converter = Utils.get_type_converter(self.options_dict[opt])
self.options_dict[opt] = converter(self.options_str_dict[opt]) self.options_dict[opt] = converter(self.options_str_dict[opt])
self.option_class.handler.options_dict[opt] = self.options_dict[opt] self.option_class.handler.options_dict[opt] = self.options_dict[opt]
@ -208,10 +208,10 @@ class CommandLineTool(object):
return return
elif self.show == 'all': elif self.show == 'all':
print " Available options:" print " Available options:"
for key in self.options_dict.keys(): for key in self.options_dict:
print " %s" % key print " %s" % key
print " Use 'show=option' to see description and acceptable values" print " Use 'show=option' to see description and acceptable values"
elif self.show in self.options_dict.keys(): elif self.show in self.options_dict:
print ' %s%s\t%s' % (self.show, print ' %s%s\t%s' % (self.show,
self.options_help[self.show][0], self.options_help[self.show][0],
self.options_help[self.show][1]) self.options_help[self.show][1])

View File

@ -796,7 +796,7 @@ class RelationshipCalculator(object):
self.dirtymap = False self.dirtymap = False
self.map_handle = orig_person.handle self.map_handle = orig_person.handle
for person_handle in secondMap.keys() : for person_handle in secondMap :
if person_handle in firstMap : if person_handle in firstMap :
com = [] com = []
#a common ancestor #a common ancestor
@ -957,7 +957,7 @@ class RelationshipCalculator(object):
self.REL_FATHER_NOTBIRTH, childrel[0][1]), self.REL_FATHER_NOTBIRTH, childrel[0][1]),
(mhandle, self.REL_MOTHER, (mhandle, self.REL_MOTHER,
self.REL_MOTHER_NOTBIRTH, childrel[0][0])]: self.REL_MOTHER_NOTBIRTH, childrel[0][0])]:
if data[0] and not data[0] in parentstodo.keys() : if data[0] and data[0] not in parentstodo :
persontodo = db.get_person_from_handle(data[0]) persontodo = db.get_person_from_handle(data[0])
if data[3] == gen.lib.ChildRefType.BIRTH : if data[3] == gen.lib.ChildRefType.BIRTH :
addstr = data[1] addstr = data[1]
@ -969,7 +969,7 @@ class RelationshipCalculator(object):
parentstodo[data[0]] = (persontodo, parentstodo[data[0]] = (persontodo,
rel_str + addstr, rel_str + addstr,
rel_fam_new) rel_fam_new)
elif data [0] and data[0] in parentstodo.keys(): elif data [0] and data[0] in parentstodo:
#this person is already scheduled to research #this person is already scheduled to research
#update family list #update family list
famlist = parentstodo[data[0]][2] famlist = parentstodo[data[0]][2]
@ -999,8 +999,7 @@ class RelationshipCalculator(object):
pmap[chandle] = [[rel_str+addstr],[rel_fam_new]] pmap[chandle] = [[rel_str+addstr],[rel_fam_new]]
fam += 1 fam += 1
for handle in parentstodo.keys(): for handle, data in parentstodo.iteritems():
data = parentstodo[handle]
self.__apply_filter(db, data[0], self.__apply_filter(db, data[0],
data[1], data[2], data[1], data[2],
pmap, depth, stoprecursemap) pmap, depth, stoprecursemap)

View File

@ -281,8 +281,8 @@ class CommandLineReport(object):
return return
menu = self.option_class.menu menu = self.option_class.menu
menu_opt_names = menu.get_all_option_names() menu_opt_names = menu.get_all_option_names()
for opt in self.options_str_dict.keys(): for opt in self.options_str_dict:
if opt in self.options_dict.keys(): if opt in self.options_dict:
converter = Utils.get_type_converter(self.options_dict[opt]) converter = Utils.get_type_converter(self.options_dict[opt])
self.options_dict[opt] = converter(self.options_str_dict[opt]) self.options_dict[opt] = converter(self.options_str_dict[opt])
self.option_class.handler.options_dict[opt] = \ self.option_class.handler.options_dict[opt] = \
@ -349,8 +349,8 @@ class CommandLineReport(object):
return return
elif self.show == 'all': elif self.show == 'all':
print " Available options:" print " Available options:"
for key in self.options_dict.keys(): for key in self.options_dict:
if key in self.options_dict.keys(): if key in self.options_dict:
# Make the output nicer to read, assume that tab has 8 spaces # Make the output nicer to read, assume that tab has 8 spaces
if len(key) < 10: if len(key) < 10:
print " %s\t\t%s (%s)" % (key, print " %s\t\t%s (%s)" % (key,
@ -363,7 +363,7 @@ class CommandLineReport(object):
else: else:
print " %s" % key print " %s" % key
print " Use 'show=option' to see description and acceptable values" print " Use 'show=option' to see description and acceptable values"
elif self.show in self.options_dict.keys(): elif self.show in self.options_dict:
print ' %s%s\t%s' % (self.show, print ' %s%s\t%s' % (self.show,
self.options_help[self.show][0], self.options_help[self.show][0],
self.options_help[self.show][1]) self.options_help[self.show][1])

View File

@ -141,7 +141,7 @@ class ScratchPadGrampsTypeWrapper(ScratchPadWrapper):
'Source': self._db.get_source_from_handle} 'Source': self._db.get_source_from_handle}
for (classname, handle) in self._obj.get_referenced_handles_recursively(): for (classname, handle) in self._obj.get_referenced_handles_recursively():
if classname in valid_func_map.keys(): if classname in valid_func_map:
if not valid_func_map[classname](handle): if not valid_func_map[classname](handle):
return False return False
@ -1100,7 +1100,7 @@ class ScratchPadListView(object):
# Find a wrapper class # Find a wrapper class
possible_wrappers = [target for target in context.targets \ possible_wrappers = [target for target in context.targets \
if target in self._target_type_to_wrapper_class_map.keys()] if target in self._target_type_to_wrapper_class_map]
if len(possible_wrappers) == 0: if len(possible_wrappers) == 0:
# No wrapper for this class # No wrapper for this class

View File

@ -214,10 +214,10 @@ class Spell(object):
if self.lang and Config.get(Config.SPELLCHECK): if self.lang and Config.get(Config.SPELLCHECK):
# if LANG is not a correct key (pt_BR or pt_PT), # if LANG is not a correct key (pt_BR or pt_PT),
# try only the language part of LANG # try only the language part of LANG
if self.lang not in self._installed_languages.keys(): if self.lang not in self._installed_languages:
self.lang = self.lang.split('_')[0] self.lang = self.lang.split('_')[0]
# if this still doesn't work we fall back to 'off' # if this still doesn't work we fall back to 'off'
if self.lang not in self._installed_languages.keys(): if self.lang not in self._installed_languages:
self.lang = 'off' self.lang = 'off'
else: else:
self.lang = 'off' self.lang = 'off'

View File

@ -338,7 +338,7 @@ def ansel_to_utf8(s):
elif s[0] in _onebyte: elif s[0] in _onebyte:
head = _onebyte[s[0]] head = _onebyte[s[0]]
s = s[1:] s = s[1:]
elif s[0] in _acombiners.keys(): elif s[0] in _acombiners:
c = _acombiners[s[0]] c = _acombiners[s[0]]
# always consume the combiner # always consume the combiner
s = s[1:] s = s[1:]
@ -372,9 +372,9 @@ def utf8_to_ansel(s):
if not head in _use_ASCII: if not head in _use_ASCII:
head = ' ' head = ' '
else: else:
if s[0] in _utoa.keys(): if s[0] in _utoa:
head = _utoa[s[0]] head = _utoa[s[0]]
elif s[0] in _ucombiners.keys(): elif s[0] in _ucombiners:
c = _ucombiners[s[0]] c = _ucombiners[s[0]]
# head happens to have last conversion to ansel # head happens to have last conversion to ansel
if len(head) == 1 and head[-1] in _printable_ascii: if len(head) == 1 and head[-1] in _printable_ascii:

View File

@ -276,12 +276,13 @@ class Callback(object):
returns a unique key that can be passed to disconnect(). returns a unique key that can be passed to disconnect().
""" """
# Check that signal exists. # Check that signal exists.
if signal_name not in self.__signal_map.keys(): if signal_name not in self.__signal_map:
self._log("Warning: attempt to connect to unknown signal: %s\n" % str(signal_name)) self._log("Warning: attempt to connect to unknown signal: %s\n"
% str(signal_name))
return return
# Add callable to callback_map # Add callable to callback_map
if signal_name not in self.__callback_map.keys(): if signal_name not in self.__callback_map:
self.__callback_map[signal_name] = [] self.__callback_map[signal_name] = []
self._current_key += 1 self._current_key += 1
@ -298,7 +299,7 @@ class Callback(object):
""" """
# Find the key in the callback map. # Find the key in the callback map.
for signal_name in self.__callback_map.keys(): for signal_name in self.__callback_map:
for cb in self.__callback_map[signal_name]: for cb in self.__callback_map[signal_name]:
(skey, fn) = cb (skey, fn) = cb
if skey == key: if skey == key:
@ -320,7 +321,7 @@ class Callback(object):
return return
# Check signal exists # Check signal exists
if signal_name not in self.__signal_map.keys(): if signal_name not in self.__signal_map:
self._warn("Attempt to emit to unknown signal: %s\n" self._warn("Attempt to emit to unknown signal: %s\n"
" from: file: %s\n" " from: file: %s\n"
" line: %d\n" " line: %d\n"
@ -390,8 +391,7 @@ class Callback(object):
% ((str(signal_name), ) + inspect.stack()[1][1:4] +\ % ((str(signal_name), ) + inspect.stack()[1][1:4] +\
(args[i], repr(type(args[i])), repr(arg_types[i])))) (args[i], repr(type(args[i])), repr(arg_types[i]))))
return return
if signal_name in self.__callback_map:
if signal_name in self.__callback_map.keys():
self._log("emitting signal: %s\n" % (signal_name, )) self._log("emitting signal: %s\n" % (signal_name, ))
# Don't bother if there are no callbacks. # Don't bother if there are no callbacks.
for (key, fn) in self.__callback_map[signal_name]: for (key, fn) in self.__callback_map[signal_name]:

View File

@ -379,7 +379,7 @@ class Extract(object):
value = [_("Personal information missing")] value = [_("Personal information missing")]
# list of information found # list of information found
for key in value: for key in value:
if key in chart[1].keys(): if key in chart[1]:
chart[1][key] += 1 chart[1][key] += 1
else: else:
chart[1][key] = 1 chart[1][key] = 1
@ -408,7 +408,7 @@ class Extract(object):
data = [] data = []
ext = self.extractors ext = self.extractors
# which methods to use # which methods to use
for name in self.extractors.keys(): for name in self.extractors:
option = menu.get_option_by_name(name) option = menu.get_option_by_name(name)
if option.get_value() == True: if option.get_value() == True:
# localized data title, value dict, type and data method # localized data title, value dict, type and data method

View File

@ -268,7 +268,7 @@ class CSVWriter(object):
family = self.db.get_family_from_handle(family_handle) family = self.db.get_family_from_handle(family_handle)
for child_ref in family.get_child_ref_list(): for child_ref in family.get_child_ref_list():
child_handle = child_ref.ref child_handle = child_ref.ref
if child_handle in self.plist.keys(): if child_handle in self.plist:
self.flist[family_handle] = 1 self.flist[family_handle] = 1
def update_empty(self): def update_empty(self):

View File

@ -345,7 +345,7 @@ class CSVParser(object):
return self.lookup(type, id) return self.lookup(type, id)
else: else:
return db_lookup return db_lookup
elif id.lower() in self.fref.keys(): elif id.lower() in self.fref:
return self.fref[id.lower()] return self.fref[id.lower()]
else: else:
return None return None
@ -357,7 +357,7 @@ class CSVParser(object):
return self.lookup(type, id) return self.lookup(type, id)
else: else:
return db_lookup return db_lookup
elif id.lower() in self.pref.keys(): elif id.lower() in self.pref:
return self.pref[id.lower()] return self.pref[id.lower()]
else: else:
return None return None

View File

@ -139,7 +139,7 @@ class Statusbar(gtk.HBox):
"""Get next unused statusbar id. """Get next unused statusbar id.
""" """
id = 1 id = 1
while id in self._bars.keys(): while id in self._bars:
id = id + 1 id = id + 1
return id return id