Revision: 6666
Author: russblau
Date: 2009-04-22 14:18:07 +0000 (Wed, 22 Apr 2009)
Log Message:
-----------
remove some unnecessary .iterkeys() calls and clean up code
Modified Paths:
--------------
branches/rewrite/pywikibot/bot.py
branches/rewrite/pywikibot/date.py
branches/rewrite/pywikibot/login.py
branches/rewrite/pywikibot/page.py
branches/rewrite/pywikibot/site.py
Modified: branches/rewrite/pywikibot/bot.py
===================================================================
--- branches/rewrite/pywikibot/bot.py 2009-04-22 14:01:22 UTC (rev 6665)
+++ branches/rewrite/pywikibot/bot.py 2009-04-22 14:18:07 UTC (rev 6666)
@@ -479,8 +479,8 @@
# contains the options overriden from defaults
self.options = {}
- validOptions = set(Bot.availableOptions.iterkeys())
- receivedOptions = set(kwargs.iterkeys())
+ validOptions = set(Bot.availableOptions)
+ receivedOptions = set(kwargs)
for opt in receivedOptions & validOptions:
self.options[opt] = kwargs[opt]
Modified: branches/rewrite/pywikibot/date.py
===================================================================
--- branches/rewrite/pywikibot/date.py 2009-04-22 14:01:22 UTC (rev 6665)
+++ branches/rewrite/pywikibot/date.py 2009-04-22 14:18:07 UTC (rev 6666)
@@ -277,8 +277,8 @@
'T' : ( _decimalDigits, lambda v: unicode(v+543), lambda v: int(v)-543 ),
}
-# Allows to search for '(%%)|(%d)|(%R)|...", and allows one digit 1-9 too set the size of zero-padding for numbers
-_reParameters = re.compile(u'|'.join([ u'(%%[1-9]?%s)' % s for s in _digitDecoders.iterkeys() ]))
+# Allows to search for '(%%)|(%d)|(%R)|...", and allows one digit 1-9 to set the size of zero-padding for numbers
+_reParameters = re.compile(u'|'.join( u'(%%[1-9]?%s)' % s for s in _digitDecoders ))
# A map of sitecode+pattern to (re matching object and corresponding decoders)
_escPtrnCache2 = {}
@@ -1567,7 +1567,7 @@
>>> date.test()
"""
- for formatName in formats.iterkeys():
+ for formatName in formats:
if quick:
testMapEntry( formatName, showAll, formatLimits[formatName][1] ) # Only test the first value in the test range
Modified: branches/rewrite/pywikibot/login.py
===================================================================
--- branches/rewrite/pywikibot/login.py 2009-04-22 14:01:22 UTC (rev 6665)
+++ branches/rewrite/pywikibot/login.py 2009-04-22 14:18:07 UTC (rev 6666)
@@ -246,8 +246,8 @@
namedict = config.sysopnames
else:
namedict = config.usernames
- for familyName in namedict.iterkeys():
- for lang in namedict[familyName].iterkeys():
+ for familyName in namedict:
+ for lang in namedict[familyName]:
try:
site = pywikibot.getSite(code=lang, fam=familyName)
if not forceLogin and (site.logged_in(sysop) and site.user()) != None:
Modified: branches/rewrite/pywikibot/page.py
===================================================================
--- branches/rewrite/pywikibot/page.py 2009-04-22 14:01:22 UTC (rev 6665)
+++ branches/rewrite/pywikibot/page.py 2009-04-22 14:18:07 UTC (rev 6666)
@@ -410,7 +410,7 @@
def previousRevision(self):
"""Return the revision id for the previous revision of this Page."""
vh = self.getVersionHistory(revCount=2)
- revkey = sorted(self._revisions.iterkeys(), reverse=True)[1]
+ revkey = sorted(self._revisions, reverse=True)[1]
return revkey
def exists(self):
@@ -846,7 +846,7 @@
args = template[1]
positional = []
named = {}
- for key in sorted(args.iterkeys()):
+ for key in sorted(args):
try:
int(key)
except ValueError:
@@ -910,7 +910,7 @@
self._revisions[rev].timestamp,
self._revisions[rev].user,
self._revisions[rev].comment
- ) for rev in sorted(self._revisions.iterkeys(),
+ ) for rev in sorted(self._revisions,
reverse=not reverseOrder)[ : revCount]
]
@@ -1449,7 +1449,7 @@
@type recurse: int or bool
"""
- namespaces = [x for x in self.site().namespaces().iterkeys()
+ namespaces = [x for x in self.site().namespaces()
if x>=0 and x!=14]
for member in self.site().categorymembers(self,
namespaces=namespaces):
Modified: branches/rewrite/pywikibot/site.py
===================================================================
--- branches/rewrite/pywikibot/site.py 2009-04-22 14:01:22 UTC (rev 6665)
+++ branches/rewrite/pywikibot/site.py 2009-04-22 14:18:07 UTC (rev 6666)
@@ -221,9 +221,9 @@
def validLanguageLinks(self):
"""Return list of language codes that can be used in interwiki links."""
- nsnames = sum(self.namespaces().itervalues(), [])
- return [l for l in self.languages()
- if l[:1].upper() + l[1:] not in self.namespaces()]
+ nsnames = [name for name in self.namespaces().itervalues()]
+ return [lang for lang in self.languages()
+ if lang[:1].upper() + lang[1:] not in nsnames]
def ns_index(self, namespace):
"""Given a namespace name, return its int index, or None if invalid."""
@@ -1001,7 +1001,7 @@
raise pywikibot.CircularRedirect(redirmap[title])
for pagedata in result['query']['pages'].itervalues():
# there should be only one value in 'pages', and it is the target
- if pagedata['title'] not in redirmap.values():
+ if pagedata['title'] not in redirmap.itervalues():
raise RuntimeError(
"getredirtarget: target page '%s' not found in 'redirects'"
% pagedata['title'])