jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/655892 )
Change subject: [IMPR] Use need_right decorator to check required user right
......................................................................
[IMPR] Use need_right decorator to check required user right
Change-Id: Ic8da5864e365b8bc59d9432542c25a4cebbe8baf
---
M pywikibot/site/__init__.py
1 file changed, 1 insertion(+), 5 deletions(-)
Approvals:
Mpaa: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/site/__init__.py b/pywikibot/site/__init__.py
index 348f34d..2cc9d63 100644
--- a/pywikibot/site/__init__.py
+++ b/pywikibot/site/__init__.py
@@ -4357,6 +4357,7 @@
return req.submit()['query']['stashimageinfo'][0]
@deprecate_arg('imagepage', 'filepage')
+ @need_right('upload')
def upload(self, filepage, source_filename=None, source_url=None,
comment=None, text=None, watch=False, ignore_warnings=False,
chunk_size: int = 0, _file_key: Optional[str] = None,
@@ -4448,11 +4449,6 @@
# An offset != 0 doesn't make sense without a file key
assert(_offset == 0 or _file_key is not None)
- # check for required user right
- if not self.has_right('upload'):
- raise Error(
- "User '%s' does not have upload rights on site %s."
- % (self.user(), self))
# check for required parameters
if bool(source_filename) == bool(source_url):
raise ValueError('APISite.upload: must provide either '
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/655892
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: Ic8da5864e365b8bc59d9432542c25a4cebbe8baf
Gerrit-Change-Number: 655892
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Mpaa <mpaa.wiki(a)gmail.com>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/655868 )
Change subject: [cleanup] remove Page methods deprecated for 6 years
......................................................................
[cleanup] remove Page methods deprecated for 6 years
Remove deprecated methods and properties:
- latestRevision
- pageAPInfo
- previous_revision_id
- previousRevision
- isEmpty()
- isFlowPage
Change-Id: I264235b21a97748ed363436a25a061b2108318dd
---
M pywikibot/page/__init__.py
M tests/page_tests.py
2 files changed, 3 insertions(+), 60 deletions(-)
Approvals:
Mpaa: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/page/__init__.py b/pywikibot/page/__init__.py
index b4d259f..3dc9015 100644
--- a/pywikibot/page/__init__.py
+++ b/pywikibot/page/__init__.py
@@ -11,7 +11,7 @@
"""
#
-# (C) Pywikibot team, 2008-2020
+# (C) Pywikibot team, 2008-2021
#
# Distributed under the terms of the MIT license.
#
@@ -581,18 +581,6 @@
del self.latest_revision_id
self._revid = value
- @deprecated('latest_revision_id', since='20150727', future_warning=True)
- def latestRevision(self): # pragma: no cover
- """Return the current revision id for this page."""
- return self.latest_revision_id
-
- @deprecated('latest_revision_id', since='20150407', future_warning=True)
- def pageAPInfo(self): # pragma: no cover
- """Return the current revision id for this page."""
- if self.isRedirectPage():
- raise pywikibot.IsRedirectPage(self)
- return self.latest_revision_id
-
@property
def latest_revision(self):
"""Return the current revision for this page."""
@@ -740,27 +728,6 @@
"""
return self.latest_revision.timestamp
- @property
- @deprecated('latest_revision.parent_id (0 instead of -1 when no parent)',
- since='20150609', future_warning=True)
- def previous_revision_id(self) -> int: # pragma: no cover
- """
- Return the revision id for the previous revision of this Page.
-
- If the page has only one revision, it shall return -1.
- """
- return self.latest_revision.parent_id or -1
-
- @deprecated('latest_revision.parent_id (0 instead of -1 when no parent)',
- since='20150609', future_warning=True)
- def previousRevision(self) -> int: # pragma: no cover
- """
- Return the revision id for the previous revision.
-
- DEPRECATED: Use latest_revision.parent_id instead.
- """
- return self.latest_revision.parent_id or -1
-
def exists(self) -> bool:
"""Return True if page exists on the wiki, even if it's a redirect.
@@ -837,19 +804,6 @@
return Category(Link(self._catredirect, self.site))
raise pywikibot.IsNotRedirectPage(self)
- @deprecated(since='20151207', future_warning=True)
- def isEmpty(self) -> bool: # pragma: no cover
- """
- Return True if the page text has less than 4 characters.
-
- Character count ignores language links and category links.
- Can raise the same exceptions as get().
- """
- txt = self.get()
- txt = textlib.removeLanguageLinks(txt, site=self.site)
- txt = textlib.removeCategoryLinks(txt, site=self.site)
- return len(txt) < 4
-
def isTalkPage(self):
"""Return True if this page is in any talk namespace."""
ns = self.namespace()
@@ -2095,11 +2049,6 @@
'required.' % self.title(as_link=True))
return False
- @deprecated('Page.is_flow_page()', since='20150128', future_warning=True)
- def isFlowPage(self): # pragma: no cover
- """DEPRECATED: use self.is_flow_page instead."""
- return self.is_flow_page()
-
def is_flow_page(self) -> bool:
"""Whether a page is a Flow page."""
return self.content_model == 'flow-board'
diff --git a/tests/page_tests.py b/tests/page_tests.py
index 1bc7743..b98782b 100644
--- a/tests/page_tests.py
+++ b/tests/page_tests.py
@@ -1,7 +1,6 @@
-# -*- coding: utf-8 -*-
"""Tests for the page module."""
#
-# (C) Pywikibot team, 2008-2020
+# (C) Pywikibot team, 2008-2021
#
# Distributed under the terms of the MIT license.
#
@@ -14,7 +13,6 @@
import pywikibot.page
from pywikibot import config, InvalidTitle
-from pywikibot.tools import suppress_warnings
from tests.aspects import (
DefaultDrySiteTestCase, DefaultSiteTestCase, SiteAttributeTestCase,
@@ -442,11 +440,7 @@
# since there is no way to predict what data the wiki will return,
# we only check that the returned objects are of correct type.
self.assertIsInstance(mainpage.get(), str)
- with suppress_warnings(
- r'pywikibot\.page\.BasePage\.latestRevision '
- r'is deprecated[\s\w]+; '
- r'use latest_revision_id instead\.'):
- self.assertIsInstance(mainpage.latestRevision(), int)
+ self.assertIsInstance(mainpage.latest_revision_id, int)
self.assertIsInstance(mainpage.userName(), str)
self.assertIsInstance(mainpage.isIpEdit(), bool)
self.assertIsInstance(mainpage.exists(), bool)
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/655868
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I264235b21a97748ed363436a25a061b2108318dd
Gerrit-Change-Number: 655868
Gerrit-PatchSet: 3
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Mpaa <mpaa.wiki(a)gmail.com>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/655878 )
Change subject: Don't print a FutureWarning until T271899 is solved
......................................................................
Don't print a FutureWarning until T271899 is solved
Following the Deprecation/FutureWarning in APISite.upload() will
raise a ValueError if ignore_warnings is boolean and report_success
is set by default. Therefore don't show a FutureWarning anymore until
T271899 has been solved finally.
Bug: T271899
Change-Id: I8c17f44e910ab2399a5ad1daf4c1203fd994ac8b
---
M pywikibot/site/__init__.py
1 file changed, 1 insertion(+), 2 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/site/__init__.py b/pywikibot/site/__init__.py
index 348f34d..86394f6 100644
--- a/pywikibot/site/__init__.py
+++ b/pywikibot/site/__init__.py
@@ -4472,8 +4472,7 @@
'"report_success" is True or None',
'"report_success=False" or define '
'"ignore_warnings" as callable/iterable',
- 3, warning_class=FutureWarning,
- since='20150823')
+ 3, since='20150823')
if isinstance(ignore_warnings, Iterable):
ignored_warnings = ignore_warnings
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/655878
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I8c17f44e910ab2399a5ad1daf4c1203fd994ac8b
Gerrit-Change-Number: 655878
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/584919 )
Change subject: [IMPR] Create a Site with AutoFamily if a family isn't predefined
......................................................................
[IMPR] Create a Site with AutoFamily if a family isn't predefined
This enables Site.interwiki() to create a Site object even the
corresponding family file isn't predefined. Now the known_families
dict and get_known_families method in Family object can be replaced
as suggested because the Site object is created instead of raising
SiteDefinitionError.
- If a family is not predefined in family folder use AutoFamily to
create the family within _code_fam_from_url.
- A new parameter "name" is used for the family name. Create the
family name from url if name isn't given.
- Store prefix in IWEntry that it can be reused for AutoFamily
name.
Bug: T249087
Change-Id: Ic7fb876570a15a5808b5fd56cafa5c3335013955
---
M pywikibot/__init__.py
M pywikibot/site/_interwikimap.py
2 files changed, 20 insertions(+), 14 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/__init__.py b/pywikibot/__init__.py
index b2dc8ff..5b60012 100644
--- a/pywikibot/__init__.py
+++ b/pywikibot/__init__.py
@@ -16,6 +16,7 @@
from decimal import Decimal
from queue import Queue
from typing import Optional, Union
+from urllib.parse import urlparse
from warnings import warn
from pywikibot.__metadata__ import (
@@ -23,7 +24,7 @@
__maintainer__, __maintainer_email__, __name__, __url__, __version__)
from pywikibot._wbtypes import WbRepresentation as _WbRepresentation
-from pywikibot.backports import cache
+from pywikibot.backports import cache, removesuffix
from pywikibot.bot import (
input, input_choice, input_yn, handle_args, show_help, ui,
calledModuleName, Bot, CurrentPageBot, WikidataBot,
@@ -48,7 +49,7 @@
UnknownExtension, UnknownFamily, UnknownSite, UnsupportedPage,
WikiBaseError,
)
-from pywikibot.family import Family
+from pywikibot.family import AutoFamily, Family
from pywikibot.i18n import translate
from pywikibot.logging import (
critical, debug, error, exception, log, output, stdout, warning
@@ -1050,12 +1051,12 @@
@cache
-def _code_fam_from_url(url: str):
+def _code_fam_from_url(url: str, name: Optional[str] = None):
"""Set url to cache and get code and family from cache.
Site helper method.
@param url: The site URL to get code and family
- @raises pywikibot.exceptions.SiteDefinitionError: Unknown URL
+ @param name: A family name used by AutoFamily
"""
matched_sites = []
# Iterate through all families and look, which does apply to
@@ -1067,9 +1068,12 @@
matched_sites.append((code, family))
if not matched_sites:
- # TODO: As soon as AutoFamily is ready, try and use an
- # AutoFamily
- raise SiteDefinitionError("Unknown URL '{}'.".format(url))
+ if not name: # create a name from url
+ name = urlparse(url).netloc.split('.')[-2]
+ name = removesuffix(name, 'wiki')
+ family = AutoFamily(name, url)
+ matched_sites.append((family.code, family))
+
if len(matched_sites) > 1:
warning('Found multiple matches for URL "{}": {} (use first)'
.format(url, ', '.join(str(s) for s in matched_sites)))
@@ -1099,17 +1103,16 @@
URL. Still requires that the family supporting that URL exists.
@raises ValueError: URL and pair of code and family given
@raises ValueError: Invalid interface name
- @raises pywikibot.exceptions.SiteDefinitionError: Unknown URL
"""
_logger = 'wiki'
if url:
- # Either code and fam or only url
- if code or fam:
+ # Either code and fam or url with optional fam for AutoFamily name
+ if code:
raise ValueError(
'URL to the wiki OR a pair of code and family name '
'should be provided')
- code, fam = _code_fam_from_url(url)
+ code, fam = _code_fam_from_url(url, fam)
elif code and ':' in code:
if fam:
raise ValueError(
diff --git a/pywikibot/site/_interwikimap.py b/pywikibot/site/_interwikimap.py
index 2f18e54..ea894b0 100644
--- a/pywikibot/site/_interwikimap.py
+++ b/pywikibot/site/_interwikimap.py
@@ -12,7 +12,7 @@
"""An entry of the _InterwikiMap with a lazy loading site."""
- def __init__(self, local, url):
+ def __init__(self, local, url, prefix=None):
self._site = None
self.local = local
self.url = url
@@ -21,7 +21,8 @@
def site(self):
if self._site is None:
try:
- self._site = pywikibot.Site(url=self.url)
+ self._site = pywikibot.Site(
+ url=self.url, fam=None if self.local else self.prefix)
except Exception as e:
self._site = e
return self._site
@@ -52,7 +53,9 @@
# _iw_sites is a local cache to return an APISite instance depending
# on the interwiki prefix of that site
if self._map is None:
- self._map = {iw['prefix']: _IWEntry('local' in iw, iw['url'])
+ self._map = {iw['prefix']: _IWEntry('local' in iw,
+ iw['url'],
+ iw['prefix'])
for iw in self._site.siteinfo['interwikimap']}
return self._map
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/584919
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: Ic7fb876570a15a5808b5fd56cafa5c3335013955
Gerrit-Change-Number: 584919
Gerrit-PatchSet: 8
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Mpaa <mpaa.wiki(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/654869 )
Change subject: [IMPR] Avoid deeply nested flow statements in redirect.py
......................................................................
[IMPR] Avoid deeply nested flow statements in redirect.py
Change-Id: I9b1cc85262630c59b5f1726bac839be65878352e
---
M scripts/redirect.py
1 file changed, 24 insertions(+), 30 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/redirect.py b/scripts/redirect.py
index 9b07caf..80fa4de 100755
--- a/scripts/redirect.py
+++ b/scripts/redirect.py
@@ -1,5 +1,4 @@
#!/usr/bin/python
-# -*- coding: utf-8 -*-
"""
Script to resolve double redirects, and to delete broken redirects.
@@ -70,7 +69,7 @@
"""
#
-# (C) Pywikibot team, 2004-2020
+# (C) Pywikibot team, 2004-2021
#
# Distributed under the terms of the MIT license.
#
@@ -256,24 +255,21 @@
for x in data['query']['redirects']}
for pagetitle in data['query']['pages'].values():
- if 'missing' in pagetitle and 'pageid' not in pagetitle:
- pages[pagetitle['title']] = False
- else:
- pages[pagetitle['title']] = True
+ pages[pagetitle['title']] = \
+ 'missing' not in pagetitle or 'pageid' in pagetitle
for redirect in redirects:
target = redirects[redirect]
- result = 0
+ result = None
final = None
- try:
- if pages[target]:
- final = target
- with suppress(KeyError):
- while result <= maxlen:
- result += 1
- final = redirects[final]
- # result = None
- except KeyError:
- result = None
+
+ if pages.get(target):
+ result = 0
+ final = target
+ with suppress(KeyError):
+ while result <= maxlen:
+ result += 1
+ final = redirects[final]
+
yield (redirect, result, target, final)
def retrieve_broken_redirects(self) -> Generator[
@@ -281,14 +277,13 @@
"""Retrieve broken redirects."""
if self.opt.fullscan:
count = 0
- for (pagetitle, type, target, final) \
- in self.get_redirects_via_api(maxlen=2):
+ for pagetitle, type, target, final in self.get_redirects_via_api(
+ maxlen=2):
if type == 0:
yield pagetitle
- if self.opt.limit:
- count += 1
- if count >= self.opt.limit:
- break
+ count += 1
+ if self.opt.limit and count >= self.opt.limit:
+ break
elif self.opt.xml:
# retrieve information from XML dump
pywikibot.output(
@@ -311,14 +306,13 @@
yield from self.get_moved_pages_redirects()
elif self.opt.fullscan:
count = 0
- for (pagetitle, type, target, final) \
- in self.get_redirects_via_api(maxlen=2):
- if type != 0 and type != 1:
+ for pagetitle, type_, target, final in self.get_redirects_via_api(
+ maxlen=2):
+ if type_ != 0 and type_ != 1:
yield pagetitle
- if self.opt.limit:
- count += 1
- if count >= self.opt.limit:
- break
+ count += 1
+ if self.opt.limit and count >= self.opt.limit:
+ break
elif self.opt.xml:
redict, _ = self.get_redirects_from_dump()
total = len(redict)
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/654869
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I9b1cc85262630c59b5f1726bac839be65878352e
Gerrit-Change-Number: 654869
Gerrit-PatchSet: 3
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: D3r1ck01 <xsavitar.wiki(a)aol.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/654468 )
Change subject: [IMPR] Use pagegenerators -page option in redirect.py
......................................................................
[IMPR] Use pagegenerators -page option in redirect.py
Bug: T100643
Change-Id: I1723b7160924d82b0529b2346389cefebc4d7ef7
---
M scripts/redirect.py
1 file changed, 7 insertions(+), 12 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/redirect.py b/scripts/redirect.py
index ef04b64..1cf0da0 100755
--- a/scripts/redirect.py
+++ b/scripts/redirect.py
@@ -39,8 +39,6 @@
If neither of -xml -fullscan -moves is given, info will be
loaded from a special page of the live wiki.
--page:title Work on a single page
-
-offset:n With -moves, the number of hours ago to start scanning moved
pages. With -xml, the number of the redirect to restart with
(see progress). Otherwise, ignored.
@@ -104,7 +102,6 @@
'moves': False,
'namespaces': {0},
'offset': -1,
- 'page': None,
'start': None,
'limit': None,
'until': None,
@@ -299,8 +296,6 @@
for (key, value) in redirs.items():
if value not in pageTitles:
yield key
- elif self.opt.page:
- yield self.opt.page
else:
pywikibot.output('Retrieving broken redirect special page...')
yield from self.site.preloadpages(self.site.broken_redirects())
@@ -330,8 +325,6 @@
pywikibot.output('\nChecking redirect {0} of {1}...'
.format(num, total))
yield key
- elif self.opt.page:
- yield self.opt.page
else:
pywikibot.output('Retrieving double redirect special page...')
yield from self.site.preloadpages(self.site.double_redirects())
@@ -693,7 +686,7 @@
source.add(arg)
elif option == 'offset':
gen_options[option] = int(value)
- elif option in ('page', 'start', 'until'):
+ elif option in ('start', 'until'):
gen_options[option] = value
elif option == 'limit':
options['limit'] = gen_options['limit'] = int(value)
@@ -713,10 +706,12 @@
pywikibot.bot.suggest_help(missing_action=True)
return
- if gen_factory.namespaces:
- gen_options['namespaces'] = gen_factory.namespaces
- gen = RedirectGenerator(action, **gen_options)
- options['generator'] = gen_factory.getCombinedGenerator(gen)
+ gen = None
+ if not gen_factory.gens:
+ if gen_factory.namespaces:
+ gen_options['namespaces'] = gen_factory.namespaces
+ gen = RedirectGenerator(action, **gen_options)
+ options['generator'] = gen_factory.getCombinedGenerator(gen=gen)
bot = RedirectRobot(action, **options)
bot.run()
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/654468
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I1723b7160924d82b0529b2346389cefebc4d7ef7
Gerrit-Change-Number: 654468
Gerrit-PatchSet: 2
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: D3r1ck01 <xsavitar.wiki(a)aol.com>
Gerrit-Reviewer: MarcoAurelio <maurelio(a)tools.wmflabs.org>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged