jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/538369 )

Change subject: [bugfix] Fix method call for assert_valid_iter_param
......................................................................

[bugfix] Fix method call for assert_valid_iter_param

- Also revide assert_valid_iter_params test method because the required
  start/end order depends on the content. For timestamp values the start
  must be later than end whereas for titles the start value must be less
  than end.
- Instead of raising a pywikibot.Error it raises an AssertionError if
  the order is wrong. This sounds like a breaking change but
  assert_valid_iter_params should break the script anyway if the values
  are wrong.
- Add need_version 1.17 for filearchive method

Bug: T233476
Change-Id: I25ed6568bc1bbe3c09f4471061c533080c345a89
---
M pywikibot/site.py
1 file changed, 31 insertions(+), 12 deletions(-)

Approvals:
  Mpaa: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/pywikibot/site.py b/pywikibot/site.py
index 48ccbb5..1889462 100644
--- a/pywikibot/site.py
+++ b/pywikibot/site.py
@@ -21,6 +21,7 @@
 import mimetypes
 import os
 import re
+from textwrap import fill
 import threading
 import time
 import uuid
@@ -2270,16 +2271,33 @@
             'articlepath must end with /$1'
         return self.siteinfo['general']['articlepath'][:-2]

-    def assert_valid_iter_params(self, msg_prefix, start, end, reverse):
-        """Validate iterating API parameters."""
-        if reverse:
-            if end < start:
-                raise Error(msg_prefix
-                            + ': end must be later than start'
-                              ' with reverse=True')
-        elif start < end:
-            raise Error(msg_prefix
-                        + ': start must be later than end with reverse=False')
+    def assert_valid_iter_params(self, msg_prefix, start, end, reverse,
+                                 is_ts=True):
+        """Validate iterating API parameters.
+
+        @param msg_prefix: The calling method name
+        @type msg_prefix: str
+        @param start: The start value to compare
+        @param end: The end value to compare
+        @param reverse: The reverse option
+        @type reverse: bool
+        @param is_ts: When comparing timestamps (with is_ts=True) the start
+            is usually greater than end. Comparing titles this is vice versa.
+        type is_ts: bool
+        @raises AssertionError: start/end values are in wrong order
+        """
+        if reverse ^ is_ts:
+            low, high = end, start
+            order = 'follow'
+        else:
+            low, high = start, end
+            order = 'precede'
+        msg = ('{method}: "start" must {order} "end" '
+               'with reverse={reverse} and is_ts={is_ts} '
+               'but "start" is "{start}" and "end" is "{end}".')
+        assert low < high, fill(msg.format(method=msg_prefix, order=order,
+                                           start=start, end=end,
+                                           reverse=reverse, is_ts=is_ts))

     def has_right(self, right, sysop=False):
         """Return true if and only if the user has a specific right.
@@ -4470,6 +4488,7 @@
             aigen.request['gaisha1base36'] = sha1base36
         return aigen

+    @need_version('1.17')
     @deprecated_args(limit='total')  # ignore falimit setting
     def filearchive(self, start=None, end=None, reverse=False, total=None,
                     **kwargs):
@@ -4489,8 +4508,8 @@
         @keyword prop: Image information to get. Default is timestamp
         """
         if start and end:
-            self.assert_valid_iter_params(self, 'filearchive', start, end,
-                                          reverse)
+            self.assert_valid_iter_params(
+                'filearchive', start, end, reverse, is_ts=False)
         fagen = self._generator(api.ListGenerator,
                                 type_arg='filearchive',
                                 fafrom=start,

--
To view, visit https://gerrit.wikimedia.org/r/538369
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.wikimedia.org/r/settings

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I25ed6568bc1bbe3c09f4471061c533080c345a89
Gerrit-Change-Number: 538369
Gerrit-PatchSet: 5
Gerrit-Owner: Xqt <[email protected]>
Gerrit-Reviewer: Mpaa <[email protected]>
Gerrit-Reviewer: Multichill <[email protected]>
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: jenkins-bot (75)
_______________________________________________
Pywikibot-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/pywikibot-commits

Reply via email to