http://www.mediawiki.org/wiki/Special:Code/pywikipedia/11259
Revision: 11259
Author: legoktm
Date: 2013-03-25 07:29:54 +0000 (Mon, 25 Mar 2013)
Log Message:
-----------
PEP8 fixes
Modified Paths:
--------------
branches/rewrite/pywikibot/exceptions.py
Modified: branches/rewrite/pywikibot/exceptions.py
===================================================================
--- branches/rewrite/pywikibot/exceptions.py 2013-03-25 07:17:53 UTC (rev 11258)
+++ branches/rewrite/pywikibot/exceptions.py 2013-03-25 07:29:54 UTC (rev 11259)
@@ -15,6 +15,7 @@
# TODO: These are copied from wikipedia.py; not certain that all of them
# will be needed in the rewrite.
+
class Error(Exception):
"""Wikipedia error"""
def __init__(self, arg):
@@ -23,11 +24,14 @@
self.string = arg.encode(config.console_encoding, "xmlcharrefreplace")
except (AttributeError, TypeError):
self.string = arg.encode("ascii", "xmlcharrefreplace")
+
def __str__(self):
return self.string
+
def __unicode__(self):
return self.unicode
+
class PageRelatedError(Error):
"""Abstract Exception, used when the Exception concerns a particular
Page, and when a generic message can be written once for all"""
@@ -35,6 +39,7 @@
# Override this in subclasses.
# u"Oh noes! Page %s is too funky, we should not delete it ;("
message = None
+
def __init__(self, page):
"""
@param page
@@ -48,24 +53,30 @@
def getPage(self):
return self._page
+
class NoUsername(Error):
"""Username is not in user-config.py"""
+
class NoPage(PageRelatedError):
"""Page does not exist"""
message = u"Page %s doesn't exist."
+
class NoSuchSite(Error):
"""Site does not exist"""
+
class IsRedirectPage(PageRelatedError):
"""Page is a redirect page"""
message = u"Page %s is a redirect page."
+
class IsNotRedirectPage(PageRelatedError):
"""Page is not a redirect page"""
message = u"Page %s is not a redirect page."
+
class CircularRedirect(Error):
"""Page is a circular redirect
@@ -75,22 +86,28 @@
"""
+
class InvalidTitle(Error):
"""Invalid page title"""
+
class LockedPage(PageRelatedError):
"""Page is locked"""
message = u"Page %s is locked."
+
class SectionError(Error):
"""The section specified by # does not exist"""
+
class PageNotSaved(Error):
"""Saving the page has failed"""
+
class EditConflict(PageNotSaved):
"""There has been an edit conflict while uploading the page"""
+
class SpamfilterError(PageNotSaved):
"""Saving the page has failed because the MediaWiki spam filter detected a blacklisted URL."""
def __init__(self, arg):
@@ -98,35 +115,46 @@
self.url = arg
self.args = arg,
+
class ServerError(Error):
"""Got unexpected server response"""
+
class Server504Error(Error):
"""Server timed out with http 504 code"""
+
class BadTitle(Error):
"""Server responded with BadTitle."""
# UserBlocked exceptions should in general not be caught. If the bot has
# been blocked, the bot operator should address the reason for the block
# before continuing.
+
+
class UserBlocked(Error):
"""Your username or IP has been blocked"""
+
class PageNotFound(Error):
"""Page not found in list"""
+
class CaptchaError(Error):
"""Captcha is asked and config.solve_captcha == False."""
+
class UploadWarning(Error):
"""Upload failed with a warning message (passed as the argument)."""
+
class AutoblockUser(Error):
"""
The class AutoblockUserError is an exception that is raised whenever
an action is requested on a virtual autoblock user that's not available
for him (i.e. roughly everything except unblock).
"""
+
+
class UserActionRefuse(Error):
pass
http://www.mediawiki.org/wiki/Special:Code/pywikipedia/11255
Revision: 11255
Author: xqt
Date: 2013-03-24 17:28:53 +0000 (Sun, 24 Mar 2013)
Log Message:
-----------
* use default user from config file for _sites cache (update from rewrite r5088), follow up for r11247, r11070
* remove old deprecate_arg warning for "persistent_http" (> 1 year)
Modified Paths:
--------------
trunk/pywikipedia/wikipedia.py
Modified: trunk/pywikipedia/wikipedia.py
===================================================================
--- trunk/pywikipedia/wikipedia.py 2013-03-24 17:19:45 UTC (rev 11254)
+++ trunk/pywikipedia/wikipedia.py 2013-03-24 17:28:53 UTC (rev 11255)
@@ -8715,20 +8715,26 @@
_sites = {}
_namespaceCache = {}
-@deprecate_arg("persistent_http", None)
+
def getSite(code=None, fam=None, user=None, noLogin=False):
if code is None:
code = default_code
if fam is None:
fam = default_family
+ if user is None:
+ try:
+ user = config.usernames[fam][code]
+ except KeyError:
+ user = None
key = '%s:%s:%s' % (fam, code, user)
- if key not in _sites:
+ if not key in _sites:
_sites[key] = Site(code=code, fam=fam, user=user)
ret = _sites[key]
if not ret.family.isPublic(code) and not noLogin:
ret.forceLogin()
return ret
+
def setSite(site):
global default_code, default_family
default_code = site.language()