Xqt has submitted this change and it was merged.
Change subject: [PEP8] changes
......................................................................
[PEP8] changes
Change-Id: Icfdde9e9c6fb32832b582ac88b52f1f0ced19f20
---
M upload.py
1 file changed, 29 insertions(+), 24 deletions(-)
Approvals:
Xqt: Looks good to me, approved
diff --git a/upload.py b/upload.py
index 11e76a5..8210770 100644
--- a/upload.py
+++ b/upload.py
@@ -19,11 +19,11 @@
"""
#
# (C) Rob W.W. Hooft, Andre Engels 2003-2004
-# (C) Pywikipedia bot team, 2003-2013
+# (C) Pywikibot team, 2003-2013
#
# Distributed under the terms of the MIT license.
#
-__version__='$Id$'
+__version__ = '$Id$'
#
import os
@@ -33,6 +33,7 @@
import wikipedia as pywikibot
import config
import query
+
def post_multipart(site, address, fields, files, cookies):
""" Post fields and files to an http host as multipart/form-data.
@@ -46,6 +47,7 @@
contentType, body = encode_multipart_formdata(fields, files)
return site.postData(address, body, contentType=contentType,
cookies=cookies)
+
def encode_multipart_formdata(fields, files):
"""
@@ -77,6 +79,7 @@
body = '\r\n'.join(lines)
content_type = 'multipart/form-data; boundary=%s' % boundary
return content_type, body
+
def get_content_type(filename):
return mimetypes.guess_type(filename)[0] or 'application/octet-stream'
@@ -136,8 +139,8 @@
file = uo.open(self.url)
if 'text/html' in file.info().getheader('Content-Type'):
- print \
-"Couldn't download the image: the requested URL was not found on this server."
+ print("Couldn't download the image: the requested URL "
+ "was not found on this server.")
return
content_len = file.info().getheader('Content-Length')
@@ -170,13 +173,13 @@
dt += 60
else:
if pywikibot.verbose:
- pywikibot.warning(
-u"No check length to retrieved data is possible.")
+ pywikibot.warning(u"No check length to retrieved "
+ u"data is possible.")
else:
# Opening local files with MyURLopener would be possible, but we
# don't do it because it only accepts ASCII characters in the
# filename.
- file = open(self.url,"rb")
+ file = open(self.url, "rb")
self._contents = file.read()
file.close()
@@ -255,10 +258,11 @@
If the user chooses not to retry, return null.
"""
- if not self.targetSite.has_api() or self.targetSite.versionnumber() < 16:
+ if not self.targetSite.has_api() or \
+ self.targetSite.versionnumber() < 16:
return self._uploadImageOld(debug)
- if not hasattr(self,'_contents'):
+ if not hasattr(self, '_contents'):
self.read_file_content()
filename = self.process_filename()
@@ -289,14 +293,14 @@
if pywikibot.verbose:
pywikibot.output("%s" % data)
- if 'error' in data: # error occured
+ if 'error' in data: # error occured
errCode = data['error']['code']
pywikibot.output("%s" % data)
else:
data = data['upload']
- if data['result'] == u'Warning': #upload success but return warning.
+ if data['result'] == u'Warning': # upload success but return warning.
pywikibot.output("Got warning message:")
- for k,v in data['warnings'].iteritems():
+ for k, v in data['warnings'].iteritems():
if k == 'duplicate-archive':
pywikibot.output(
"\tThe file is duplicate a deleted file %s." % v)
@@ -328,10 +332,10 @@
#No any warning, upload and online complete.
elif data['result'] == u'Success':
pywikibot.output(u"Upload successful.")
- return filename #data['filename']
+ return filename # data['filename']
def _uploadImageOld(self, debug=False):
- if not hasattr(self,'_contents'):
+ if not hasattr(self, '_contents'):
self.read_file_content()
filename = self.process_filename()
@@ -343,24 +347,24 @@
'wpUploadDescription': self.description,
'wpUploadAffirm': '1',
'wpUpload': 'upload bestand',
- 'wpEditToken': self.targetSite.getToken(), # Get an edit token so we can do the upload
- 'wpDestFile': filename, # Set the new filename
+ 'wpEditToken': self.targetSite.getToken(), # Get an edit token so we can do the upload
+ 'wpDestFile': filename, # Set the new filename
}
# This somehow doesn't work.
if self.ignoreWarning:
formdata["wpIgnoreWarning"] = "1"
if self.uploadByUrl:
- formdata["wpUploadFileURL"] = self.url
+ formdata["wpUploadFileURL"] = self.url
formdata["wpSourceType"] = 'Url'
# try to encode the strings to the encoding used by the target site.
- # if that's not possible (e.g. because there are non-Latin-1 characters and
- # the home Wikipedia uses Latin-1), convert all non-ASCII characters to
- # HTML entities.
+ # if that's not possible (e.g. because there are non-Latin-1 characters
+ # and the home Wikipedia uses Latin-1), convert all non-ASCII
+ # characters to HTML entities.
for key in formdata:
assert isinstance(key, basestring), \
- "ERROR: %s is not a string but %s" % (key, type(key))
+ "ERROR: %s is not a string but %s" % (key, type(key))
try:
formdata[key] = formdata[key].encode(self.targetSite.encoding())
except (UnicodeEncodeError, UnicodeDecodeError):
@@ -381,7 +385,7 @@
self.targetSite, self.targetSite.upload_address(),
formdata.items(),
(('wpUploadFile', encodedFilename, self._contents),),
- cookies = self.targetSite.cookies())
+ cookies=self.targetSite.cookies())
# There are 2 ways MediaWiki can react on success: either it gives
# a 200 with a success message, or it gives a 302 (redirection).
# Do we know how the "success!" HTML page should look like?
@@ -389,7 +393,7 @@
# show an English interface, this detection will fail!
success_msg = self.targetSite.mediawiki_message('successfulupload')
if success_msg in returned_html or response.code == 302:
- pywikibot.output(u"Upload successful.")
+ pywikibot.output(u"Upload successful.")
# The following is not a good idea, because the server also gives a
# 200 when something went wrong.
## if response.code in [200, 302]:
@@ -427,7 +431,8 @@
return self._uploadImageOld(debug)
else:
answer = pywikibot.inputChoice(
-u'Upload of %s probably failed. Above you see the HTML page which was returned by MediaWiki. Try again?'
+ u'Upload of %s probably failed. Above you see the HTML '
+ u'page which was returned by MediaWiki. Try again?'
% filename, ['Yes', 'No'], ['y', 'N'], 'N')
if answer == "y":
return self._uploadImageOld(debug)
--
To view, visit https://gerrit.wikimedia.org/r/98366
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Icfdde9e9c6fb32832b582ac88b52f1f0ced19f20
Gerrit-PatchSet: 2
Gerrit-Project: pywikibot/compat
Gerrit-Branch: master
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
jenkins-bot has submitted this change and it was merged.
Change subject: Change delinker.txt documentation to use Git.
......................................................................
Change delinker.txt documentation to use Git.
Change-Id: If8f082edb82af947e1db7fa0072ae9ce6a15d09e
---
M commonsdelinker/delinker.txt
1 file changed, 3 insertions(+), 4 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/commonsdelinker/delinker.txt b/commonsdelinker/delinker.txt
index 81eb8ca..a96979b 100644
--- a/commonsdelinker/delinker.txt
+++ b/commonsdelinker/delinker.txt
@@ -49,7 +49,7 @@
in plugins.txt.
== Requirements ==
-* A recent SVN checkout of the pywikipedia framework
+* A recent Git clone of the pywikipedia framework
* Python 2.4 or higher
* A MySQL database and the MySQLdb api for Python, version 1.2.1_p or higher
** In the future, probably also sqlite3 will be supported.
@@ -215,9 +215,8 @@
OTHER DEALINGS IN THE SOFTWARE.
The most recent version of this documentation can be found in the
-pywikipedia SVN, on <http://svn.wikimedia.org/svnroot/pywikipedia/
-trunk/pywikipedia/> and browsable on <http://svn.wikimedia.org/viewvc/
-pywikipedia/>. Copies maybe found on meta <http://meta.wikimedia.org/
+pywikipedia Git, <https://git.wikimedia.org/summary/
+pywikibot%2Fcompat.git>. Copies maybe found on meta <http://meta.wikimedia.org/
wiki/CommonsDelinker/For_operators> and BotWiki <http://botwiki.sno.cc/
wiki/Python:CommonsDelinker/For_operators>.
--
To view, visit https://gerrit.wikimedia.org/r/98125
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: If8f082edb82af947e1db7fa0072ae9ce6a15d09e
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/compat
Gerrit-Branch: master
Gerrit-Owner: Lewis Cawte <lewis(a)lewiscawte.me>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Xqt has submitted this change and it was merged.
Change subject: [PEP8] changes
......................................................................
[PEP8] changes
Change-Id: Ifea4187e91ba15f14ed154ea8c163dc93feda1f2
---
M wikipedia.py
1 file changed, 30 insertions(+), 26 deletions(-)
Approvals:
Xqt: Looks good to me, approved
diff --git a/wikipedia.py b/wikipedia.py
index e5c9b2b..a5da2cf 100644
--- a/wikipedia.py
+++ b/wikipedia.py
@@ -561,7 +561,7 @@
if not withSection:
sectionName = self.section(underscore=underscore)
if sectionName:
- title = title[:-len(sectionName)-1]
+ title = title[:-len(sectionName) - 1]
return title
#@deprecated("Page.title(withNamespace=False)")
@@ -601,7 +601,7 @@
sectionName = self.section(underscore=underscore)
title = self.title(underscore=underscore)
if sectionName:
- return title[:-len(sectionName)-1]
+ return title[:-len(sectionName) - 1]
else:
return title
@@ -746,7 +746,7 @@
else:
# Make sure we re-raise an exception we got on an earlier attempt
if hasattr(self, '_redirarg') and not get_redirect:
- raise IsRedirectPage, self._redirarg
+ raise IsRedirectPage(self._redirarg)
elif hasattr(self, '_getexception'):
if self._getexception == IsRedirectPage and get_redirect:
pass
@@ -919,7 +919,7 @@
output(u'Getting page %s' % self.title(asLink=True))
path = self.site().edit_address(self.urlname())
if oldid:
- path += "&oldid="+oldid
+ path += "&oldid=" + oldid
# Make sure Brion doesn't get angry by waiting if the last time a page
# was retrieved was not long enough ago.
if throttle:
@@ -2192,12 +2192,12 @@
not calledModuleName() in ('category_redirect', 'cosmetic_changes',
'touch'):
if config.cosmetic_changes_mylang_only:
- cc = (self.site.family.name == config.family and
- self.site.lang == config.mylang) or \
- self.site.family.name in \
- config.cosmetic_changes_enable.keys() and \
+ cc = ((self.site.family.name == config.family and
+ self.site.lang == config.mylang) or
+ self.site.family.name in
+ config.cosmetic_changes_enable.keys() and
self.site.lang in config.cosmetic_changes_enable[
- self.site.family.name]
+ self.site.family.name])
else:
cc = True
cc = cc and not (self.site.family.name in
@@ -2421,10 +2421,14 @@
# 'editconflict':"Edit conflict detected",
raise EditConflict(u'An edit conflict has occured.')
elif errorCode == 'spamdetected':
- # 'spamdetected':"Your edit was refused because it contained a spam fragment: ``\$1''",
+ # 'spamdetected':
+ # "Your edit was refused because it contained a spam
+ # fragment: ``\$1''",
raise SpamfilterError(data['error']['info'][62:-2])
elif errorCode == 'pagedeleted':
- # 'pagedeleted':"The page has been deleted since you fetched its timestamp",
+ # 'pagedeleted':
+ # "The page has been deleted since you fetched its
+ # timestamp",
# Make sure your system clock is correct if this error
# occurs without any reason!
# raise EditConflict(u'Someone deleted the page.')
@@ -2453,7 +2457,9 @@
retry_delay = 30
continue
elif errorCode == 'contenttoobig':
- # 'contenttoobig':"The content you supplied exceeds the article size limit of \$1 kilobytes",
+ # 'contenttoobig':
+ # "The content you supplied exceeds the article size limit
+ # of \$1 kilobytes",
raise LongPageError(len(params['text']),
int(data['error']['info'][59:-10]))
elif errorCode in ['protectedpage', 'customcssjsprotected',
@@ -2609,7 +2615,7 @@
% wait)
dblagged = True
time.sleep(wait)
- wait = min(wait*2, 300)
+ wait = min(wait * 2, 300)
continue
# Squid error 503
raise ServerError(response.code)
@@ -3401,15 +3407,13 @@
now = time.time()
response, data = self.site().postForm(address, predata)
data = data.encode(self.site().encoding())
-## get_throttle.setDelay(time.time() - now)
output = []
- # TODO: parse XML using an actual XML parser instead of regex!
+ # TODO: parse XML using an actual XML parser instead of regex!
r = re.compile(
"\<revision\>.*?\<id\>(?P<id>.*?)\<\/id\>.*?\<timestamp\>"
"(?P<timestamp>.*?)\<\/timestamp\>.*?\<(?:ip|username)\>"
"(?P<user>.*?)\</(?:ip|username)\>.*?\<text.*?\>"
"(?P<content>.*?)\<\/text\>", re.DOTALL)
-## r = re.compile("\<revision\>.*?\<timestamp\>(.*?)\<\/timestamp\>.*?\<(?:ip|username)\>(.*?)\<",re.DOTALL)
return [(match.group('id'),
match.group('timestamp'),
unescape(match.group('user')),
@@ -4035,7 +4039,7 @@
if self._deletedRevs and self._deletedRevsModified:
for ts in self._deletedRevs:
if self._deletedRevs[ts][4]:
- formdata['ts'+ts] = '1'
+ formdata['ts' + ts] = '1'
self._deletedRevs = None
# TODO: Check for errors below (have we succeeded? etc):
@@ -5012,7 +5016,7 @@
else:
raise RuntimeError("unknown type: %s call User:Ladsgroup to fix "
"this" % self._contents['entity'][0])
- self._title = self._title+str(self._contents['entity'][1])
+ self._title += str(self._contents['entity'][1])
return self._contents
@deprecate_arg("get", None)
@@ -5692,8 +5696,8 @@
flag = u"is set to default ('%s'), but should be '%s'" \
% (ns, nshdr)
elif dflt == nshdr:
- flag = u"is '%s', but should be removed (default value '%s')" \
- % (ns, nshdr)
+ flag = (u"is '%s', but should be removed "
+ u"(default value '%s')" % (ns, nshdr))
else:
flag = u"is '%s', but should be '%s'" % (ns, nshdr)
warning(u"Outdated family file %s: namespace['%s'][%i] %s"
@@ -5875,8 +5879,8 @@
flag = u"is set to default ('%s'), but should be '%s'" \
% (ns, nshdr)
elif dflt == nshdr:
- flag = u"is '%s', but should be removed (default value '%s')" \
- % (ns, nshdr)
+ flag = (u"is '%s', but should be removed "
+ u"(default value '%s')" % (ns, nshdr))
else:
flag = u"is '%s', but should be '%s'" % (ns, nshdr)
warning(u"Outdated family file %s: namespace['%s'][%i] %s"
@@ -6035,12 +6039,12 @@
if len(old) % 2 == 0:
# The first two chars represent an Esperanto letter.
# Following x's are doubled.
- new = esperanto + ''.join([old[2 * i]
- for i in xrange(1, len(old)/2)])
+ new = esperanto + ''.join([old[2 * i] for i in
+ xrange(1, len(old) / 2)])
else:
# The first character stays latin; only the x's are doubled.
new = latin + ''.join([old[2 * i + 1]
- for i in xrange(0, len(old)/2)])
+ for i in xrange(0, len(old) / 2)])
result += text[pos: match.start() + pos] + new
pos += match.start() + len(old)
else:
@@ -7768,7 +7772,7 @@
'review', 'stable', 'gblblock', 'renameuser',
'globalauth', 'gblrights', 'abusefilter',
'articlefeedbackv5', 'newusers'):
- raise NotImplementedError, mode
+ raise NotImplementedError(mode)
params = {
'action': 'query',
'list': 'logevents',
--
To view, visit https://gerrit.wikimedia.org/r/98360
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ifea4187e91ba15f14ed154ea8c163dc93feda1f2
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/compat
Gerrit-Branch: master
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot