Bug 3018: remove calls to keys() dictionary method where possible
svn: r12562
This commit is contained in:
parent
5c9d8ab7ff
commit
fc90d5fce2
@ -204,7 +204,7 @@ class StandardCustomSelector(object):
|
||||
int_val = self.custom_key
|
||||
str_val = self.selector.child.get_text().strip()
|
||||
if str_val in self.mapping.values():
|
||||
for key in self.mapping.keys():
|
||||
for key in self.mapping:
|
||||
if str_val == self.mapping[key]:
|
||||
int_val = key
|
||||
break
|
||||
@ -220,7 +220,7 @@ class StandardCustomSelector(object):
|
||||
@type val: tuple
|
||||
"""
|
||||
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)
|
||||
elif self.custom_key is not None:
|
||||
self.selector.child.set_text(text)
|
||||
|
@ -1248,8 +1248,7 @@ class GrampletView(PageView.PersonNavView):
|
||||
|
||||
def save(self, *args):
|
||||
if debug: print "saving"
|
||||
if len(self.frame_map.keys() +
|
||||
self.detached_gramplets) == 0:
|
||||
if len(self.frame_map) + len(self.detached_gramplets) == 0:
|
||||
return # something is the matter
|
||||
filename = GRAMPLET_FILENAME
|
||||
try:
|
||||
@ -1581,7 +1580,7 @@ class GrampletView(PageView.PersonNavView):
|
||||
qr_menu = ag_menu.get_submenu()
|
||||
qr_menu = gtk.Menu()
|
||||
names = [AVAILABLE_GRAMPLETS[key]["tname"] for key
|
||||
in AVAILABLE_GRAMPLETS.keys()]
|
||||
in AVAILABLE_GRAMPLETS]
|
||||
names.sort()
|
||||
for name in names:
|
||||
Utils.add_menuitem(qr_menu, name,
|
||||
|
@ -59,7 +59,7 @@ class FilterList(object):
|
||||
def add(self, namespace, filt):
|
||||
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].append(filt)
|
||||
|
||||
@ -88,7 +88,7 @@ class FilterList(object):
|
||||
|
||||
f.write("<?xml version=\"1.0\" encoding=\"utf-8\"?>\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)
|
||||
filter_list = self.filter_namespaces[namespace]
|
||||
for the_filter in filter_list:
|
||||
|
@ -82,7 +82,7 @@ class FilterParser(handler.ContentHandler):
|
||||
self.gfilter_list.add(self.namespace, self.f)
|
||||
elif tag == "rule":
|
||||
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]
|
||||
else:
|
||||
try:
|
||||
|
@ -393,7 +393,7 @@ class ListModel(object):
|
||||
"""
|
||||
Selects the item associated with the pass information.
|
||||
"""
|
||||
if info in self.idmap.keys():
|
||||
if info in self.idmap:
|
||||
node = self.idmap[str(info)]
|
||||
self.selection.select_iter(node)
|
||||
|
||||
|
@ -174,18 +174,18 @@ class CommandLineTool(object):
|
||||
return
|
||||
|
||||
# Add tool-specific options
|
||||
for key in self.option_class.handler.options_dict.keys():
|
||||
if key not in self.options_dict.keys():
|
||||
for key in self.option_class.handler.options_dict:
|
||||
if key not in self.options_dict:
|
||||
self.options_dict[key] = self.option_class.handler.options_dict[key]
|
||||
|
||||
# Add help for tool-specific options
|
||||
for key in self.option_class.options_help.keys():
|
||||
if key not in self.options_help.keys():
|
||||
for key in self.option_class.options_help:
|
||||
if key not in self.options_help:
|
||||
self.options_help[key] = self.option_class.options_help[key]
|
||||
|
||||
def parse_option_str(self):
|
||||
for opt in self.options_str_dict.keys():
|
||||
if opt in self.options_dict.keys():
|
||||
for opt in self.options_str_dict:
|
||||
if opt in self.options_dict:
|
||||
converter = Utils.get_type_converter(self.options_dict[opt])
|
||||
self.options_dict[opt] = converter(self.options_str_dict[opt])
|
||||
self.option_class.handler.options_dict[opt] = self.options_dict[opt]
|
||||
@ -208,10 +208,10 @@ class CommandLineTool(object):
|
||||
return
|
||||
elif self.show == 'all':
|
||||
print " Available options:"
|
||||
for key in self.options_dict.keys():
|
||||
for key in self.options_dict:
|
||||
print " %s" % key
|
||||
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,
|
||||
self.options_help[self.show][0],
|
||||
self.options_help[self.show][1])
|
||||
|
@ -796,7 +796,7 @@ class RelationshipCalculator(object):
|
||||
self.dirtymap = False
|
||||
self.map_handle = orig_person.handle
|
||||
|
||||
for person_handle in secondMap.keys() :
|
||||
for person_handle in secondMap :
|
||||
if person_handle in firstMap :
|
||||
com = []
|
||||
#a common ancestor
|
||||
@ -957,7 +957,7 @@ class RelationshipCalculator(object):
|
||||
self.REL_FATHER_NOTBIRTH, childrel[0][1]),
|
||||
(mhandle, self.REL_MOTHER,
|
||||
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])
|
||||
if data[3] == gen.lib.ChildRefType.BIRTH :
|
||||
addstr = data[1]
|
||||
@ -969,7 +969,7 @@ class RelationshipCalculator(object):
|
||||
parentstodo[data[0]] = (persontodo,
|
||||
rel_str + addstr,
|
||||
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
|
||||
#update family list
|
||||
famlist = parentstodo[data[0]][2]
|
||||
@ -999,8 +999,7 @@ class RelationshipCalculator(object):
|
||||
pmap[chandle] = [[rel_str+addstr],[rel_fam_new]]
|
||||
fam += 1
|
||||
|
||||
for handle in parentstodo.keys():
|
||||
data = parentstodo[handle]
|
||||
for handle, data in parentstodo.iteritems():
|
||||
self.__apply_filter(db, data[0],
|
||||
data[1], data[2],
|
||||
pmap, depth, stoprecursemap)
|
||||
|
@ -281,8 +281,8 @@ class CommandLineReport(object):
|
||||
return
|
||||
menu = self.option_class.menu
|
||||
menu_opt_names = menu.get_all_option_names()
|
||||
for opt in self.options_str_dict.keys():
|
||||
if opt in self.options_dict.keys():
|
||||
for opt in self.options_str_dict:
|
||||
if opt in self.options_dict:
|
||||
converter = Utils.get_type_converter(self.options_dict[opt])
|
||||
self.options_dict[opt] = converter(self.options_str_dict[opt])
|
||||
self.option_class.handler.options_dict[opt] = \
|
||||
@ -349,8 +349,8 @@ class CommandLineReport(object):
|
||||
return
|
||||
elif self.show == 'all':
|
||||
print " Available options:"
|
||||
for key in self.options_dict.keys():
|
||||
if key in self.options_dict.keys():
|
||||
for key in self.options_dict:
|
||||
if key in self.options_dict:
|
||||
# Make the output nicer to read, assume that tab has 8 spaces
|
||||
if len(key) < 10:
|
||||
print " %s\t\t%s (%s)" % (key,
|
||||
@ -363,7 +363,7 @@ class CommandLineReport(object):
|
||||
else:
|
||||
print " %s" % key
|
||||
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,
|
||||
self.options_help[self.show][0],
|
||||
self.options_help[self.show][1])
|
||||
|
@ -141,7 +141,7 @@ class ScratchPadGrampsTypeWrapper(ScratchPadWrapper):
|
||||
'Source': self._db.get_source_from_handle}
|
||||
|
||||
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):
|
||||
return False
|
||||
|
||||
@ -1100,7 +1100,7 @@ class ScratchPadListView(object):
|
||||
|
||||
# Find a wrapper class
|
||||
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:
|
||||
# No wrapper for this class
|
||||
|
@ -214,10 +214,10 @@ class Spell(object):
|
||||
if self.lang and Config.get(Config.SPELLCHECK):
|
||||
# if LANG is not a correct key (pt_BR or pt_PT),
|
||||
# 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]
|
||||
# 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'
|
||||
else:
|
||||
self.lang = 'off'
|
||||
|
@ -338,7 +338,7 @@ def ansel_to_utf8(s):
|
||||
elif s[0] in _onebyte:
|
||||
head = _onebyte[s[0]]
|
||||
s = s[1:]
|
||||
elif s[0] in _acombiners.keys():
|
||||
elif s[0] in _acombiners:
|
||||
c = _acombiners[s[0]]
|
||||
# always consume the combiner
|
||||
s = s[1:]
|
||||
@ -372,9 +372,9 @@ def utf8_to_ansel(s):
|
||||
if not head in _use_ASCII:
|
||||
head = ' '
|
||||
else:
|
||||
if s[0] in _utoa.keys():
|
||||
if s[0] in _utoa:
|
||||
head = _utoa[s[0]]
|
||||
elif s[0] in _ucombiners.keys():
|
||||
elif s[0] in _ucombiners:
|
||||
c = _ucombiners[s[0]]
|
||||
# head happens to have last conversion to ansel
|
||||
if len(head) == 1 and head[-1] in _printable_ascii:
|
||||
|
@ -276,12 +276,13 @@ class Callback(object):
|
||||
returns a unique key that can be passed to disconnect().
|
||||
"""
|
||||
# Check that signal exists.
|
||||
if signal_name not in self.__signal_map.keys():
|
||||
self._log("Warning: attempt to connect to unknown signal: %s\n" % str(signal_name))
|
||||
if signal_name not in self.__signal_map:
|
||||
self._log("Warning: attempt to connect to unknown signal: %s\n"
|
||||
% str(signal_name))
|
||||
return
|
||||
|
||||
# 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._current_key += 1
|
||||
@ -298,7 +299,7 @@ class Callback(object):
|
||||
"""
|
||||
|
||||
# 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]:
|
||||
(skey, fn) = cb
|
||||
if skey == key:
|
||||
@ -320,7 +321,7 @@ class Callback(object):
|
||||
return
|
||||
|
||||
# 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"
|
||||
" from: file: %s\n"
|
||||
" line: %d\n"
|
||||
@ -390,8 +391,7 @@ class Callback(object):
|
||||
% ((str(signal_name), ) + inspect.stack()[1][1:4] +\
|
||||
(args[i], repr(type(args[i])), repr(arg_types[i]))))
|
||||
return
|
||||
|
||||
if signal_name in self.__callback_map.keys():
|
||||
if signal_name in self.__callback_map:
|
||||
self._log("emitting signal: %s\n" % (signal_name, ))
|
||||
# Don't bother if there are no callbacks.
|
||||
for (key, fn) in self.__callback_map[signal_name]:
|
||||
|
@ -379,7 +379,7 @@ class Extract(object):
|
||||
value = [_("Personal information missing")]
|
||||
# list of information found
|
||||
for key in value:
|
||||
if key in chart[1].keys():
|
||||
if key in chart[1]:
|
||||
chart[1][key] += 1
|
||||
else:
|
||||
chart[1][key] = 1
|
||||
@ -408,7 +408,7 @@ class Extract(object):
|
||||
data = []
|
||||
ext = self.extractors
|
||||
# which methods to use
|
||||
for name in self.extractors.keys():
|
||||
for name in self.extractors:
|
||||
option = menu.get_option_by_name(name)
|
||||
if option.get_value() == True:
|
||||
# localized data title, value dict, type and data method
|
||||
|
@ -268,7 +268,7 @@ class CSVWriter(object):
|
||||
family = self.db.get_family_from_handle(family_handle)
|
||||
for child_ref in family.get_child_ref_list():
|
||||
child_handle = child_ref.ref
|
||||
if child_handle in self.plist.keys():
|
||||
if child_handle in self.plist:
|
||||
self.flist[family_handle] = 1
|
||||
|
||||
def update_empty(self):
|
||||
|
@ -345,7 +345,7 @@ class CSVParser(object):
|
||||
return self.lookup(type, id)
|
||||
else:
|
||||
return db_lookup
|
||||
elif id.lower() in self.fref.keys():
|
||||
elif id.lower() in self.fref:
|
||||
return self.fref[id.lower()]
|
||||
else:
|
||||
return None
|
||||
@ -357,7 +357,7 @@ class CSVParser(object):
|
||||
return self.lookup(type, id)
|
||||
else:
|
||||
return db_lookup
|
||||
elif id.lower() in self.pref.keys():
|
||||
elif id.lower() in self.pref:
|
||||
return self.pref[id.lower()]
|
||||
else:
|
||||
return None
|
||||
|
@ -139,7 +139,7 @@ class Statusbar(gtk.HBox):
|
||||
"""Get next unused statusbar id.
|
||||
"""
|
||||
id = 1
|
||||
while id in self._bars.keys():
|
||||
while id in self._bars:
|
||||
id = id + 1
|
||||
|
||||
return id
|
||||
|
Loading…
x
Reference in New Issue
Block a user