jenkins-bot has submitted this change and it was merged.
Change subject: site.py: pyflake, remove unneeded debug print
......................................................................
site.py: pyflake, remove unneeded debug print
- explicit import statement for pywikibot.exceptions
- local variable 'filterredirs' is assigned to but never used
wrong name -> renamed to filterredir
- local variable 'prev_user' is assigned to but never used
- local variable 'filesize' is assigned to but never used
- local variable 'err' is assigned to but never used
- undefined name 'namespace'
Moreover:
- remove absolute path for pywikibot.data.api.APIError
- remove unneeded debug print of deprecated parameter
Added TODO in site_tests.py, some methods lack tests
Change-Id: I79660f877102472fcab00732f9f0c310bea3a0c8
---
M pywikibot/site.py
M tests/site_tests.py
2 files changed, 23 insertions(+), 17 deletions(-)
Approvals:
John Vandenberg: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/site.py b/pywikibot/site.py
index 3b4d817..385ed16 100644
--- a/pywikibot/site.py
+++ b/pywikibot/site.py
@@ -29,7 +29,16 @@
from pywikibot import deprecated
from pywikibot.throttle import Throttle
from pywikibot.data import api
-from pywikibot.exceptions import *
+from pywikibot.exceptions import (
+ EditConflict,
+ Error,
+ LockedPage,
+ NoPage,
+ NoSuchSite,
+ NoUsername,
+ SpamfilterError,
+ UserBlocked,
+)
if sys.version_info[0] > 2:
basestring = (str,)
@@ -743,7 +752,7 @@
if self.userinfo['name'] == self._username[sysop] and \
self.logged_in(sysop):
return
- except pywikibot.data.api.APIError: # May occur if you are not logged in (no API read permissions).
+ except api.APIError: # May occur if you are not logged in (no API read permissions).
pass
loginMan = api.LoginManager(site=self, sysop=sysop,
user=self._username[sysop])
@@ -1285,7 +1294,7 @@
m = re.match(r"^MediaWiki ([0-9]+)\.([0-9]+)(.*)$", versionstring)
if m:
return (int(m.group(1)), int(m.group(2)), m.group(3))
- except pywikibot.data.api.APIError: # May occur if you are not logged in (no API read permissions).
+ except api.APIError: # May occur if you are not logged in (no API read permissions).
return (0, 0, 0)
def loadpageinfo(self, page, preload=False):
@@ -2037,25 +2046,22 @@
level; can only be used if protect_type is specified
@param reverse: if True, iterate in reverse Unicode lexigraphic
order (default: iterate in forward order)
- @param includeredirects: DEPRECATED, use filterredirs instead
+ @param includeredirects: DEPRECATED, use filterredir instead
@param content: if True, load the current content of each iterated page
(default False)
"""
if not isinstance(namespace, int):
raise Error("allpages: only one namespace permitted.")
+
if includeredirects is not None:
- pywikibot.debug(
- u"allpages: 'includeRedirects' argument is deprecated; "
- u"use 'filterredirs'.",
- _logger)
if includeredirects:
if includeredirects == "only":
- filterredirs = True
+ filterredir = True
else:
- filterredirs = None
+ filterredir = None
else:
- filterredirs = False
+ filterredir = False
apgen = self._generator(api.PageGenerator, type_arg="allpages",
gapnamespace=str(namespace),
@@ -3035,7 +3041,6 @@
for rev in sorted(list(page._revisions.keys()), reverse=True):
# start with most recent revision first
if rev.user != last_user:
- prev_user = rev.user
break
else:
raise pywikibot.Error(
@@ -3336,9 +3341,8 @@
if not os.path.isfile(source_filename):
raise ValueError("File '%s' does not exist."
% source_filename)
- filesize = os.path.getsize(source_filename)
# TODO: if file size exceeds some threshold (to be determined),
- # upload by chunks
+ # upload by chunks (--> os.path.getsize(source_filename))
req = api.Request(site=self, action="upload", token=token,
filename=imagepage.title(withNamespace=False),
file=source_filename, comment=comment,
@@ -3358,7 +3362,7 @@
req["ignorewarnings"] = ""
try:
result = req.submit()
- except api.APIError as err:
+ except api.APIError:
# TODO: catch and process foreseeable errors
raise
result = result["upload"]
@@ -3404,7 +3408,6 @@
# N.B. API still provides no way to access Special:Newpages content
# directly, so we get new pages indirectly through 'recentchanges'
- namespaces = namespaces if namespaces is not None else namespace
gen = self.recentchanges(
start=start, end=end, reverse=reverse,
namespaces=namespaces, changetype="new", user=user,
@@ -3702,7 +3705,7 @@
req = api.Request(site=self, **params)
data = req.submit()
if 'success' not in data:
- raise pywikibot.data.api.APIError(data['errors'])
+ raise api.APIError(data['errors'])
return data['entities']
def preloaditempages(self, pagelist, groupsize=50):
diff --git a/tests/site_tests.py b/tests/site_tests.py
index cbce977..cca2db0 100644
--- a/tests/site_tests.py
+++ b/tests/site_tests.py
@@ -952,6 +952,9 @@
self.assertType(rndpage, pywikibot.Page)
self.assertTrue(rndpage.namespace() in [6, 7])
+ # TODO: test newimages, longpages, shortpages, ancientpages, unwatchedpages
+ # and the other following methods in site.py
+
def testExtensions(self):
# test automatically getting _extensions
del mysite._extensions
--
To view, visit https://gerrit.wikimedia.org/r/143056
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I79660f877102472fcab00732f9f0c310bea3a0c8
Gerrit-PatchSet: 10
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Mpaa <mpaa.wiki(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: Mpaa <mpaa.wiki(a)gmail.com>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: (bug 66345) solve unicode error in html2unicode
......................................................................
(bug 66345) solve unicode error in html2unicode
unichr() isn't defined for values >= 0x10000 in python 2
(I guess in py3 it is, but there are remaining problems on Windows
for py < 3.4)
and raises a ValueError with that remark "(narrow Python build)".
Now unicode char is created as '\Uxxxxxxxx' literal.
Change-Id: I7a38aae7a19079e7cdf93d6cc6922b2214558973
---
M pywikibot/page.py
1 file changed, 7 insertions(+), 1 deletion(-)
Approvals:
Merlijn van Deen: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/page.py b/pywikibot/page.py
index fb55dfb..1d4c643 100644
--- a/pywikibot/page.py
+++ b/pywikibot/page.py
@@ -29,6 +29,7 @@
import logging
import re
+import sys
import unicodedata
import collections
@@ -3623,7 +3624,12 @@
except KeyError:
pass
if unicodeCodepoint and unicodeCodepoint not in ignore:
- result += unichr(unicodeCodepoint)
+ # solve narrow Python build exception (UTF-16)
+ if unicodeCodepoint > sys.maxunicode:
+ unicode_literal = lambda n: eval("u'\U%08x'" % n)
+ result += unicode_literal(unicodeCodepoint)
+ else:
+ result += unichr(unicodeCodepoint)
else:
# Leave the entity unchanged
result += text[match.start():match.end()]
--
To view, visit https://gerrit.wikimedia.org/r/138311
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I7a38aae7a19079e7cdf93d6cc6922b2214558973
Gerrit-PatchSet: 2
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Legoktm <legoktm.wikipedia(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: Russell Blau <russblau(a)imapmail.org>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot <>