jenkins-bot has submitted this change and it was merged.
Change subject: [PEP8] changes
......................................................................
[PEP8] changes
Change-Id: I06c5caef1dbde999c10c59605b5f5af4cf06fe83
---
M delete.py
M delinker.py
M disambredir.py
M diskcache.py
4 files changed, 68 insertions(+), 47 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/delete.py b/delete.py
index de37b43..7c14955 100644
--- a/delete.py
+++ b/delete.py
@@ -32,12 +32,13 @@
__version__ = '$Id$'
#
-import wikipedia as pywikibot
+import pywikibot
from pywikibot import i18n
import config
import catlib
import pagegenerators
+
class DeletionRobot:
""" This robot allows deletion of pages en masse. """
diff --git a/delinker.py b/delinker.py
index 955e0f6..4c4b6fe 100644
--- a/delinker.py
+++ b/delinker.py
@@ -2,9 +2,11 @@
__version__ = '$Id$'
-import wikipedia, config
+import sys
+import os
+import wikipedia
+import config
-import sys, os
sys.path.insert(0, 'commonsdelinker')
module = 'delinker'
diff --git a/disambredir.py b/disambredir.py
index d2ea6bc..ffc644e 100644
--- a/disambredir.py
+++ b/disambredir.py
@@ -5,15 +5,17 @@
each link that goes to a redirect page whether it should be replaced.
"""
#
-# (C) André Engels and others, 2006-2009
+# (c) André Engels and others, 2006-2009
+# (c) pywikibot team, 2006-2013
#
# Distributed under the terms of the MIT license.
#
-__version__='$Id$'
+__version__ = '$Id$'
#
-import wikipedia as pywikibot
+import sys
+import re
+import pywikibot
import pagegenerators
-import sys, re
import catlib
msg = {
@@ -31,19 +33,20 @@
'zh': u'機器人: 修改消歧義頁中的重定向連結',
}
+
def firstcap(string):
- return string[0].upper()+string[1:]
+ return string[0].upper() + string[1:]
+
def treat(text, linkedPage, targetPage):
- """
- Based on the method of the same name in solve_disambiguation.py.
- """
+ """ Based on the method of the same name in solve_disambiguation.py.
"""
# make a backup of the original text so we can show the changes later
- linkR =
re.compile(r'\[\[(?P<title>[^\]\|#]*)(?P<section>#[^\]\|]*)?(\|(?P<label>[^\]]*))?\]\](?P<linktrail>'
+ linktrail + ')')
+ linkR = re.compile(
+
r'\[\[(?P<title>[^\]\|#]*)(?P<section>#[^\]\|]*)?(\|(?P<label>[^\]]*))?\]\](?P<linktrail>'
+ linktrail + ')')
curpos = 0
# This loop will run until we have finished the current page
while True:
- m = linkR.search(text, pos = curpos)
+ m = linkR.search(text, pos=curpos)
if not m:
break
# Make sure that next time around we will not find this same hit.
@@ -61,12 +64,13 @@
context = 30
# at the beginning of the link, start red color.
# at the end of the link, reset the color to default
- pywikibot.output(text[max(0, m.start() - context) : m.start()] +
- '\03{lightred}' + text[m.start() : m.end()] +
- '\03{default}' + text[m.end() : m.end() + context])
+ pywikibot.output(text[max(0, m.start() - context):m.start()] +
+ '\03{lightred}' + text[m.start():m.end()] +
+ '\03{default}' + text[m.end():m.end() + context])
while True:
choice = pywikibot.input(
- u"Option (N=do not change, y=change link to
\03{lightpurple}%s\03{default}, r=change and replace text,
u=unlink)"%targetPage.title())
+ u"Option (N=do not change, y=change link to
\03{lightpurple}%s\03{default}, r=change and replace text, u=unlink)"
+ % targetPage.title())
try:
choice = choice[0]
except:
@@ -83,7 +87,7 @@
if not link_text:
# or like this: [[page_title]]trailing_chars
link_text = page_title
- if m.group('section') == None:
+ if m.group('section') is None:
section = ''
else:
section = m.group('section')
@@ -100,8 +104,8 @@
if link_text[0].isupper():
new_page_title = targetPage.title()
else:
- new_page_title = targetPage.title()[0].lower() + \
- targetPage.title()[1:]
+ new_page_title = (targetPage.title()[0].lower() +
+ targetPage.title()[1:])
if replaceit and trailing_chars:
newlink = "[[%s%s]]%s" % (new_page_title, section, trailing_chars)
elif replaceit or (new_page_title == link_text and not section):
@@ -120,6 +124,7 @@
continue
return text
+
def workon(page, links):
text = page.get()
# Show the title of the page we're working on.
@@ -129,12 +134,13 @@
for page2 in links:
try:
target = page2.getRedirectTarget()
- except (pywikibot.Error,pywikibot.SectionError):
+ except (pywikibot.Error, pywikibot.SectionError):
continue
text = treat(text, page2, target)
if text != page.get():
comment = pywikibot.translate(mysite, msg)
page.put(text, comment)
+
def main():
global mysite, linktrail, page
@@ -149,7 +155,7 @@
linktrail = mysite.linktrail()
try:
generator = pagegenerators.CategorizedPageGenerator(
- mysite.disambcategory(), start = start)
+ mysite.disambcategory(), start=start)
except pywikibot.NoPage:
pywikibot.output(
"The bot does not know the disambiguation category for your
wiki.")
@@ -163,18 +169,18 @@
if page.isRedirectPage():
continue
linked = page.linkedPages()
- pagestodo.append((page,linked))
+ pagestodo.append((page, linked))
pagestoload += linked
if len(pagestoload) > 49:
- pywikibot.getall(mysite,pagestoload)
+ pywikibot.getall(mysite, pagestoload)
for page, links in pagestodo:
- workon(page,links)
+ workon(page, links)
pagestoload = []
pagestodo = []
+
if __name__ == "__main__":
try:
main()
finally:
pywikibot.stopme()
-
diff --git a/diskcache.py b/diskcache.py
index 8dcfb75..23f3dcc 100644
--- a/diskcache.py
+++ b/diskcache.py
@@ -1,6 +1,14 @@
+#!/usr/bin/python
# -*- coding: utf-8 -*-
-
+""" Dictionary like disk caching module """
+#
+# (c) Bryan Tong Minh, 2008
+# (c) pywikibot team, 2008-2013
+#
+# Distributed under the terms of the MIT license
+#
__version__ = '$Id$'
+#
import random
import config
@@ -8,27 +16,27 @@
#
http://mail.python.org/pipermail/python-list/2006-March/375280.html
try:
- os.SEEK_SET
+ os.SEEK_SET
except AttributeError:
- os.SEEK_SET, os.SEEK_CUR, os.SEEK_END = range(3)
+ os.SEEK_SET, os.SEEK_CUR, os.SEEK_END = range(3)
-## Dictionary like disk caching module
-## (c) Copyright 2008 - Bryan Tong Minh / The Pywikipediabot team
-## Licensed under the terms of the MIT license
class CachedReadOnlyDictI(object):
"""A cached readonly dict with case insensitive
keys."""
- def __init__(self, data, prefix = "", max_size = 10, cache_base =
'cache'):
+
+ def __init__(self, data, prefix="", max_size=10,
cache_base='cache'):
self.max_size = max_size
while True:
- self.cache_path = config.datafilepath(cache_base, prefix + ''.join(
- [random.choice('abcdefghijklmnopqrstuvwxyz')
- for i in xrange(16)]))
- if not os.path.exists(self.cache_path): break
+ self.cache_path = config.datafilepath(
+ cache_base, prefix + ''.join(
+ [random.choice('abcdefghijklmnopqrstuvwxyz')
+ for i in xrange(16)]))
+ if not os.path.exists(self.cache_path):
+ break
self.cache_file = open(self.cache_path, 'wb+')
lookup = [-1] * 36
- data.sort(key = lambda i: i[0])
+ data.sort(key=lambda i: i[0])
for key, value in data:
if type(key) is unicode:
key = key.encode('utf-8')
@@ -36,11 +44,12 @@
key = str(key)
key = key.lower()
index = key[0]
- if not ((index >= 'a' and index <= 'z') or (index >=
'0' and index <= '9')) or '\t' in key:
+ if not ((index >= 'a' and index <= 'z') or
+ (index >= '0' and index <= '9')) or
'\t' in key:
raise RuntimeError('Only alphabetic keys are supported', key)
if index < 'a':
- index = ord(index) - 48 + 26 # Numeric
+ index = ord(index) - 48 + 26 # Numeric
else:
index = ord(index) - 97
if lookup[index] == -1:
@@ -54,9 +63,11 @@
if len(key) > 0xFF:
raise RuntimeError('Key length must be smaller than %i' % 0xFF)
if len(value) > 0xFFFFFF:
- raise RuntimeError('Value length must be smaller than %i' %
0xFFFFFF)
+ raise RuntimeError('Value length must be smaller than %i'
+ % 0xFFFFFF)
- self.cache_file.write('%02x%s%06x%s' % (len(key), key, len(value),
value))
+ self.cache_file.write('%02x%s%06x%s'
+ % (len(key), key, len(value), value))
self.lookup = lookup
@@ -96,11 +107,12 @@
index = key[0]
except IndexError:
raise KeyError(key)
- if not ((index >= 'a' and index <= 'z') or (index >=
'0' and index <= '9')):
+ if not ((index >= 'a' and index <= 'z') or
+ (index >= '0' and index <= '9')):
raise KeyError(key)
if index < 'a':
- i = ord(index) - 48 + 26 # Numeric
+ i = ord(index) - 48 + 26 # Numeric
else:
i = ord(index) - 97
@@ -134,8 +146,8 @@
length = int(self.read(6, key), 16)
self.cache_file.seek(length, os.SEEK_CUR)
-
- def read(self, length, key = ''):
+ def read(self, length, key=''):
s = self.cache_file.read(length)
- if not s: raise KeyError(key)
+ if not s:
+ raise KeyError(key)
return s
--
To view, visit
https://gerrit.wikimedia.org/r/103539
To unsubscribe, visit
https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I06c5caef1dbde999c10c59605b5f5af4cf06fe83
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/compat
Gerrit-Branch: master
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot