Revision: 6492
Author: nicdumz
Date: 2009-03-07 04:32:00 +0000 (Sat, 07 Mar 2009)
Log Message:
-----------
Finally understanding the power of decorators =]
Turning pywikibot.deprecated into a clean decorator instead of using call stack !!
Modified Paths:
--------------
branches/rewrite/pywikibot/__init__.py
branches/rewrite/pywikibot/family.py
branches/rewrite/pywikibot/page.py
branches/rewrite/pywikibot/site.py
Modified: branches/rewrite/pywikibot/__init__.py
===================================================================
--- branches/rewrite/pywikibot/__init__.py 2009-03-06 10:41:37 UTC (rev 6491)
+++ branches/rewrite/pywikibot/__init__.py 2009-03-07 04:32:00 UTC (rev 6492)
@@ -29,16 +29,21 @@
@param instead: if provided, will be used to specify the replacement
@type instead: string
"""
- f = sys._getframe(1)
- classname = f.f_locals['self'].__class__.__name__
- funcname = f.f_code.co_name
- if instead:
- output(u"%s.%s is DEPRECATED, use %s instead."
- % (classname, funcname, instead),
- level=WARNING)
- else:
- output(u"%s.%s is DEPRECATED." % (classname, funcname),
- level=WARNING)
+ def decorator(method):
+ def wrapper(*args, **kwargs):
+ funcname = method.func_name
+ classname = args[0].__class__.__name__
+ if instead:
+ output(u"%s.%s is DEPRECATED, use %s instead."
+ % (classname, funcname, instead),
+ level=WARNING)
+ else:
+ output(u"%s.%s is DEPRECATED." % (classname, funcname),
+ level=WARNING)
+ return method(*args, **kwargs)
+ wrapper.func_name = method.func_name
+ return wrapper
+ return decorator
def deprecate_arg(old_arg, new_arg):
"""Decorator to declare old_arg deprecated and replace it with
new_arg"""
Modified: branches/rewrite/pywikibot/family.py
===================================================================
--- branches/rewrite/pywikibot/family.py 2009-03-06 10:41:37 UTC (rev 6491)
+++ branches/rewrite/pywikibot/family.py 2009-03-07 04:32:00 UTC (rev 6492)
@@ -1004,11 +1004,11 @@
"""Return the shared image repository, if any."""
return (None, None)
+ @pywikibot.deprecated("Site.getcurrenttime()")
def server_time(self, code):
"""
DEPRECATED, use Site.getcurrenttime() instead
Return a datetime object representing server time"""
- pywikibot.deprecated("Site.getcurrenttime()")
return pywikibot.Site(code, self).getcurrenttime()
def isPublic(self, code):
Modified: branches/rewrite/pywikibot/page.py
===================================================================
--- branches/rewrite/pywikibot/page.py 2009-03-06 10:41:37 UTC (rev 6491)
+++ branches/rewrite/pywikibot/page.py 2009-03-07 04:32:00 UTC (rev 6492)
@@ -1223,40 +1223,40 @@
######## DEPRECATED METHODS ########
+ @deprecated("Site.encoding()")
def encoding(self):
"""DEPRECATED: use Site.encoding() instead"""
- deprecated("Site.encoding()")
return self.site().encoding()
+ @deprecated("Page.title(withNamespace=False)")
def titleWithoutNamespace(self, underscore=False):
"""DEPRECATED: use self.title(withNamespace=False)
instead."""
- deprecated("Page.title(withNamespace=False)")
return self.title(underscore=underscore, withNamespace=False,
withSection=False)
+ @deprecated("Page.title(as_filename=True)")
def titleForFilename(self):
"""DEPRECATED: use self.title(as_filename=True)
instead."""
- deprecated("Page.title(as_filename=True)")
return self.title(as_filename=True)
+ @deprecated("Page.title(withSection=False)")
def sectionFreeTitle(self, underscore=False):
"""DEPRECATED: use self.title(withSection=False)
instead."""
- deprecated("Page.title(withSection=False)")
return self.title(underscore=underscore, withSection=False)
+ @deprecated("Page.title(asLink=True)")
def aslink(self, forceInterwiki=False, textlink=False, noInterwiki=False):
"""DEPRECATED: use self.title(asLink=True)
instead."""
- deprecated("Page.title(asLink=True)")
return self.title(asLink=True, forceInterwiki=forceInterwiki,
allowInterwiki=not noInterwiki, textlink=textlink)
+ @deprecated("Page.title(asUrl=True)")
def urlname(self):
"""Return the Page title encoded for use in an URL.
DEPRECATED: use self.title(asUrl=True) instead.
"""
- deprecated("Page.title(asUrl=True)")
return self.title(asUrl=True)
####### DISABLED METHODS (warnings provided) ######
@@ -1331,9 +1331,9 @@
u'http://wikitravel.org/upload/shared/')
return self.fileIsOnCommons()
+ @deprecated("ImagePage.getFileSHA1Sum()")
def getFileMd5Sum(self):
"""Return image file's MD5 checksum."""
- deprecated("ImagePage.getFileSHA1Sum()")
# FIXME: MD5 might be performed on incomplete file due to server disconnection
# (see bug #1795683).
import md5, urllib
@@ -1567,24 +1567,24 @@
return True
#### DEPRECATED METHODS ####
+ @deprecated("list(Category.subcategories(...))")
def subcategoriesList(self, recurse=False):
"""DEPRECATED: Equivalent to
list(self.subcategories(...))"""
- deprecated("list(Category.subcategories(...))")
return sorted(list(set(self.subcategories(recurse))))
+ @deprecated("list(Category.articles(...))")
def articlesList(self, recurse=False):
"""DEPRECATED: equivalent to
list(self.articles(...))"""
- deprecated("list(Category.articles(...))")
return sorted(list(set(self.articles(recurse))))
+ @deprecated("Category.categories()")
def supercategories(self):
"""DEPRECATED: equivalent to self.categories()"""
- deprecated("Category.categories()")
return self.categories()
+ @deprecated("list(Category.categories(...))")
def supercategoriesList(self):
"""DEPRECATED: equivalent to
list(self.categories(...))"""
- deprecated("list(Category.categories(...))")
return sorted(list(set(self.categories())))
Modified: branches/rewrite/pywikibot/site.py
===================================================================
--- branches/rewrite/pywikibot/site.py 2009-03-06 10:41:37 UTC (rev 6491)
+++ branches/rewrite/pywikibot/site.py 2009-03-07 04:32:00 UTC (rev 6492)
@@ -308,13 +308,13 @@
% {'site': self})
return pywikibot.Category(pywikibot.Link(name, self))
+ @deprecated("pywikibot.Link")
def linkto(self, title, othersite = None):
"""Return unicode string in the form of a wikilink to
'title'
Use optional Site argument 'othersite' to generate an interwiki link.
"""
- deprecated("pywikibot.Link")
return pywikibot.Link(title, self).astext(othersite)
def isInterwikiLink(self, s):
@@ -407,16 +407,17 @@
# deprecated methods for backwards-compatibility
+ @deprecated("family attribute")
def fam(self):
"""Return Family object for this Site."""
- deprecated("family attribute")
return self.family
+ @deprecated("urllib.urlencode()")
def urlEncode(self, query):
"""DEPRECATED"""
- deprecated("urllib.urlencode()")
return urllib.urlencode(query)
+ @deprecated("pywikibot.comms.http.request")
def getUrl(self, path, retry=True, sysop=False, data=None,
compress=True, no_hostname=False, cookie_only=False):
"""DEPRECATED.
@@ -425,7 +426,6 @@
are ignored.
"""
- deprecated("pywikibot.comms.http.request")
from pywikibot.comms import http
if data:
if not isinstance(data, basestring):
@@ -434,15 +434,15 @@
else:
return http.request(self, path)
+ @deprecated()
def postForm(self, address, predata, sysop=False, cookies=None):
"""DEPRECATED"""
- deprecated()
return self.getUrl(address, data=predata)
+ @deprecated()
def postData(self, address, data, contentType=None, sysop=False,
compress=True, cookies=None):
"""DEPRECATED"""
- deprecated()
return self.getUrl(address, data=data)
# unsupported methods from version 1
@@ -635,13 +635,13 @@
return False
return (not sysop) or 'sysop' in self.userinfo['groups']
+ @deprecated("Site.user()")
def loggedInAs(self, sysop = False):
"""Return the current username if logged in, otherwise return
None.
DEPRECATED (use .user() method instead)
"""
- deprecated("Site.user()")
return self.logged_in(sysop) and self.user()
def login(self, sysop=False):
@@ -733,9 +733,9 @@
self.login(sysop)
return right.lower() in self._userinfo['rights']
+ @deprecated("Site.has_right()")
def isAllowed(self, right, sysop=False):
"""Deprecated; retained for
backwards-compatibility"""
- deprecated("Site.has_right()")
return self.has_right(right, sysop)
def has_group(self, group, sysop=False):
@@ -1487,13 +1487,13 @@
apgen.request["gapdir"] = "descending"
return apgen
+ @deprecated("Site.allpages()")
def prefixindex(self, prefix, namespace=0, includeredirects=True):
"""Yield all pages with a given prefix. Deprecated.
Use allpages() with the prefix= parameter instead of this method.
"""
- deprecated("Site.allpages()")
return self.allpages(prefix=prefix, namespace=namespace,
includeredirects=includeredirects)
@@ -1565,9 +1565,9 @@
acgen.request["gacdir"] = "descending"
return acgen
+ @deprecated("Site.allcategories()")
def categories(self, number=10, repeat=False):
"""Deprecated; retained for
backwards-compatibility"""
- deprecated("Site.allcategories()")
if repeat:
limit = None
else: