Revision: 6006
Author: russblau
Date: 2008-10-20 18:41:13 +0000 (Mon, 20 Oct 2008)
Log Message:
-----------
more Site tests and bug-fixes
Modified Paths:
--------------
branches/rewrite/pywikibot/site.py
branches/rewrite/pywikibot/tests/site_tests.py
Modified: branches/rewrite/pywikibot/site.py
===================================================================
--- branches/rewrite/pywikibot/site.py 2008-10-20 16:39:05 UTC (rev 6005)
+++ branches/rewrite/pywikibot/site.py 2008-10-20 18:41:13 UTC (rev 6006)
@@ -52,6 +52,8 @@
% locals())
del __kw[old_arg]
return method(*__args, **__kw)
+ wrapper.__doc__ = method.__doc__
+ wrapper.__name__ = method.__name__
return wrapper
return decorator
@@ -895,9 +897,11 @@
"""
bltitle = page.title(withSection=False).encode(self.encoding())
blgen = api.PageGenerator("backlinks", gbltitle=bltitle, site=self)
- if namespaces is not None:
+ if isinstance(namespaces, list):
blgen.request["gblnamespace"] = u"|".join(unicode(ns)
for ns in namespaces)
+ elif namespaces is not None:
+ blgen.request["gblnamespace"] = str(namespaces)
if filterRedirects is not None:
blgen.request["gblfilterredir"] = filterRedirects and "redirects"\
or "nonredirects"
@@ -918,9 +922,11 @@
"""
eititle = page.title(withSection=False).encode(self.encoding())
eigen = api.PageGenerator("embeddedin", geititle=eititle, site=self)
- if namespaces is not None:
+ if isinstance(namespaces, list):
eigen.request["geinamespace"] = u"|".join(unicode(ns)
for ns in namespaces)
+ elif namespaces is not None:
+ eigen.request["geinamespace"] = str(namespaces)
if filterRedirects is not None:
eigen.request["geifilterredir"] = filterRedirects and "redirects"\
or "nonredirects"
@@ -964,9 +970,11 @@
plgen.request['titles'] = pltitle
if follow_redirects:
plgen.request['redirects'] = ''
- if namespaces is not None:
+ if isinstance(namespaces, list):
plgen.request["gplnamespace"] = u"|".join(unicode(ns)
for ns in namespaces)
+ elif namespaces is not None:
+ plgen.request["gplnamespace"] = str(namespaces)
return plgen
@deprecate_arg("withSortKey", None) # Sortkey doesn't work with generator
@@ -993,9 +1001,11 @@
tltitle = page.title(withSection=False).encode(self.encoding())
tlgen = api.PageGenerator("templates", titles=tltitle, site=self)
- if namespaces is not None:
+ if isinstance(namespaces, list):
tlgen.request["gtlnamespace"] = u"|".join(unicode(ns)
for ns in namespaces)
+ elif namespaces is not None:
+ tlgen.request["gtlnamespace"] = str(namespaces)
return tlgen
def categorymembers(self, category, namespaces=None, limit=None):
@@ -1019,9 +1029,11 @@
cmtitle = category.title(withSection=False).encode(self.encoding())
cmgen = api.PageGenerator("categorymembers", gcmtitle=cmtitle,
gcmprop="ids|title|sortkey", site=self)
- if namespaces is not None:
- cmgen.request["gcmnamespace"] = u"|".join(str(ns)
+ if isinstance(namespaces, list):
+ cmgen.request["gcmnamespace"] = u"|".join(unicode(ns)
for ns in namespaces)
+ elif namespaces is not None:
+ cmgen.request["gcmnamespace"] = str(namespaces)
if isinstance(limit, int):
cmgen.limit = limit
return cmgen
@@ -1465,9 +1477,11 @@
"""
eugen = api.PageGenerator("exturlusage", geuquery=url,
geuprotocol=protocol, site=self)
- if namespaces is not None:
+ if isinstance(namespaces, list):
eugen.request["geunamespace"] = u"|".join(unicode(ns)
for ns in namespaces)
+ elif namespaces is not None:
+ eugen.request["geunamespace"] = str(namespaces)
if isinstance(limit, int):
eugen.limit = limit
return eugen
@@ -1487,9 +1501,11 @@
"""
iugen = api.PageGenerator("imageusage", site=self,
giutitle=image.title(withSection=False))
- if namespaces is not None:
+ if isinstance(namespaces, list):
iugen.request["giunamespace"] = u"|".join(unicode(ns)
for ns in namespaces)
+ elif namespaces is not None:
+ iugen.request["giunamespace"] = str(namespaces)
if isinstance(limit, int):
iugen.limit = limit
if filterredir is not None:
@@ -1577,7 +1593,9 @@
if start < end:
raise Error(
"recentchanges: start must be later than end with reverse=False")
- rcgen = api.ListGenerator("recentchanges", site=self)
+ rcgen = api.ListGenerator("recentchanges", site=self,
+ rcprop="user|comment|timestamp|title|ids"
+ "|redirect|patrolled|loginfo|flags")
if start is not None:
rcgen.request["rcstart"] = start
if end is not None:
@@ -1586,9 +1604,11 @@
rcgen.request["rcdir"] = "newer"
if isinstance(limit, int):
rcgen.limit = limit
- if namespaces is not None:
- rcgen.request["rcunamespace"] = u"|".join(unicode(ns)
+ if isinstance(namespaces, list):
+ rcgen.request["rcnamespace"] = u"|".join(unicode(ns)
for ns in namespaces)
+ elif namespaces is not None:
+ rcgen.request["rcnamespace"] = str(namespaces)
if pagelist:
rcgen.request["rctitles"] = u"|".join(p.title(withSection=False)
for p in pagelist)
@@ -1597,7 +1617,7 @@
filters = {'minor': showMinor,
'bot': showBot,
'anon': showAnon,
- 'redirects': showRedirects,
+ 'redirect': showRedirects,
'patrolled': showPatrolled}
rcshow = []
for item in filters:
@@ -1608,7 +1628,7 @@
return rcgen
@deprecate_arg("number", "limit")
- def search(self, searchstring, namespaces=[0], where="text",
+ def search(self, searchstring, namespaces=None, where="text",
getredirects=False, limit=None):
"""Iterate Pages that contain the searchstring.
@@ -1619,11 +1639,10 @@
@type searchstring: unicode
@param where: Where to search; value must be "text" or "titles" (many
wikis do not support title search)
- @param namespaces: search only in these namespaces (default: 0)
+ @param namespaces: search only in these namespaces (defaults to 0)
@type namespaces: list of ints
@param getredirects: if True, include redirects in results
@param limit: maximum number of results to iterate
- @param number: deprecated, synonym for 'limit'
"""
if not searchstring:
@@ -1635,11 +1654,11 @@
if not namespaces:
logger.warning("search: namespaces cannot be empty; using [0].")
namespaces = [0]
- if isinstance(namespaces, basestring):
- srgen.request["gsrnamespace"] = namespaces
- else:
+ if isinstance(namespaces, list):
srgen.request["gsrnamespace"] = u"|".join(unicode(ns)
for ns in namespaces)
+ else:
+ srgen.request["gsrnamespace"] = str(namespaces)
if getredirects:
srgen.request["gsrredirects"] = ""
if isinstance(limit, int):
@@ -1692,9 +1711,11 @@
ucgen.request["ucdir"] = "newer"
if isinstance(limit, int):
ucgen.limit = limit
- if namespaces is not None:
+ if isinstance(namespaces, list):
ucgen.request["ucnamespace"] = u"|".join(unicode(ns)
for ns in namespaces)
+ elif namespaces is not None:
+ ucgen.request["ucnamespace"] = str(namespaces)
if showMinor is not None:
ucgen.request["ucshow"] = showMinor and "minor" or "!minor"
return ucgen
@@ -1741,9 +1762,11 @@
wlgen.request["wldir"] = "newer"
if isinstance(limit, int):
wlgen.limit = limit
- if namespaces is not None:
+ if isinstance(namespaces, list):
wlgen.request["wlnamespace"] = u"|".join(unicode(ns)
- for ns in namespaces)
+ for ns in namespaces)
+ elif namespaces is not None:
+ wlgen.request["wlnamespace"] = str(namespaces)
filters = {'minor': showMinor,
'bot': showBot,
'anon': showAnon}
@@ -1843,9 +1866,11 @@
"""
rngen = api.PageGenerator("random", site=self)
rngen.limit = limit
- if namespaces:
- rngen.request["wlnamespace"] = u"|".join(unicode(ns)
- for ns in namespaces)
+ if isinstance(namespaces, list):
+ rngen.request["grnnamespace"] = u"|".join(unicode(ns)
+ for ns in namespaces)
+ elif namespaces is not None:
+ rngen.request["grnnamespace"] = str(namespaces)
return rngen
# catalog of editpage error codes, for use in generating messages
@@ -2208,6 +2233,8 @@
# TODO: implement undelete
+ # TODO: implement patrol
+
#### METHODS NOT IMPLEMENTED YET ####
class NotImplementedYet:
Modified: branches/rewrite/pywikibot/tests/site_tests.py
===================================================================
--- branches/rewrite/pywikibot/tests/site_tests.py 2008-10-20 16:39:05 UTC (rev 6005)
+++ branches/rewrite/pywikibot/tests/site_tests.py 2008-10-20 18:41:13 UTC (rev 6006)
@@ -15,6 +15,7 @@
mysite = pywikibot.Site()
mainpage = pywikibot.Page(pywikibot.Link("Main Page", mysite))
+imagepage = iter(mainpage.imagelinks()).next() # 1st image on main page
class TestSiteObject(unittest.TestCase):
@@ -359,7 +360,7 @@
for cat in mysite.allcategories(limit=5, prefix="Def"):
self.assertType(cat, pywikibot.Category)
self.assertTrue(cat.title(withNamespace=False).startswith("Def"))
- # Bug # 15985
+## # Bug # 15985
## for cat in mysite.allcategories(limit=5, start="Hij", reverse=True):
## self.assertType(cat, pywikibot.Category)
## self.assertTrue(cat.title(withNamespace=False) <= "Hij")
@@ -405,7 +406,7 @@
self.assertType(impage, pywikibot.ImagePage)
self.assertTrue(mysite.page_exists(impage))
self.assertTrue(impage.title(withNamespace=False) >= "Ba")
- # Bug # 15985
+## # Bug # 15985
## for impage in mysite.allimages(start="Da", reverse=True, limit=5):
## self.assertType(impage, pywikibot.ImagePage)
## self.assertTrue(mysite.page_exists(impage))
@@ -449,34 +450,37 @@
for t in xrange(1, len(timestamps)):
self.assertTrue(timestamps[t] >= timestamps[t-1])
- for block in mysite.blocks(starttime="20080101000001", limit=5):
+ for block in mysite.blocks(starttime="2008-01-01T00:00:01", limit=5):
self.assertType(block, dict)
for prop in props:
self.assertTrue(prop in block)
- for block in mysite.blocks(endtime="20080131235959", limit=5):
+ for block in mysite.blocks(endtime="2008-01-31T23:59:59", limit=5):
self.assertType(block, dict)
for prop in props:
self.assertTrue(prop in block)
- for block in mysite.blocks(starttime="20080202000001",
- endtime="20080202235959",
+ for block in mysite.blocks(starttime="2008-02-02T00:00:01",
+ endtime="2008-02-02T23:59:59",
reverse=True, limit=5):
self.assertType(block, dict)
for prop in props:
self.assertTrue(prop in block)
- for block in mysite.blocks(starttime="20080203235959",
- endtime="20080203000001",
+ for block in mysite.blocks(starttime="2008-02-03T23:59:59",
+ endtime="2008-02-03T00:00:01",
limit=5):
self.assertType(block, dict)
for prop in props:
self.assertTrue(prop in block)
# starttime earlier than endtime
self.assertRaises(pywikibot.Error, mysite.blocks,
- starttime="20080203000001",
- endtime="20080203235959", limit=5)
+ starttime="2008-02-03T00:00:01",
+ endtime="2008-02-03T23:59:59", limit=5)
# reverse: endtime earlier than starttime
self.assertRaises(pywikibot.Error, mysite.blocks,
- starttime="20080203235959",
- endtime="20080203000001", reverse=True, limit=5)
+ starttime="2008-02-03T23:59:59",
+ endtime="2008-02-03T00:00:01", reverse=True, limit=5)
+ for block in mysite.blocks(users=mysite.user(), limit=5):
+ self.assertType(block, dict)
+ self.assertEqual(block['user'], mysite.user())
def testExturlusage(self):
"""Test the site.exturlusage() method"""
@@ -493,8 +497,6 @@
def testImageusage(self):
"""Test the site.imageusage() method"""
- imagepage = iter(mainpage.imagelinks()).next()
- # use first image appearing on main page
iu = list(mysite.imageusage(imagepage, limit=10))
self.assertTrue(len(iu) <= 10)
self.assertTrue(all(isinstance(link, pywikibot.Page)
@@ -526,32 +528,32 @@
for entry in mysite.logevents(user=mysite.user(), limit=3):
self.assertTrue("user" in entry
and entry["user"] == mysite.user())
- for entry in mysite.logevents(start="20080101000001", limit=5):
+ for entry in mysite.logevents(start="2008-01-01T00:00:01", limit=5):
self.assertType(entry, dict)
self.assertTrue(entry['timestamp'] <= "2008-01-01T00:00:01Z")
- for entry in mysite.logevents(end="20080131235959", limit=5):
+ for entry in mysite.logevents(end="2008-01-31T23:59:59", limit=5):
self.assertType(entry, dict)
self.assertTrue(entry['timestamp'] >= "2008-01-31T23:59:59Z")
- for entry in mysite.logevents(start="20080202000001",
- end="20080202235959",
+ for entry in mysite.logevents(start="2008-02-02T00:00:01",
+ end="2008-02-02T23:59:59",
reverse=True, limit=5):
self.assertType(entry, dict)
self.assertTrue("2008-02-02T00:00:01Z" <= entry['timestamp']
<= "2008-02-02T23:59:59Z")
- for entry in mysite.logevents(start="20080203235959",
- end="20080203000001",
+ for entry in mysite.logevents(start="2008-02-03T23:59:59",
+ end="2008-02-03T00:00:01",
limit=5):
self.assertType(entry, dict)
self.assertTrue("2008-02-03T00:00:01Z" <= entry['timestamp']
<= "2008-02-03T23:59:59Z")
# starttime earlier than endtime
self.assertRaises(pywikibot.Error, mysite.logevents,
- start="20080203000001",
- end="20080203235959", limit=5)
+ start="2008-02-03T00:00:01",
+ end="2008-02-03T23:59:59", limit=5)
# reverse: endtime earlier than starttime
self.assertRaises(pywikibot.Error, mysite.logevents,
- start="20080203235959",
- end="20080203000001", reverse=True, limit=5)
+ start="2008-02-03T23:59:59",
+ end="2008-02-03T00:00:01", reverse=True, limit=5)
def testRecentchanges(self):
"""Test the site.recentchanges() method"""
@@ -560,6 +562,89 @@
self.assertTrue(len(rc) <= 10)
self.assertTrue(all(isinstance(change, dict)
for change in rc))
+ for change in mysite.recentchanges(start="2008-10-01T01:02:03Z",
+ limit=5):
+ self.assertType(change, dict)
+ self.assertTrue(change['timestamp'] <= "2008-10-01T01:02:03Z")
+ for change in mysite.recentchanges(end="2008-04-01T02:03:04Z",
+ limit=5):
+ self.assertType(change, dict)
+ self.assertTrue(change['timestamp'] >= "2008-10-01T02:03:04Z")
+ for change in mysite.recentchanges(start="2008-10-01T03:05:07Z",
+ limit=5, reverse=True):
+ self.assertType(change, dict)
+ self.assertTrue(change['timestamp'] >= "2008-10-01T03:05:07Z")
+ for change in mysite.recentchanges(end="2008-10-01T04:06:08Z",
+ limit=5, reverse=True):
+ self.assertType(change, dict)
+ self.assertTrue(change['timestamp'] <= "2008-10-01T04:06:08Z")
+ for change in mysite.recentchanges(start="2008-10-03T11:59:59Z",
+ end="2008-10-03T00:00:01Z",
+ limit=5):
+ self.assertType(change, dict)
+ self.assertTrue("2008-10-03T00:00:01Z" <= change['timestamp']
+ <= "2008-10-03T11:59:59Z")
+ for change in mysite.recentchanges(start="2008-10-05T06:00:01Z",
+ end="2008-10-05T23:59:59Z",
+ reverse=True, limit=5):
+ self.assertType(change, dict)
+ self.assertTrue("2008-10-05T06:00:01Z" <= change['timestamp']
+ <= "2008-10-05T23:59:59Z")
+ # start earlier than end
+ self.assertRaises(pywikibot.Error, mysite.recentchanges,
+ start="2008-02-03T00:00:01",
+ end="2008-02-03T23:59:59", limit=5)
+ # reverse: end earlier than start
+ self.assertRaises(pywikibot.Error, mysite.recentchanges,
+ start="2008-02-03T23:59:59",
+ end="2008-02-03T00:00:01", reverse=True, limit=5)
+ for change in mysite.recentchanges(namespaces=[6,7], limit=5):
+ self.assertType(change, dict)
+ self.assertTrue("title" in change and "ns" in change)
+ title = change['title']
+ self.assertTrue(":" in title)
+ prefix = title[ : title.index(":")]
+ self.assertTrue(mysite.ns_index(prefix) in [6,7])
+ self.assertTrue(change["ns"] in [6,7])
+ for change in mysite.recentchanges(pagelist=[mainpage, imagepage],
+ limit=5):
+ self.assertType(change, dict)
+ self.assertTrue("title" in change)
+ self.assertTrue(change["title"] in (mainpage.title(),
+ imagepage.title()))
+ for typ in ("edit", "new", "log"):
+ for change in mysite.recentchanges(changetype=typ, limit=5):
+ self.assertType(change, dict)
+ self.assertTrue("type" in change)
+ self.assertEqual(change["type"], typ)
+ for change in mysite.recentchanges(showMinor=True, limit=5):
+ self.assertType(change, dict)
+ self.assertTrue("minor" in change)
+ for change in mysite.recentchanges(showMinor=False, limit=5):
+ self.assertType(change, dict)
+ self.assertTrue("minor" not in change)
+ for change in mysite.recentchanges(showBot=True, limit=5):
+ self.assertType(change, dict)
+ self.assertTrue("bot" in change)
+ for change in mysite.recentchanges(showBot=False, limit=5):
+ self.assertType(change, dict)
+ self.assertTrue("bot" not in change)
+ for change in mysite.recentchanges(showAnon=True, limit=5):
+ self.assertType(change, dict)
+ for change in mysite.recentchanges(showAnon=False, limit=5):
+ self.assertType(change, dict)
+ for change in mysite.recentchanges(showRedirects=True, limit=5):
+ self.assertType(change, dict)
+ self.assertTrue("redirect" in change)
+ for change in mysite.recentchanges(showRedirects=False, limit=5):
+ self.assertType(change, dict)
+ self.assertTrue("redirect" not in change)
+ for change in mysite.recentchanges(showPatrolled=True, limit=5):
+ self.assertType(change, dict)
+ self.assertTrue("patrolled" in change)
+ for change in mysite.recentchanges(showPatrolled=False, limit=5):
+ self.assertType(change, dict)
+ self.assertTrue("patrolled" not in change)
def testSearch(self):
"""Test the site.search() method"""
@@ -568,6 +653,20 @@
self.assertTrue(len(se) <= 10)
self.assertTrue(all(isinstance(hit, pywikibot.Page)
for hit in se))
+ self.assertTrue(all(hit.namespace() == 0 for hit in se))
+ for hit in mysite.search("common", namespaces=4, limit=5):
+ self.assertType(hit, pywikibot.Page)
+ self.assertEqual(hit.namespace(), 4)
+ for hit in mysite.search("word", namespaces=[5,6,7], limit=5):
+ self.assertType(hit, pywikibot.Page)
+ self.assertTrue(hit.namespace() in [5,6,7])
+ for hit in mysite.search("another", namespaces="8|9|10", limit=5):
+ self.assertType(hit, pywikibot.Page)
+ self.assertTrue(hit.namespace() in [8,9,10])
+ for hit in mysite.search("wiki", namespaces=0, limit=10,
+ getredirects=True):
+ self.assertType(hit, pywikibot.Page)
+ self.assertEqual(hit.namespace(), 0)
def testUsercontribs(self):
"""Test the site.usercontribs() method"""
@@ -576,7 +675,72 @@
self.assertTrue(len(uc) <= 10)
self.assertTrue(all(isinstance(contrib, dict)
for contrib in uc))
+ self.assertTrue(all("user" in contrib
+ and contrib["user"] == mysite.user()
+ for contrib in uc))
+ for contrib in mysite.usercontribs(userprefix="John", limit=5):
+ self.assertType(contrib, dict)
+ for key in ("user", "title", "ns", "pageid", "revid"):
+ self.assertTrue(key in contrib)
+ self.assertTrue(contrib["user"].startswith("John"))
+ for contrib in mysite.usercontribs(userprefix="Jane",
+ start="2008-10-06T01:02:03Z",
+ limit=5):
+ self.assertTrue(contrib['timestamp'] <= "2008-10-06T01:02:03Z")
+ for contrib in mysite.usercontribs(userprefix="Jane",
+ end="2008-10-07T02:03:04Z",
+ limit=5):
+ self.assertTrue(contrib['timestamp'] >= "2008-10-07T02:03:04Z")
+ for contrib in mysite.usercontribs(userprefix="Brion",
+ start="2008-10-08T03:05:07Z",
+ limit=5, reverse=True):
+ self.assertTrue(contrib['timestamp'] >= "2008-10-08T03:05:07Z")
+ for contrib in mysite.usercontribs(userprefix="Brion",
+ end="2008-10-09T04:06:08Z",
+ limit=5, reverse=True):
+ self.assertTrue(contrib['timestamp'] <= "2008-10-09T04:06:08Z")
+ for contrib in mysite.usercontribs(userprefix="Tim",
+ start="2008-10-10T11:59:59Z",
+ end="2008-10-10T00:00:01Z",
+ limit=5):
+ self.assertTrue("2008-10-10T00:00:01Z" <= contrib['timestamp']
+ <= "2008-10-10T11:59:59Z")
+ for contrib in mysite.usercontribs(userprefix="Tim",
+ start="2008-10-11T06:00:01Z",
+ end="2008-10-11T23:59:59Z",
+ reverse=True, limit=5):
+ self.assertTrue("2008-10-11T06:00:01Z" <= contrib['timestamp']
+ <= "2008-10-11T23:59:59Z")
+ # start earlier than end
+ self.assertRaises(pywikibot.Error, mysite.usercontribs,
+ userprefix="Jim",
+ start="2008-10-03T00:00:01",
+ end="2008-10-03T23:59:59", limit=5)
+ # reverse: end earlier than start
+ self.assertRaises(pywikibot.Error, mysite.usercontribs,
+ userprefix="Jim",
+ start="2008-10-03T23:59:59",
+ end="2008-10-03T00:00:01", reverse=True, limit=5)
+ for contrib in mysite.usercontribs(user=mysite.user(),
+ namespaces=14, limit=5):
+ self.assertType(contrib, dict)
+ self.assertTrue("title" in contrib)
+ self.assertTrue(contrib["title"].startswith(mysite.namespace(14)))
+ for contrib in mysite.usercontribs(user=mysite.user(),
+ namespaces=[10,11], limit=5):
+ self.assertType(contrib, dict)
+ self.assertTrue("title" in contrib)
+ self.assertTrue(contrib["ns"] in (10, 11))
+ for contrib in mysite.usercontribs(user=mysite.user(),
+ showMinor=True, limit=5):
+ self.assertType(contrib, dict)
+ self.assertTrue("minor" in contrib)
+ for contrib in mysite.usercontribs(user=mysite.user(),
+ showMinor=False, limit=5):
+ self.assertType(contrib, dict)
+ self.assertTrue("minor" not in contrib)
+
def testWatchlistrevs(self):
"""Test the site.watchlist_revs() method"""
Revision: 6005
Author: russblau
Date: 2008-10-20 16:39:05 +0000 (Mon, 20 Oct 2008)
Log Message:
-----------
query-continue could sometimes return an int instead of a str
Modified Paths:
--------------
branches/rewrite/pywikibot/data/api.py
Modified: branches/rewrite/pywikibot/data/api.py
===================================================================
--- branches/rewrite/pywikibot/data/api.py 2008-10-20 14:02:43 UTC (rev 6004)
+++ branches/rewrite/pywikibot/data/api.py 2008-10-20 16:39:05 UTC (rev 6005)
@@ -396,7 +396,9 @@
if not self.module in self.data["query-continue"]:
raise Error("Missing '%s' key in ['query-continue'] value."
% self.module)
- self.request.update(self.data["query-continue"][self.module])
+ update = self.data["query-continue"][self.module]
+ for key in update:
+ self.request[key] = str(update[key])
def result(self, data):
"""Process result data as needed for particular subclass."""
Revision: 6003
Author: filnik
Date: 2008-10-20 13:44:30 +0000 (Mon, 20 Oct 2008)
Log Message:
-----------
BugFix in the whitelistEraser function, regex not fully working, wait() function really improved
Modified Paths:
--------------
trunk/pywikipedia/checkimages.py
Modified: trunk/pywikipedia/checkimages.py
===================================================================
--- trunk/pywikipedia/checkimages.py 2008-10-20 03:11:06 UTC (rev 6002)
+++ trunk/pywikipedia/checkimages.py 2008-10-20 13:44:30 UTC (rev 6003)
@@ -1177,27 +1177,65 @@
wikipedia.output('') # Print a blank line.
return False
- def wait(self, waitTime):
+ def wait(self, waitTime, generator, normal, limit):
""" Skip the images uploaded before x seconds to let
the users to fix the image's problem alone in the
first x seconds.
"""
- #http://pytz.sourceforge.net/ <- maybe useful?
- imagedata = self.timestamp
- # '2008-06-18T08:04:29Z'
- img_time = datetime.datetime.strptime(imagedata, u"%Y-%m-%dT%H:%M:%SZ") #not relative to localtime
- now = datetime.datetime.strptime(str(datetime.datetime.utcnow()).split('.')[0], "%Y-%m-%d %H:%M:%S") #timezones are UTC
- # + seconds to be sure that now > img_time
- while now < img_time:
- now = (now + datetime.timedelta(seconds=1))
- delta = now - img_time
- secs_of_diff = delta.seconds
- if waitTime > secs_of_diff:
- wikipedia.output(u'Skipping %s, uploaded %s seconds ago..' % (self.imageName, int(secs_of_diff)))
- return True # Still wait
- else:
- return False # No ok, continue
-
+ imagesToSkip = 0
+ while 1:
+ loadOtherImages = True # ensure that all the images loaded aren't to skip!
+ for image in generator:
+ if normal:
+ imageData = image
+ image = imageData[0]
+ timestamp = imageData[1]
+ else:
+ timestamp = image.getLatestUploader()[1]
+ #http://pytz.sourceforge.net/ <- maybe useful?
+ # '2008-06-18T08:04:29Z'
+ img_time = datetime.datetime.strptime(timestamp, u"%Y-%m-%dT%H:%M:%SZ") #not relative to localtime
+ now = datetime.datetime.strptime(str(datetime.datetime.utcnow()).split('.')[0], "%Y-%m-%d %H:%M:%S") #timezones are UTC
+ # + seconds to be sure that now > img_time
+ while now < img_time:
+ now = (now + datetime.timedelta(seconds=1))
+ delta = now - img_time
+ secs_of_diff = delta.seconds
+ if waitTime > secs_of_diff:
+ wikipedia.output(u'Skipping %s, uploaded %s seconds ago..' % (image.title(), int(secs_of_diff)))
+ imagesToSkip += 1
+ continue # Still wait
+ else:
+ loadOtherImages = False
+ break # No ok, continue
+ # if yes, we have skipped all the images given!
+ if loadOtherImages:
+ generator = self.site.newimages(number = limit, lestart = timestamp)
+ imagesToSkip = 0
+ # continue to load images! continue
+ continue
+ else:
+ break # ok some other images, go below
+ # if normal, we can take as many images as "limit" has told us, otherwise, sorry, nope.
+ if normal:
+ newGen = list()
+ imagesToSkip += 1 # some calcs, better add 1
+ # Add new images, instead of the images skipped
+ newImages = self.site.newimages(number = imagesToSkip, lestart = timestamp)
+ for imageData in generator:
+ if normal:
+ image = imageData[0]
+ timestamp = imageData[1]
+ uploader = imageData[2]
+ comment = imageData[3]
+ newGen.append([image, timestamp, uploader, comment])
+ else:
+ image = imageData
+ newGen.append(image)
+ num = 0
+ for imageData in newImages:
+ newGen.append(imageData)
+ return newGen
def isTagged(self):
""" Understand if an image is already tagged or not. """
@@ -1220,15 +1258,17 @@
# Load the white templates(hidden template is the same as white template, regarding the meaning)
white_templates_found = 0
hiddentemplate = self.loadHiddenTemplates()
- for l in hiddentemplate:
+ for regexWhiteLicense in hiddentemplate:
+ fullRegexWL = r'\{\{(?:template:|)(?:%s[ \n]*?(?:\n|\||\}|<)|creator:)' % regexWhiteLicense.lower()
if self.tagged == False:
# why creator? Because on commons there's a template such as {{creator:name}} that.. works
- res = re.findall(r'\{\{(?:[Tt]emplate:|)(?:%s[ \n]*?(?:\n|\||\}|<)|creator:)' % l.lower(), self.imageCheckText.lower())
+ res = re.findall(fullRegexWL, self.imageCheckText.lower())
if res != []:
- white_templates_found += 1
- if l != '' and l != ' ': # Check that l is not nothing or a space
+ for element in res: # if a regex gives more than 1 results, are more than 1 template found.
+ white_templates_found += 1
+ if regexWhiteLicense != '' and regexWhiteLicense != ' ': # Check that regexWhiteLicense is not nothing or a space
# Deleting! (replace the template with nothing)
- regex_white_template = re.compile(r'\{\{(?:template:|)(?:%s|creator)' % l, re.IGNORECASE)
+ regex_white_template = re.compile(fullRegexWL, re.IGNORECASE)
self.imageCheckText = regex_white_template.sub(r'', self.imageCheckText)
if white_templates_found == 1:
wikipedia.output(u'A white template found, skipping the template...')
@@ -1348,7 +1388,7 @@
self.findAdditionalProblems()
# If the image exists (maybe it has been deleting during the oder
# checking parts or something, who knows? ;-))
- #if p.exists(): <-- improve the bot, better to make as
+ #if p.exists(): <-- improve thebot, better to make as
# less call to the server as possible
# Here begins the check block.
if self.tagged == True:
@@ -1585,6 +1625,8 @@
#parsed = False
if wait:
printWithTimeZone(u'Skipping the images uploaded less than %s seconds ago..' % wait_number)
+ # Let's sleep...
+ generator = mainClass.wait(wait_number, generator, normal, limit)
for image in generator:
# When you've a lot of image to skip before working use this workaround, otherwise
# let this commented, thanks. [ decoment also parsed = False if you want to use it
@@ -1615,13 +1657,7 @@
except IndexError:# Namespace image not found, that's not an image! Let's skip...
wikipedia.output(u"%s is not an image, skipping..." % image.title())
continue
- mainClass.setParameters(imageName, timestamp, uploader) # Setting the image for the main class
- # If I don't inizialize the generator, wait part and skip part are useless
- if wait:
- # Let's sleep...
- wait = mainClass.wait(wait_number)
- if wait:
- continue
+ mainClass.setParameters(imageName, timestamp, uploader) # Setting the image for the main class
# Skip block
if skip == True:
skip = mainClass.skipImages(skip_number, limit)
Bugs item #2136828, was opened at 2008-09-29 23:10
Message generated for change (Comment added) made by nicdumz
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=603138&aid=2136828&group_…
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: None
Group: None
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: ulana merops (spacebirdy)
Assigned to: Nobody/Anonymous (nobody)
Summary: wiktionary_family.py - wrong sort order for fr.wikt.
Initial Comment:
Please see http://fr.wiktionary.org/wiki/Discussion_Wiktionnaire:Structure_des_article…
and remove 'fr': self.alphabetic,
in line 416
Syntax on fr.wikt:
http://fr.wiktionary.org/wiki/Wiktionnaire:Structure_des_articles#Liens_int…
I don't know who added this here but it seems wrong, thanks
----------------------------------------------------------------------
Comment By: NicDumZ Nicolas Dumazet (nicdumz)
Date: 2008-10-20 06:16
Message:
I really don't understand that request ; that line has always been here,
and used as a convention for all pywikipedia bot running on fr.wikt
I left a note, in French, on the project page.
----------------------------------------------------------------------
Comment By: ulana merops (spacebirdy)
Date: 2008-10-11 16:02
Message:
Please, I would like to update the bot normally without having to remove
that line all the time, thanks in advance.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=603138&aid=2136828&group_…
Bugs item #2164505, was opened at 2008-10-13 22:55
Message generated for change (Comment added) made by nicdumz
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=603138&aid=2164505&group_…
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: None
Group: None
Status: Open
Resolution: None
Priority: 7
Private: No
Submitted By: Purodha B Blissenbach (purodha)
Assigned to: Nobody/Anonymous (nobody)
Summary: interwiki.py deletes comment lines
Initial Comment:
interwiki.py removes comment lines which should remain where they are, see http://nn.wikipedia.org/w/index.php?title=Kategori%3AAfghanistan&diff=75132…
AndersL of the Nynorsk Wikipedia tells that, there were multiple such sinstances, see
http://ksh.wikipedia.org/w/index.php?title=Metmaacher_Klaaf%3APurodha&diff=…
The program version of the above sample was of that day, or the day before. I am updating the program for Purbo T daily from svn.
----------------------------------------------------------------------
Comment By: NicDumZ Nicolas Dumazet (nicdumz)
Date: 2008-10-20 05:41
Message:
I have tried to track the bug ; attached is my attempt to reproduce it, on
the exact same page.
Somehow I cannot reproduce it... Am I missing something here ?
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=603138&aid=2164505&group_…