jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/636748 )
Change subject: [IMPR] remove deprecated mime_params in api.Request()
......................................................................
[IMPR] remove deprecated mime_params in api.Request()
Remove mime_params form Request():
- parameter was deprecated and warning issued since 2015.
- FutureWarning is issued if mime param is now used with
bool values
- mime=True is converted to mime={}
Change-Id: I80b11819dddf00bc3634fe8360a3b5424d04e57e
---
M pywikibot/data/api.py
M pywikibot/site/__init__.py
M tests/dry_api_tests.py
3 files changed, 32 insertions(+), 49 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/data/api.py b/pywikibot/data/api.py
index b452ee4..772db21 100644
--- a/pywikibot/data/api.py
+++ b/pywikibot/data/api.py
@@ -38,7 +38,8 @@
from pywikibot.family import SubdomainFamily
from pywikibot.login import LoginStatus
from pywikibot.tools import (
- deprecated, itergroup, PYTHON_VERSION, remove_last_args
+ deprecated, issue_deprecation_warning, itergroup, PYTHON_VERSION,
+ remove_last_args,
)
from pywikibot.tools.formatter import color_format
@@ -984,7 +985,7 @@
details on what parameters are accepted for each request type.
Uploading files is a special case: to upload, the parameter "mime" must
- be true, and the parameter "file" must be set equal to a valid
+ contain a dict, and the parameter "file" must be set equal to a valid
filename on the local computer, _not_ to the content of the file.
Returns a dict containing the JSON data returned by the wiki. Normally,
@@ -1026,7 +1027,7 @@
# To make sure the default value of 'parameters' can be identified.
_PARAM_DEFAULT = object()
- def __init__(self, site=None, mime=None, throttle=True, mime_params=None,
+ def __init__(self, site=None, mime=None, throttle=True,
max_retries=None, retry_wait=None, use_get=None,
parameters=_PARAM_DEFAULT, **kwargs):
"""
@@ -1055,14 +1056,11 @@
@param site: The Site to which the request will be submitted. If not
supplied, uses the user's configured default Site.
- @param mime: If true, send in "multipart/form-data" format (default
- False). Parameters which should only be transferred via mime
- mode can be defined via that parameter too (an empty dict acts
- like 'True' not like 'False'!).
- @type mime: bool or dict
- @param mime_params: DEPRECATED! A dictionary of parameter which should
- only be transferred via mime mode. If not None sets mime to
- True.
+ @param mime: If not None, send in "multipart/form-data" format (default
+ None). Parameters which should only be transferred via mime
+ mode are defined via this parameter (even an empty dict means
+ mime shall be used).
+ @type mime: None or dict
@param max_retries: (optional) Maximum number of times to retry after
errors, defaults to config.max_retries.
@param retry_wait: (optional) Minimum time in seconds to wait after an
@@ -1081,14 +1079,12 @@
.format(self.site), RuntimeWarning, 2)
else:
self.site = site
- if mime_params is not None:
- # mime may not be different from mime_params
- if mime is not None and mime is not True:
- raise ValueError('If mime_params is set, mime may not differ '
- 'from it.')
- warn('Use the "mime" parameter instead of the "mime_params".')
- mime = mime_params
- self.mime = mime # this also sets self.mime_params
+ self.mime = mime
+ if isinstance(mime, bool): # type(mime) == bool is deprecated.
+ issue_deprecation_warning(
+ 'Bool values of mime param in api.Request()',
+ depth=3, warning_class=FutureWarning, since='20201028')
+ self.mime = {} if mime is True else None
self.throttle = throttle
self.use_get = use_get
if max_retries is None:
@@ -1326,23 +1322,6 @@
"""Return a list of tuples containing the parameters in any order."""
return list(self._params.items())
- @property
- def mime(self):
- """Return whether mime parameters are defined."""
- return self.mime_params is not None
-
- @mime.setter
- def mime(self, value):
- """
- Change whether mime parameter should be defined.
-
- This will clear the mime parameters.
- """
- try:
- self.mime_params = dict(value)
- except TypeError:
- self.mime_params = {} if value else None
-
@deprecated(since='20141006', future_warning=True)
def http_params(self):
"""Return the parameters formatted for inclusion in an HTTP request.
@@ -1361,9 +1340,9 @@
if hasattr(self, '__defaulted'):
return
- if self.mime_params \
- and set(self._params.keys()) & set(self.mime_params.keys()):
- raise ValueError('The mime_params and params may not share the '
+ if self.mime is not None \
+ and set(self._params.keys()) & set(self.mime.keys()):
+ raise ValueError('The mime and params shall not share the '
'same keys.')
if self.action == 'query':
@@ -1558,7 +1537,7 @@
@classmethod
def _build_mime_request(cls, params: dict,
- mime_params) -> Tuple[dict, str]:
+ mime_params: dict) -> Tuple[dict, bytes]:
"""
Construct a MIME multipart form post.
@@ -1588,9 +1567,9 @@
def _get_request_params(self, use_get, paramstring):
"""Get request parameters."""
uri = self.site.apipath()
- if self.mime:
+ if self.mime is not None:
(headers, body) = Request._build_mime_request(
- self._encoded_items(), self.mime_params)
+ self._encoded_items(), self.mime)
use_get = False # MIME requests require HTTP POST
else:
headers = {'Content-Type': 'application/x-www-form-urlencoded'}
diff --git a/pywikibot/site/__init__.py b/pywikibot/site/__init__.py
index 9356600..7b4ef9c 100644
--- a/pywikibot/site/__init__.py
+++ b/pywikibot/site/__init__.py
@@ -5718,9 +5718,11 @@
'offset': offset,
'filename': file_page_title,
'ignorewarnings': ignore_all_warnings})
- req.mime_params['chunk'] = (
- chunk, ('application', 'octet-stream'),
- {'filename': mime_filename})
+ req.mime = {
+ 'chunk': (chunk,
+ ('application', 'octet-stream'),
+ {'filename': mime_filename})
+ }
if _file_key:
req['filekey'] = _file_key
try:
@@ -5813,7 +5815,7 @@
file_contents = f.read()
filetype = (mimetypes.guess_type(source_filename)[0]
or 'application/octet-stream')
- final_request.mime_params = {
+ final_request.mime = {
'file': (file_contents, filetype.split('/'),
{'filename': mime_filename})
}
diff --git a/tests/dry_api_tests.py b/tests/dry_api_tests.py
index c6a06c6..23cd552 100644
--- a/tests/dry_api_tests.py
+++ b/tests/dry_api_tests.py
@@ -297,10 +297,10 @@
local_filename = join_images_path('MP_sounds.png')
with open(local_filename, 'rb') as f:
file_content = f.read()
- body = Request._build_mime_request({}, {
+ _, body = Request._build_mime_request({}, {
'file': (file_content, ('image', 'png'),
{'filename': local_filename})
- })[1]
+ })
self.assertNotEqual(body.find(file_content), -1)
@@ -317,7 +317,9 @@
parameters = {'action': 'upload', 'file': 'MP_sounds.png',
'filename': join_images_path('MP_sounds.png')}
req = Request(site=site, mime=True, parameters=parameters)
- self.assertEqual(req.mime, True)
+ with self.assertRaises(AssertionError):
+ assert req.mime is True
+ self.assertEqual(req.mime, {})
class ParamInfoDictTests(DefaultDrySiteTestCase):
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/636748
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: I80b11819dddf00bc3634fe8360a3b5424d04e57e
Gerrit-Change-Number: 636748
Gerrit-PatchSet: 7
Gerrit-Owner: 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/+/266073 )
Change subject: [bugfix] Enable misspelling.py for several sites using wikidata
......................................................................
[bugfix] Enable misspelling.py for several sites using wikidata
- collect misspelling categories from wikidata items Q8644265 or Q9195708.
This enables the script for additional sites
- prefer templates over categories if misspelling_templates can be found
by its sitename.
- use usual BaseBot option handling with MisspellingRobot. Therfore use
kwargs for the options. Unfortunately DisambiguationRobot does not have
a compatible interface. Therefore call SingleSiteBot.__init__ first and
pass the options back to MisspellingRobot's super().__init__ but call
their parameter by its name.
- enable kwargs with DisambiguationRobot and only set self.generator
if the positional argument for generator is useful and not None
- rename createPageGenerator to generator which is used directly by
run method.
Bug: T94681
Bug: T258859
Change-Id: I0eaca5b35435984be5e7516e7e5dc8ebba21cf5e
---
M scripts/misspelling.py
M scripts/solve_disambiguation.py
2 files changed, 94 insertions(+), 75 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/misspelling.py b/scripts/misspelling.py
index 85cba8e..af6029a 100755
--- a/scripts/misspelling.py
+++ b/scripts/misspelling.py
@@ -31,6 +31,8 @@
import pywikibot
from pywikibot import i18n, pagegenerators
+from pywikibot.bot import SingleSiteBot
+from pywikibot.tools.formatter import color_format
from scripts.solve_disambiguation import DisambiguationRobot
@@ -48,62 +50,72 @@
"""Spelling bot."""
- misspellingTemplate = {
- 'de': ('Falschschreibung', 'Obsolete Schreibung'),
+ available_options = {
+ 'always': None,
+ 'start': None,
+ 'main': False,
+ }
+
+ misspelling_templates = {
+ 'wikipedia:de': ('Falschschreibung', 'Obsolete Schreibung'),
}
# Optional: if there is a category, one can use the -start
# parameter.
- misspellingCategory = {
- 'ar': 'تحويلات أخطاء إملائية',
- # da: only contains date redirects at the moment
- 'da': 'Omdirigeringer af fejlstavninger',
- 'de': ('Kategorie:Wikipedia:Falschschreibung',
- 'Kategorie:Wikipedia:Obsolete Schreibung'),
- 'en': 'Redirects from misspellings',
- 'hu': 'Átirányítások hibás névről',
- 'nl': 'Categorie:Wikipedia:Redirect voor spelfout',
- }
+ misspelling_categories = ('Q8644265', 'Q9195708')
- def __init__(self, always, firstPageTitle, main_only) -> None:
+ def __init__(self, **kwargs) -> None:
"""Initializer."""
- super().__init__(always, [], True, False, None, False, main_only)
- self.generator = self.createPageGenerator(firstPageTitle)
+ # handle options first;
+ # they are needed for DisambiguationRobot positional arguments
+ SingleSiteBot.__init__(self, **kwargs)
+ super().__init__(always=self.opt.always, alternatives=[],
+ getAlternatives=True, dnSkip=False, generator=None,
+ primary=False, main_only=self.opt.main,
+ **self.options) # save options
- def createPageGenerator(self, firstPageTitle) -> Generator[pywikibot.Page,
- None, None]:
+ @property
+ def generator(self) -> Generator[pywikibot.Page, None, None]:
"""Generator to retrieve misspelling pages or misspelling redirects."""
- mycode = self.site.code
- if mycode in self.misspellingCategory:
- categories = self.misspellingCategory[mycode]
- if isinstance(categories, str):
- categories = (categories, )
- generators = (
- pagegenerators.CategorizedPageGenerator(
- pywikibot.Category(self.site, misspellingCategoryTitle),
- recurse=True, start=firstPageTitle)
- for misspellingCategoryTitle in categories)
- elif mycode in self.misspellingTemplate:
- templates = self.misspellingTemplate[mycode]
+ templates = self.misspelling_templates.get(self.site.sitename)
+ categories = [cat for cat in (self.site.page_from_repository(item)
+ for item in self.misspelling_categories)
+ if cat is not None]
+
+ if templates:
+ pywikibot.output(color_format(
+ '{yellow}Working on templates...{default}'))
if isinstance(templates, str):
templates = (templates, )
+
generators = (
- pagegenerators.ReferringPageGenerator(
- pywikibot.Page(self.site, misspellingTemplateName, ns=10),
- onlyTemplateInclusion=True)
- for misspellingTemplateName in templates)
- if firstPageTitle:
+ pywikibot.Page(self.site, template_name, ns=10).getReferences(
+ follow_redirects=False,
+ only_template_inclusion=True)
+ for template_name in templates
+ )
+
+ if self.opt.start:
pywikibot.output(
- '-start parameter unsupported on this wiki because there '
- 'is no category for misspellings.')
+ '-start parameter is not supported on this wiki\n'
+ 'because templates are used for misspellings.')
+ elif categories:
+ pywikibot.output(color_format(
+ '{yellow}Working on categories...{default}'))
+ generators = (
+ pagegenerators.CategorizedPageGenerator(
+ cat, recurse=True, start=self.opt.start
+ )
+ for cat in categories
+ )
+
else:
pywikibot.output(HELP_MSG.format(site=self.site))
+ return
- empty_gen = (i for i in [])
- return empty_gen
generator = chain(*generators)
preloadingGen = pagegenerators.PreloadingGenerator(generator)
- return preloadingGen
+ yield from preloadingGen
def findAlternatives(self, disambPage) -> bool:
"""
@@ -116,25 +128,30 @@
if disambPage.isRedirectPage():
self.alternatives.append(disambPage.getRedirectTarget().title())
return True
- if self.misspellingTemplate.get(disambPage.site.code) is not None:
- templates = self.misspellingTemplate[disambPage.site.code]
- if isinstance(templates, str):
- templates = (templates, )
- for template, params in disambPage.templatesWithParams():
- if template.title(with_ns=False) in templates:
- # The correct spelling is in the last parameter.
- correctSpelling = params[-1]
- # On de.wikipedia, there are some cases where the
- # misspelling is ambiguous, see for example:
- # https://de.wikipedia.org/wiki/Buthan
- for match in self.linkR.finditer(correctSpelling):
- self.alternatives.append(match.group('title'))
- if not self.alternatives:
- # There were no links in the parameter, so there is
- # only one correct spelling.
- self.alternatives.append(correctSpelling)
- return True
+ sitename = disambPage.site.sitename
+ templates = self.misspelling_templates.get(sitename)
+ if templates is None:
+ return False
+
+ if isinstance(templates, str):
+ templates = (templates, )
+
+ for template, params in disambPage.templatesWithParams():
+ if template.title(with_ns=False) in templates:
+ # The correct spelling is in the last parameter.
+ correct_spelling = params[-1]
+ # On de.wikipedia, there are some cases where the
+ # misspelling is ambiguous, see for example:
+ # https://de.wikipedia.org/wiki/Buthan
+ for match in self.linkR.finditer(correct_spelling):
+ self.alternatives.append(match.group('title'))
+
+ if not self.alternatives:
+ # There were no links in the parameter, so there is
+ # only one correct spelling.
+ self.alternatives.append(correct_spelling)
+ return True
return False
def setSummaryMessage(self, disambPage, *args, **kwargs) -> None:
@@ -158,23 +175,24 @@
@param args: command line arguments
@type args: str
"""
- # the option that's always selected when the bot wonders what to do with
- # a link. If it's None, the user is prompted (default behaviour).
- always = None
- main_only = False
- firstPageTitle = None
-
+ options = {}
for arg in pywikibot.handle_args(args):
- arg, sep, value = arg.partition(':')
- if arg == '-always':
- always = value
- elif arg == '-start':
- firstPageTitle = value or pywikibot.input(
+ opt, _, value = arg.partition(':')
+ if not opt.startswith('-'):
+ continue
+ opt = opt[1:]
+ if opt == 'always':
+ # the option that's always selected when the bot wonders
+ # what to do with a link. If it's None, the user is prompted
+ # (default behaviour).
+ options[opt] = value
+ elif opt == 'start':
+ options[opt] = value or pywikibot.input(
'At which page do you want to start?')
- elif arg == '-main':
- main_only = True
+ elif opt == 'main':
+ options[opt] = True
- bot = MisspellingRobot(always, firstPageTitle, main_only)
+ bot = MisspellingRobot(**options)
bot.run()
diff --git a/scripts/solve_disambiguation.py b/scripts/solve_disambiguation.py
index a078064..ec3516c 100755
--- a/scripts/solve_disambiguation.py
+++ b/scripts/solve_disambiguation.py
@@ -601,15 +601,16 @@
}
def __init__(self, always, alternatives, getAlternatives, dnSkip,
- generator, primary, main_only, first_only=False, minimum=0
- ) -> None:
+ generator, primary, main_only, first_only=False, minimum=0,
+ **kwargs) -> None:
"""Initializer."""
- super().__init__()
+ super().__init__(**kwargs)
self.always = always
self.alternatives = alternatives
self.getAlternatives = getAlternatives
self.dnSkip = dnSkip
- self.generator = generator
+ if generator:
+ self.generator = generator
self.primary = primary
self.main_only = main_only
self.first_only = first_only
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/266073
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: I0eaca5b35435984be5e7516e7e5dc8ebba21cf5e
Gerrit-Change-Number: 266073
Gerrit-PatchSet: 11
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Alex S.H. Lin <alexsh(a)mail2000.com.tw>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Matěj Suchánek <matejsuchanek97(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/+/636133 )
Change subject: [IMPR] split reportBadAccount to decrease code complexity
......................................................................
[IMPR] split reportBadAccount to decrease code complexity
- Split reportBadAccount() into two parts to decrease code complexity
- reportBadAccount adds a name to self._BAQueue. reportBadAccount
should be renamed later after previous patches are committed
- report_bad_account() reports the bad names if required
- No further code changes were made.
Change-Id: Ie2b43b54e1068c507d3509bedeefe7cb0194e4cd
---
M scripts/welcome.py
1 file changed, 61 insertions(+), 59 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/welcome.py b/scripts/welcome.py
index 5330621..fab7a8a 100755
--- a/scripts/welcome.py
+++ b/scripts/welcome.py
@@ -594,68 +594,70 @@
return True
return False
- def reportBadAccount(self, name=None, final=False) -> None:
- """Report bad account."""
- # Queue process
- if name:
- if globalvar.confirm:
- answer = pywikibot.input_choice(
- '{} may have an unwanted username, do you want to report '
- 'this user?'
- .format(name), [('Yes', 'y'), ('No', 'n'), ('All', 'a')],
- 'n', automatic_quit=False)
- if answer in ['a', 'all']:
- answer = 'y'
- globalvar.confirm = False
- else:
+ def reportBadAccount(self, name: str) -> None: # should be renamed
+ """Add bad account to queue."""
+ if globalvar.confirm:
+ answer = pywikibot.input_choice(
+ '{} may have an unwanted username, do you want to report '
+ 'this user?'
+ .format(name), [('Yes', 'y'), ('No', 'n'), ('All', 'a')],
+ 'n', automatic_quit=False)
+ if answer in ['a', 'all']:
answer = 'y'
+ globalvar.confirm = False
+ else:
+ answer = 'y'
- if answer.lower() in ['yes', 'y'] or not globalvar.confirm:
- self.show_status()
- pywikibot.output(
- '{} is possibly an unwanted username. It will be reported.'
- .format(name))
- if hasattr(self, '_BAQueue'):
- self._BAQueue.append(name)
- else:
- self._BAQueue = [name]
-
- if len(self._BAQueue) >= globalvar.dumpToLog or final:
- rep_text = ''
- # name in queue is max, put detail to report page
- pywikibot.output('Updating badname accounts to report page...')
- rep_page = pywikibot.Page(self.site,
- i18n.translate(self.site,
- report_page))
- if rep_page.exists():
- text_get = rep_page.get()
+ if answer.lower() in ['yes', 'y'] or not globalvar.confirm:
+ self.show_status()
+ pywikibot.output(
+ '{} is possibly an unwanted username. It will be reported.'
+ .format(name))
+ if hasattr(self, '_BAQueue'):
+ self._BAQueue.append(name)
else:
- text_get = ('This is a report page for the Bad-username, '
- 'please translate me. --~~~')
- pos = 0
- # The talk page includes "_" between the two names, in this way
- # replace them to " ".
- for usrna in self._BAQueue:
- username = pywikibot.url2link(usrna, self.site, self.site)
- n = re.compile(re.escape(username))
- y = n.search(text_get, pos)
- if y:
- pywikibot.output('{} is already in the report page.'
- .format(username))
- else:
- # Adding the log.
- rep_text += i18n.translate(self.site,
- report_text) % username
- if self.site.code == 'it':
- rep_text = '%s%s}}' % (rep_text, self.bname[username])
+ self._BAQueue = [name]
- com = i18n.twtranslate(self.site, 'welcome-bad_username')
- if rep_text != '':
- rep_page.put(text_get + rep_text, summary=com, force=True,
- minor=True)
- self.show_status(Msg.DONE)
- pywikibot.output('Reported')
- self.BAQueue = []
+ if len(self._BAQueue) >= globalvar.dumpToLog:
+ self.report_bad_account()
+
+ def report_bad_account(self) -> None:
+ """Report bad account."""
+ rep_text = ''
+ # name in queue is max, put detail to report page
+ pywikibot.output('Updating badname accounts to report page...')
+ rep_page = pywikibot.Page(self.site,
+ i18n.translate(self.site,
+ report_page))
+ if rep_page.exists():
+ text_get = rep_page.get()
+ else:
+ text_get = ('This is a report page for the Bad-username, '
+ 'please translate me. --~~~')
+ pos = 0
+ # The talk page includes "_" between the two names, in this way
+ # replace them to " ".
+ for usrna in self._BAQueue:
+ username = pywikibot.url2link(usrna, self.site, self.site)
+ n = re.compile(re.escape(username))
+ y = n.search(text_get, pos)
+ if y:
+ pywikibot.output('{} is already in the report page.'
+ .format(username))
+ else:
+ # Adding the log.
+ rep_text += i18n.translate(self.site,
+ report_text) % username
+ if self.site.code == 'it':
+ rep_text = '%s%s}}' % (rep_text, self.bname[username])
+
+ com = i18n.twtranslate(self.site, 'welcome-bad_username')
+ if rep_text != '':
+ rep_page.put(text_get + rep_text, summary=com, force=True,
+ minor=True)
+ self.show_status(Msg.DONE)
+ pywikibot.output('Reported')
+ self.BAQueue = []
def makelogpage(self, queue=None) -> bool:
"""Make log page."""
@@ -871,7 +873,7 @@
if hasattr(self, '_BAQueue'):
self.show_status()
pywikibot.output('Putting bad name to report page...')
- self.reportBadAccount(None, final=True)
+ self.report_bad_account()
try:
if globalvar.recursive:
self.show_status()
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/636133
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: Ie2b43b54e1068c507d3509bedeefe7cb0194e4cd
Gerrit-Change-Number: 636133
Gerrit-PatchSet: 3
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: D3r1ck01 <xsavitar.wiki(a)aol.com>
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/+/636128 )
Change subject: [doc] update ROADMAP.rst
......................................................................
[doc] update ROADMAP.rst
Change-Id: I66a093386e32cacc0451f7176b959407a9aa050f
---
M HISTORY.rst
M ROADMAP.rst
2 files changed, 4 insertions(+), 1 deletion(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/HISTORY.rst b/HISTORY.rst
index efd7f1e..5ea6768 100644
--- a/HISTORY.rst
+++ b/HISTORY.rst
@@ -6,6 +6,7 @@
*19 October 2020*
+* Add support for smn-wiki (T264962)
* callback parameter of comms.http.fetch() is desupported
* Fix api.APIError() calls for Flow and Thanks extension
* edit, move, create, upload, unprotect and prompt parameters of Page.protect() are deprecated (T227610)
diff --git a/ROADMAP.rst b/ROADMAP.rst
index a1187d9..8126cef 100644
--- a/ROADMAP.rst
+++ b/ROADMAP.rst
@@ -1,10 +1,13 @@
Current release changes
~~~~~~~~~~~~~~~~~~~~~~~
+* Fix incorrect server time (T266084)
+* L10N-Updates
* Support Namespace packages in version.py (T265946)
* Server414Error was added to pywikibot (T266000)
* Deprecated editor.command() method was removed
* comms.PywikibotCookieJar and comms.mode_check_decorator were deleted
+* Remove deprecated tools classes Stringtypes and UnicodeType
* Remove deprecated tools function open_compressed and signature and UnicodeType class
* Fix http_tests.LiveFakeUserAgentTestCase (T265842)
* HttpRequest properties were renamed to request.Response identifiers (T265206)
@@ -28,4 +31,3 @@
* 5.0.0: pagegenerators.ReferringPageGenerator is desupported and will be removed
* 4.3.0: Unused UserBlocked exception will be removed
* 4.3.0: Deprecated Page.contributingUsers() will be removed
-* 4.2.0: tools.StringTypes will be removed
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/636128
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: I66a093386e32cacc0451f7176b959407a9aa050f
Gerrit-Change-Number: 636128
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/+/636632 )
Change subject: [cleanup] cleanup interwiki_graph.py
......................................................................
[cleanup] cleanup interwiki_graph.py
- remove Python 2 code parts
- add deprecated decorator to already deprecated properties
- replace all originPage occurrences by origin
- remove old originPage variable in Subject.__init__
- update doc in Subject.__init__
- initialize found_in attribute only once
- deprecate global variable 'pydotfound'
- remove sanity check for pydot 1.0.3 because the lowest pydot version
allowed is 1.2
detached from 70ebe6db0980c4cece96356a0b8673a78c916914
Change-Id: I19d8678ec9f9241c9beca90f1cda3af2b62ab86c
---
M pywikibot/interwiki_graph.py
1 file changed, 46 insertions(+), 52 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/interwiki_graph.py b/pywikibot/interwiki_graph.py
index 4078774..216e2f7 100644
--- a/pywikibot/interwiki_graph.py
+++ b/pywikibot/interwiki_graph.py
@@ -1,28 +1,24 @@
# -*- coding: utf-8 -*-
"""Module with the Graphviz drawing calls."""
#
-# (C) Pywikibot team, 2006-2018
+# (C) Pywikibot team, 2006-2020
#
# Distributed under the terms of the MIT license.
#
-from __future__ import absolute_import, division, unicode_literals
-
-from collections import Counter
import itertools
import threading
-from typing import Optional
-try:
- import pydot
-except ImportError as e:
- pydot = e
+from collections import Counter
+from typing import Optional
import pywikibot
from pywikibot import config2 as config
-
-# deprecated value
-pydotfound = not isinstance(pydot, ImportError)
+from pywikibot.tools import deprecated, ModuleDeprecationWrapper
+try:
+ import pydot
+except ImportError as e:
+ pydot = e
class GraphImpossible(Exception):
@@ -60,32 +56,26 @@
pywikibot.output('Graph could not be saved as %s' % filename)
-class Subject(object):
+class Subject:
"""Data about a page with translations on multiple wikis."""
def __init__(self, origin=None):
"""Initializer.
- @param originPage: the page on the 'origin' wiki
- @type originPage: pywikibot.page.Page
+ @param origin: the page on the 'origin' wiki
+ @type origin: pywikibot.page.Page
"""
# Remember the "origin page"
self._origin = origin
- # Temporary variable to support git blame; do not use
- originPage = origin
-
- self.found_in = None
-
# foundIn is a dictionary where pages are keys and lists of
# pages are values. It stores where we found each page.
# As we haven't yet found a page that links to the origin page, we
# start with an empty list for it.
- if originPage:
- self.foundIn = {self.originPage: []}
- else:
- self.foundIn = {}
+ self.found_in = {}
+ if origin:
+ self.found_in = {origin: []}
@property
def origin(self):
@@ -97,34 +87,33 @@
self._origin = value
@property
+ @deprecated('Subject.origin', since='20150125', future_warning=True)
def originPage(self):
- """Deprecated property for the origin page.
-
- DEPRECATED. Use origin.
- """
- # TODO: deprecate this property
+ """DEPRECATED. Deprecated property for the origin page."""
return self.origin
@originPage.setter
+ @deprecated('Subject.origin', since='20150125', future_warning=True)
def originPage(self, value):
self.origin = value
@property
+ @deprecated('Subject.found_in', since='20150125', future_warning=True)
def foundIn(self):
"""Mapping of pages to others pages interwiki linked to it.
DEPRECATED. Use found_in.
"""
- # TODO: deprecate this property
return self.found_in
@foundIn.setter
+ @deprecated('Subject.found_in', since='20150125', future_warning=True)
def foundIn(self, value):
- """Temporary property setter to support code migration."""
+ """DEPRECATED. Temporary property setter to support code migration."""
self.found_in = value
-class GraphDrawer(object):
+class GraphDrawer:
"""Graphviz (dot) code creator."""
@@ -137,21 +126,21 @@
@raises GraphImpossible: pydot is not installed
"""
if isinstance(pydot, ImportError):
- raise GraphImpossible('pydot is not installed: %s.' % pydot)
+ raise GraphImpossible('pydot is not installed: {}.'.format(pydot))
self.graph = None
self.subject = subject
def getLabel(self, page):
"""Get label for page."""
- return '"%s:%s"' % (page.site.code, page.title())
+ return '"{}:{}"'.format(page.site.code, page.title())
def _octagon_site_set(self):
"""Build a list of sites with more than one valid page."""
page_list = self.subject.found_in.keys()
# Only track sites of normal pages
- each_site = [page.site for page in page_list
- if page.exists() and not page.isRedirectPage()]
+ each_site = (page.site for page in page_list
+ if page.exists() and not page.isRedirectPage())
return {x[0] for x in itertools.takewhile(
lambda x: x[1] > 1,
@@ -172,7 +161,7 @@
node.set_fillcolor('blue')
elif page.isDisambig():
node.set_fillcolor('orange')
- if page.namespace() != self.subject.originPage.namespace():
+ if page.namespace() != self.subject.origin.namespace():
node.set_color('green')
node.set_style('filled,bold')
if page.site in self.octagon_sites:
@@ -190,17 +179,15 @@
oppositeEdge = self.graph.get_edge(targetLabel, sourceLabel)
if oppositeEdge:
- if isinstance(oppositeEdge, list):
- # bugfix for pydot >= 1.0.3
- oppositeEdge = oppositeEdge[0]
+ oppositeEdge = oppositeEdge[0]
oppositeEdge.set_dir('both')
# workaround for sf.net bug 401: prevent duplicate edges
# (it is unclear why duplicate edges occur)
# https://sourceforge.net/p/pywikipediabot/bugs/401/
elif self.graph.get_edge(sourceLabel, targetLabel):
- pywikibot.output(
- 'BUG: Tried to create duplicate edge from %s to %s'
- % (refPage.title(as_link=True), page.title(as_link=True)))
+ pywikibot.error(
+ 'Tried to create duplicate edge from {} to {}'
+ .format(refPage, page))
# duplicate edges would be bad because then get_edge() would
# give a list of edges, not a single edge when we handle the
# opposite edge.
@@ -221,7 +208,7 @@
def saveGraphFile(self):
"""Write graphs to the data directory."""
- thread = GraphSavingThread(self.graph, self.subject.originPage)
+ thread = GraphSavingThread(self.graph, self.subject.origin)
thread.start()
def createGraph(self):
@@ -231,21 +218,21 @@
For more info see U{https://meta.wikimedia.org/wiki/Interwiki_graphs}
"""
pywikibot.output('Preparing graph for %s'
- % self.subject.originPage.title())
+ % self.subject.origin.title())
# create empty graph
self.graph = pydot.Dot()
# self.graph.set('concentrate', 'true')
self.octagon_sites = self._octagon_site_set()
- for page in self.subject.foundIn.keys():
+ for page in self.subject.found_in.keys():
# a node for each found page
self.addNode(page)
# mark start node by pointing there from a black dot.
- firstLabel = self.getLabel(self.subject.originPage)
+ firstLabel = self.getLabel(self.subject.origin)
self.graph.add_node(pydot.Node('start', shape='point'))
self.graph.add_edge(pydot.Edge('start', firstLabel))
- for page, referrers in self.subject.foundIn.items():
+ for page, referrers in self.subject.found_in.items():
for refPage in referrers:
self.addDirectedEdge(page, refPage)
self.saveGraphFile()
@@ -260,9 +247,16 @@
@param extension: file extension
@return: filename of <family>-<lang>-<page>.<ext>
"""
- filename = '%s-%s-%s' % (page.site.family.name,
- page.site.code,
- page.title(as_filename=True))
+ filename = '-'.join((page.site.family.name,
+ page.site.code,
+ page.title(as_filename=True)))
if extension:
- filename += '.%s' % extension
+ filename += '.{}'.format(extension)
return filename
+
+
+wrapper = ModuleDeprecationWrapper(__name__)
+wrapper._add_deprecated_attr(
+ 'pydotfound',
+ replacement_name='"not isinstance(pydot, ImportError)"',
+ since='2015125', future_warning=True)
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/636632
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: I19d8678ec9f9241c9beca90f1cda3af2b62ab86c
Gerrit-Change-Number: 636632
Gerrit-PatchSet: 2
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-CC: Zhuyifei1999 <zhuyifei1999(a)gmail.com>
Gerrit-MessageType: merged
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/555744 )
Change subject: [tests] rewrite site_tests.TestSiteObject.test_namespace_methods
......................................................................
[tests] rewrite site_tests.TestSiteObject.test_namespace_methods
- use subtests instead of all() function
- test namespace id -1 and -2
- take into account that str is an iterable and additonal tests
Bug: T240117
Change-Id: Ie5610c55366721509641c56f0d122733a43c5bb4
---
M tests/site_tests.py
1 file changed, 23 insertions(+), 15 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/tests/site_tests.py b/tests/site_tests.py
index 245ca88..747ffb9 100644
--- a/tests/site_tests.py
+++ b/tests/site_tests.py
@@ -325,23 +325,31 @@
mysite = self.get_site()
ns = mysite.namespaces
self.assertIsInstance(ns, Mapping)
- self.assertTrue(all(x in ns for x in range(0, 16)))
# built-in namespaces always present
self.assertIsInstance(mysite.ns_normalize('project'), str)
- self.assertTrue(all(isinstance(key, int)
- for key in ns))
- self.assertTrue(all(isinstance(val, Iterable)
- for val in ns.values()))
- self.assertTrue(all(isinstance(name, str)
- for val in ns.values()
- for name in val))
- self.assertTrue(all(isinstance(mysite.namespace(key), str)
- for key in ns))
- self.assertTrue(all(isinstance(mysite.namespace(key, True), Iterable)
- for key in ns))
- self.assertTrue(all(isinstance(item, str)
- for key in ns
- for item in mysite.namespace(key, True)))
+
+ for ns_id in range(-2, 16):
+ with self.subTest(namespace_id=ns_id):
+ self.assertIn(ns_id, ns)
+
+ for key in ns:
+ all_ns = mysite.namespace(key, True)
+ with self.subTest(namespace=key):
+ self.assertIsInstance(key, int)
+ self.assertIsInstance(mysite.namespace(key), str)
+ self.assertNotIsInstance(all_ns, str)
+ self.assertIsInstance(all_ns, Iterable)
+
+ for item in all_ns:
+ with self.subTest(namespace=key, item=item):
+ self.assertIsInstance(item, str)
+
+ for val in ns.values():
+ with self.subTest(value=val):
+ self.assertIsInstance(val, Iterable)
+ for name in val:
+ with self.subTest(value=val, name=name):
+ self.assertIsInstance(name, str)
def test_user_attributes_return_types(self):
"""Test returned types of user attributes."""
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/555744
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: Ie5610c55366721509641c56f0d122733a43c5bb4
Gerrit-Change-Number: 555744
Gerrit-PatchSet: 3
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Dvorapa <dvorapa(a)seznam.cz>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged