Revision: 6686 Author: cosoleto Date: 2009-04-23 20:25:23 +0000 (Thu, 23 Apr 2009)
Log Message: ----------- Replaced equality tests for None ('var == None', 'var != None') with identity test ('var is None', 'var is not None'). They are faster, especially on some object type (see also PEP 290).
Modified Paths: -------------- trunk/pywikipedia/catall.py trunk/pywikipedia/config.py trunk/pywikipedia/cosmetic_changes.py trunk/pywikipedia/date.py trunk/pywikipedia/generate_user_files.py trunk/pywikipedia/gui.py trunk/pywikipedia/interwiki.py trunk/pywikipedia/login.py trunk/pywikipedia/query.py trunk/pywikipedia/replace.py trunk/pywikipedia/userlib.py trunk/pywikipedia/wikipedia.py
Modified: trunk/pywikipedia/catall.py =================================================================== --- trunk/pywikipedia/catall.py 2009-04-23 17:44:17 UTC (rev 6685) +++ trunk/pywikipedia/catall.py 2009-04-23 20:25:23 UTC (rev 6686) @@ -118,7 +118,7 @@ wikipedia.output(c.title()) print "----------------------------------------" newcats=choosecats(text) - if newcats == None: + if newcats is None: make_categories(p, [], mysite) elif newcats != []: make_categories(p, newcats, mysite)
Modified: trunk/pywikipedia/config.py =================================================================== --- trunk/pywikipedia/config.py 2009-04-23 17:44:17 UTC (rev 6685) +++ trunk/pywikipedia/config.py 2009-04-23 20:25:23 UTC (rev 6686) @@ -472,7 +472,7 @@ print "WARNING: Configuration variable %r is defined but unknown. Misspelled?" %_key
# Fix up default console_encoding -if console_encoding == None: +if console_encoding is None: if __sys.platform=='win32': console_encoding = 'cp850' else:
Modified: trunk/pywikipedia/cosmetic_changes.py =================================================================== --- trunk/pywikipedia/cosmetic_changes.py 2009-04-23 17:44:17 UTC (rev 6685) +++ trunk/pywikipedia/cosmetic_changes.py 2009-04-23 20:25:23 UTC (rev 6686) @@ -217,7 +217,7 @@
# Remove unnecessary initial and final spaces from label. # Please note that some editors prefer spaces around pipes. (See [[en:Wikipedia:Semi-bots]]). We remove them anyway. - if label != None: + if label is not None: # Remove unnecessary leading spaces from label, # but remember if we did this because we want # to re-add it outside of the link later.
Modified: trunk/pywikipedia/date.py =================================================================== --- trunk/pywikipedia/date.py 2009-04-23 17:44:17 UTC (rev 6685) +++ trunk/pywikipedia/date.py 2009-04-23 20:25:23 UTC (rev 6686) @@ -1250,7 +1250,7 @@ raise AssertionError(u'pattern %s does not have 12 elements' % lang )
for i in range(12): - if patterns[i] != None: + if patterns[i] is not None: if isMnthOfYear: formats[yrMnthFmts[i]][lang] = eval(u'lambda v: dh_mnthOfYear( v, u"%s" )' % patterns[i]) else: @@ -1265,7 +1265,7 @@ The pattern must be have one %s that will be replaced by the localized month name. Use %%d for any other parameters that should be preserved. """ - if makeUpperCase == None: + if makeUpperCase is None: f = lambda s: s elif makeUpperCase == True: f = lambda s: s[0].upper() + s[1:]
Modified: trunk/pywikipedia/generate_user_files.py =================================================================== --- trunk/pywikipedia/generate_user_files.py 2009-04-23 17:44:17 UTC (rev 6685) +++ trunk/pywikipedia/generate_user_files.py 2009-04-23 20:25:23 UTC (rev 6686) @@ -7,7 +7,7 @@ base_dir = '' console_encoding = sys.stdout.encoding
-if console_encoding == None or sys.platform == 'cygwin': +if console_encoding is None or sys.platform == 'cygwin': console_encoding = "iso-8859-1"
def listchoice(clist = [], message = None, default = None):
Modified: trunk/pywikipedia/gui.py =================================================================== --- trunk/pywikipedia/gui.py 2009-04-23 17:44:17 UTC (rev 6685) +++ trunk/pywikipedia/gui.py 2009-04-23 20:25:23 UTC (rev 6686) @@ -217,7 +217,7 @@ class EditBoxWindow(Frame):
def __init__(self, parent = None, **kwargs): - if parent == None: + if parent is None: # create a new window parent = Tk() self.parent = parent @@ -376,7 +376,7 @@ self.parent.destroy()
def __init__(self, parent = None): - if parent == None: + if parent is None: # create a new window parent = Tk() self.parent = parent
Modified: trunk/pywikipedia/interwiki.py =================================================================== --- trunk/pywikipedia/interwiki.py 2009-04-23 17:44:17 UTC (rev 6685) +++ trunk/pywikipedia/interwiki.py 2009-04-23 20:25:23 UTC (rev 6686) @@ -295,11 +295,11 @@ """ seq2 = copy.copy(seq) if key: - if cmp == None: + if cmp is None: cmp = __builtins__.cmp seq2.sort(lambda x,y: cmp(key(x), key(y))) else: - if cmp == None: + if cmp is None: seq2.sort() else: seq2.sort(cmp) @@ -827,7 +827,7 @@ # make sure that none of the linked items is an auto item if globalvar.skipauto: dictName, year = page.autoFormat() - if dictName != None: + if dictName is not None: wikipedia.output(u'WARNING: %s:%s relates to %s:%s, which is an auto entry %s(%s)' % (self.originPage.site().language(), self.originPage.title(), page.site().language(),page.title(),dictName,year))
# Register this fact at the todo-counter. @@ -1091,7 +1091,7 @@ wikipedia.output(u"======Post-processing %s======" % self.originPage.aslink(True)) # Assemble list of accepted interwiki links new = self.assemble() - if new == None: # User said give up or autonomous with problem + if new is None: # User said give up or autonomous with problem wikipedia.output(u"======Aborted processing %s======" % self.originPage.aslink(True)) return
@@ -1215,7 +1215,7 @@ pltmp = new[page.site()] if pltmp != page: s = "None" - if pltmp != None: s = pltmp.aslink(True) + if pltmp is not None: s = pltmp.aslink(True) wikipedia.output(u"BUG>>> %s is not in the list of new links! Found %s." % (page.aslink(True), s)) raise SaveError
@@ -1435,7 +1435,7 @@ continue if globalvar.skipauto: dictName, year = page.autoFormat() - if dictName != None: + if dictName is not None: wikipedia.output(u'Skipping: %s is an auto entry %s(%s)' % (page.title(),dictName,year)) continue if globalvar.bracketonly: @@ -1524,7 +1524,7 @@ """ # First find the best language to work on site = self.selectQuerySite() - if site == None: + if site is None: wikipedia.output(u"NOTE: Nothing left to do") return False # Now assemble a reasonable list of pages to get @@ -1808,7 +1808,7 @@ except: wikipedia.output(u'Missing main page name')
- if newPages != None: + if newPages is not None: if len(namespaces) == 0: ns = 0 elif len(namespaces) == 1:
Modified: trunk/pywikipedia/login.py =================================================================== --- trunk/pywikipedia/login.py 2009-04-23 17:44:17 UTC (rev 6685) +++ trunk/pywikipedia/login.py 2009-04-23 20:25:23 UTC (rev 6686) @@ -299,7 +299,7 @@ for lang in namedict[familyName].iterkeys(): try: site = wikipedia.getSite(code=lang, fam=familyName) - if not forceLogin and site.loggedInAs(sysop = sysop) != None: + if not forceLogin and site.loggedInAs(sysop = sysop) is not None: wikipedia.output(u'Already logged in on %s' % site) else: loginMan = LoginManager(password, sysop = sysop, site = site, verbose=verbose)
Modified: trunk/pywikipedia/query.py =================================================================== --- trunk/pywikipedia/query.py 2009-04-23 17:44:17 UTC (rev 6685) +++ trunk/pywikipedia/query.py 2009-04-23 20:25:23 UTC (rev 6686) @@ -31,7 +31,7 @@ def GetData(params, site = None, verbose = False, useAPI = False, retryCount = 5, encodeTitle = True): """Get data from the query api, and convert it into a data object """ - if site == None: + if site is None: site = wikipedia.getSite()
for k,v in params.iteritems():
Modified: trunk/pywikipedia/replace.py =================================================================== --- trunk/pywikipedia/replace.py 2009-04-23 17:44:17 UTC (rev 6685) +++ trunk/pywikipedia/replace.py 2009-04-23 20:25:23 UTC (rev 6686) @@ -338,7 +338,7 @@ if 'inside' in self.exceptions: exceptions += self.exceptions['inside'] for old, new in self.replacements: - if self.sleep != None: + if self.sleep is not None: time.sleep(self.sleep) new_text = wikipedia.replaceExcept(new_text, old, new, exceptions, allowoverlap=self.allowoverlap) @@ -567,14 +567,14 @@
if (len(commandline_replacements) % 2): raise wikipedia.Error, 'require even number of replacements.' - elif (len(commandline_replacements) == 2 and fix == None): + elif (len(commandline_replacements) == 2 and fix is None): replacements.append((commandline_replacements[0], commandline_replacements[1])) if summary_commandline == False: editSummary = wikipedia.translate(wikipedia.getSite(), msg ) % (' (-' + commandline_replacements[0] + ' +' + commandline_replacements[1] + ')') elif (len(commandline_replacements) > 1): - if (fix == None): + if (fix is None): for i in xrange (0, len(commandline_replacements), 2): replacements.append((commandline_replacements[i], commandline_replacements[i + 1])) @@ -588,7 +588,7 @@ else: raise wikipedia.Error( 'Specifying -fix with replacements is undefined') - elif fix == None: + elif fix is None: old = wikipedia.input(u'Please enter the text that should be replaced:') new = wikipedia.input(u'Please enter the new text:') change = '(-' + old + ' +' + new
Modified: trunk/pywikipedia/userlib.py =================================================================== --- trunk/pywikipedia/userlib.py 2009-04-23 17:44:17 UTC (rev 6685) +++ trunk/pywikipedia/userlib.py 2009-04-23 20:25:23 UTC (rev 6686) @@ -171,9 +171,9 @@ #an autoblock, so can't be blocked. raise AutoblockUserError
- if expiry == None: + if expiry is None: expiry = input(u'Please enter the expiry time for the block:') - if reason == None: + if reason is None: reason = input(u'Please enter a reason for the block:')
token = self.site.getToken(self, sysop = True)
Modified: trunk/pywikipedia/wikipedia.py =================================================================== --- trunk/pywikipedia/wikipedia.py 2009-04-23 17:44:17 UTC (rev 6685) +++ trunk/pywikipedia/wikipedia.py 2009-04-23 20:25:23 UTC (rev 6686) @@ -332,7 +332,7 @@ # restriction affects us or not self._editrestriction = False
- if site == None: + if site is None: site = getSite() elif type(site) is str or type(site) is unicode: site = getSite(site) @@ -1399,7 +1399,7 @@ if comment and old.strip().replace('\r\n', '\n') != newtext.strip().replace('\r\n', '\n'): comment += translate(self.site(), cosmetic_changes.msg_append)
- if watchArticle == None: + if watchArticle is None: # if the page was loaded via get(), we know its status if hasattr(self, '_isWatched'): watchArticle = self._isWatched @@ -2258,7 +2258,7 @@
if throttle: put_throttle() - if reason == None: + if reason is None: reason = input(u'Please enter a reason for the move:') if self.isTalkPage(): movetalkpage = False @@ -2364,7 +2364,7 @@
if throttle: put_throttle() - if reason == None: + if reason is None: reason = input(u'Please enter a reason for the deletion:') answer = 'y' if prompt and not hasattr(self.site(), '_noDeletePrompt'): @@ -2457,7 +2457,7 @@ retrieved earlier).
""" - if self._deletedRevs == None: + if self._deletedRevs is None: self.loadDeletedRevisions() if timestamp not in self._deletedRevs: #TODO: Throw an exception instead? @@ -2482,7 +2482,7 @@ If undelete is False, mark the revision to remain deleted.
""" - if self._deletedRevs == None: + if self._deletedRevs is None: self.loadDeletedRevisions() if timestamp not in self._deletedRevs: #TODO: Throw an exception? @@ -2527,7 +2527,7 @@ 'restore': self.site().mediawiki_message('undeletebtn') }
- if self._deletedRevs != None and self._deletedRevsModified: + if self._deletedRevs is not None and self._deletedRevsModified: for ts in self._deletedRevs: if self._deletedRevs[ts][4]: formdata['ts'+ts] = '1' @@ -2565,7 +2565,7 @@ edit, move = edit.lower(), move.lower() if throttle: put_throttle() - if reason == None: + if reason is None: reason = input( u'Please enter a reason for the change of the protection level:') reason = reason.encode(self.site().encoding()) @@ -2588,7 +2588,7 @@ if move == 'none': move = ''
# Translate no duration to infinite - if duration == 'none' or duration == None: duration = 'infinite' + if duration == 'none' or duration is None: duration = 'infinite'
# Get cascading if cascading == False: @@ -2686,7 +2686,7 @@ imagePattern = u'(%s)' % capitalizationPattern(image).replace(r'_', '[ _]')
def filename_replacer(match): - if replacement == None: + if replacement is None: return u'' else: old = match.group() @@ -2697,7 +2697,7 @@ # link has to be closed properly. paramPattern = r'(?:|(?:(?![[).|[[.*?]])*?)' rImage = re.compile(ur'[[(?P<namespace>%s)(?P<filename>%s)(?P<params>%s*?)]]' % (namespacePattern, imagePattern, paramPattern)) - if replacement == None: + if replacement is None: new_text = rImage.sub('', new_text) else: new_text = rImage.sub('[[\g<namespace>%s\g<params>]]' % replacement, new_text) @@ -3073,7 +3073,7 @@ nshdr = header.namespaces[id] if self.site.family.isDefinedNSLanguage(id, lang): ns = self.site.namespace(id) - if ns == None: + if ns is None: ns = u'' if ns != nshdr: dflt = self.site.family.namespace('_default', id) @@ -3567,7 +3567,7 @@ instead.
""" - if insite == None: + if insite is None: insite = getSite() result = {} # Ignore interwiki links within nowiki tags, includeonly tags, pre tags, @@ -3609,7 +3609,7 @@ interwiki links).
""" - if site == None: + if site is None: site = getSite() if not site.validLanguageLinks(): return text @@ -3649,7 +3649,7 @@ """ # Find a marker that is not already in the text. marker = findmarker( oldtext, u'@@') - if site == None: + if site is None: site = getSite() separator = site.family.interwiki_text_separator cseparator = site.family.category_text_separator @@ -4133,7 +4133,7 @@ If fatal is True, the bot will stop running when the given family is unknown. If fatal is False, it will only raise a ValueError exception. """ - if fam == None: + if fam is None: fam = config.family
family = _familyCache.get(fam) @@ -4450,7 +4450,7 @@ * Actions: edit, move, delete, protect, upload * User levels: autoconfirmed, sysop, bot, empty string (always true) """ - if right == '' or right == None: + if right == '' or right is None: return True else: self._load(sysop = sysop) @@ -4531,7 +4531,7 @@ # wpEditToken is explicitly added as last value. # If a premature connection abort occurs while putting, the server will # not have received an edit token and thus refuse saving the page - if wpEditToken != None: + if wpEditToken is not None: l.append('wpEditToken=' + wpEditToken) return '&'.join(l)
@@ -4661,7 +4661,7 @@ Returns the HTML text of the page converted to unicode. """
- if retry==None: + if retry is None: retry=config.retry_on_fail
if False: #self.persistent_http and not data: @@ -5287,10 +5287,10 @@ 'letype' :'upload', 'lelimit' :int(number), } - if lestart != None: params['lestart'] = lestart - if leend != None: params['leend'] = leend - if leend != None: params['leuser'] = leuser - if leend != None: params['letitle'] = letitle + if lestart is not None: params['lestart'] = lestart + if leend is not None: params['leend'] = leend + if leend is not None: params['leuser'] = leuser + if leend is not None: params['letitle'] = letitle
data = query.GetData(params, useAPI = True, encodeTitle = False) @@ -5431,7 +5431,7 @@ html = self.getUrl(path) # output(u' html=%s' % (html)) m = entryR.search(html) - if m != None: + if m is not None: title = m.group('title') # output(u' title=%s' % ( title )) if title not in seen: @@ -5455,7 +5455,7 @@ html = self.getUrl(path) # output(u' html=%s' % (html)) m = entryR.search(html) - if m != None: + if m is not None: title = m.group('title') # output(u' title=%s' % ( title )) if title not in seen: @@ -5659,7 +5659,7 @@ # Avoid problems of encoding and stuff like that, let it divided please url = self.protectedpages_address() url += '&type=%s&level=%s' % (type, lvl) - if namespace != None: # /!\ if namespace seems simpler, but returns false when ns=0 + if namespace is not None: # /!\ if namespace seems simpler, but returns false when ns=0
url += '&namespace=%s' % namespace parser_text = self.getUrl(url) @@ -6247,7 +6247,7 @@
NOTE 2: it returns the image WITHOUT the image namespace. """ - if hash_found == None: # If the hash is none return None and not continue + if hash_found is None: # If the hash is none return None and not continue return None # Now get all the images with the same hash #action=query&format=xml&list=allimages&aisha1=%s @@ -6270,9 +6270,9 @@ _namespaceCache = {}
def getSite(code=None, fam=None, user=None, persistent_http=None, noLogin=False): - if code == None: + if code is None: code = default_code - if fam == None: + if fam is None: fam = default_family key = '%s:%s:%s:%s' % (fam, code, user, persistent_http) if key not in _sites:
pywikipedia-svn@lists.wikimedia.org