John Vandenberg has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/142897

Change subject: Major pyflakes in pywikibot/
......................................................................

Major pyflakes in pywikibot/

- site contains two newimages(), the latter one of which was broken.
- site.protect added unused errdata values.
- method cap_answerwikipedia does not exist.
- sys._getframe exists for py 2.1+, which is above minimum supported
  version.
- compat/ - use __all__ to specify the unused symbols are for export.

Change-Id: Ia0010c878881e30822db6d7e928534ce15670584
---
M pywikibot/bot.py
M pywikibot/compat/catlib.py
M pywikibot/compat/userlib.py
M pywikibot/logentries.py
M pywikibot/site.py
5 files changed, 21 insertions(+), 38 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core 
refs/changes/97/142897/1

diff --git a/pywikibot/bot.py b/pywikibot/bot.py
index a98eba8..6ca5c0d 100644
--- a/pywikibot/bot.py
+++ b/pywikibot/bot.py
@@ -318,20 +318,11 @@
 # string indicating the debugging layer.
 
 # next bit filched from 1.5.2's inspect.py
-def currentframe():
-    """Return the frame object for the caller's stack frame."""
-    try:
-        raise Exception
-    except:
-        # go back two levels, one for logoutput and one for whatever called it
-        return sys.exc_traceback.tb_frame.f_back.f_back
 
-if hasattr(sys, '_getframe'):
-    # less portable but more efficient
-    currentframe = lambda: sys._getframe(3)
-    # frame0 is this lambda, frame1 is logoutput() in this module,
-    # frame2 is the convenience function (output(), etc.)
-    # so frame3 is whatever called the convenience function
+_currentframe = lambda: sys._getframe(3)
+# frame0 is this lambda, frame1 is logoutput() in this module,
+# frame2 is the convenience function (output(), etc.)
+# so frame3 is whatever called the convenience function
 
 # done filching
 
@@ -352,7 +343,7 @@
     if not _handlers_initialized:
         init_handlers()
 
-    frame = currentframe()
+    frame = _currentframe()
     module = os.path.basename(frame.f_code.co_filename)
     context = {'caller_name': frame.f_code.co_name,
                'caller_file': module,
diff --git a/pywikibot/compat/catlib.py b/pywikibot/compat/catlib.py
index a3ed406..27940ff 100644
--- a/pywikibot/compat/catlib.py
+++ b/pywikibot/compat/catlib.py
@@ -20,3 +20,5 @@
 def change_category(article, oldCat, newCat, comment=None, sortKey=None,
                     inPlace=True):
     return article.change_category(oldCat, newCat, comment, sortKey, inPlace)
+
+__all__ = ['Category', 'change_category']
diff --git a/pywikibot/compat/userlib.py b/pywikibot/compat/userlib.py
index 6d90419..348b059 100644
--- a/pywikibot/compat/userlib.py
+++ b/pywikibot/compat/userlib.py
@@ -15,3 +15,5 @@
 
 
 from pywikibot import User
+
+__all__ = ['User']
diff --git a/pywikibot/logentries.py b/pywikibot/logentries.py
index be6d08b..d0e753f 100644
--- a/pywikibot/logentries.py
+++ b/pywikibot/logentries.py
@@ -10,7 +10,7 @@
 __version__ = '$Id$'
 #
 
-from pywikibot.exceptions import *
+from pywikibot.exceptions import Error
 import pywikibot
 
 _logger = "wiki"
diff --git a/pywikibot/site.py b/pywikibot/site.py
index 3b4d817..3e41b8b 100644
--- a/pywikibot/site.py
+++ b/pywikibot/site.py
@@ -29,7 +29,8 @@
 from pywikibot import deprecated
 from pywikibot.throttle import Throttle
 from pywikibot.data import api
-from pywikibot.exceptions import *
+from pywikibot.exceptions import Error, LockedPage, NoSuchSite, SpamfilterError
+from pywikibot.exceptions import UserBlocked, NoUsername, NoPage, EditConflict
 
 if sys.version_info[0] > 2:
     basestring = (str,)
@@ -2886,7 +2887,7 @@
                                         % (self.protocol(),
                                            self.hostname(),
                                            captcha["url"]))
-                        req['captchaword'] = cap_answerwikipedia.input(
+                        req['captchaword'] = pywikibot.input(
                             "Please view CAPTCHA in your browser, "
                             "then type answer here:")
                         continue
@@ -3145,10 +3146,7 @@
         except api.APIError as err:
             errdata = {
                 'site': self,
-                'title': page.title(withSection=False),
                 'user': self.user(),
-                'level-edit': edit,
-                'level-move': move
             }
             if err.code in self._protect_errors:
                 raise Error(self._protect_errors[err.code] % errdata)
@@ -3247,16 +3245,6 @@
     def linksearch(self, siteurl, limit=None):
         """Backwards-compatible interface to exturlusage()"""
         return self.exturlusage(siteurl, total=limit)
-
-    @deprecated('Site().logevents(logtype="upload",...)')
-    @deprecate_arg("repeat", None)
-    def newimages(self, number=100, lestart=None, leend=None, leuser=None,
-                  letitle=None):
-        """Yield ImagePages from most recent uploads"""
-        if isinstance(letitle, basestring):
-            letitle = pywikibot.Page(pywikibot.Link(letitle))
-        return self.logevents(logtype="upload", total=number, start=lestart,
-                              end=leend, user=leuser, page=letitle)
 
     def getFilesFromAnHash(self, hash_found=None):
         """Return all images that have the same hash.
@@ -3404,7 +3392,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,
@@ -3433,13 +3420,14 @@
 
         """
         # TODO: update docstring
-        for event in logevents(self, logtype="upload", user=user,
-                               start=start, end=end, reverse=reverse,
-                               step=step, total=total):
-            image = pywikibot.ImagePage(self, event['title'])
-            date = pywikibot.Timestamp.fromISOformat(event['timestamp'])
-            user = event['user']
-            comment = event['comment'] or u''
+        for event in self.logevents(logtype="upload", user=user,
+                                    start=start, end=end, reverse=reverse,
+                                    step=step, total=total):
+            # event.title() actually returns a Page
+            image = pywikibot.ImagePage(event.title())
+            date = event.timestamp()
+            user = event.user()
+            comment = event.comment() or u''
             yield (image, date, user, comment)
 
     @deprecate_arg("number", None)

-- 
To view, visit https://gerrit.wikimedia.org/r/142897
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia0010c878881e30822db6d7e928534ce15670584
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: John Vandenberg <jay...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to