jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/863293 )
Change subject: Improve documentation for pywikibot.WbTime
......................................................................
Improve documentation for pywikibot.WbTime
- Mention that `site` isn't used if `calendermodel` is given
Bug: T324329
Change-Id: I24cf00e74282a94b15af93b352031c3783ad8c41
---
M pywikibot/__init__.py
1 file changed, 35 insertions(+), 14 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/__init__.py b/pywikibot/__init__.py
index 3b5a311..97c4bd9 100644
--- a/pywikibot/__init__.py
+++ b/pywikibot/__init__.py
@@ -350,19 +350,21 @@
to minutes.
:param year: The year as a signed integer of between 1 and 16 digits.
- :param month: Month
- :param day: Day
- :param hour: Hour
- :param minute: Minute
- :param second: Second
+ :param month: Month of the timestamp, if it exists.
+ :param day: Day of the timestamp, if it exists.
+ :param hour: Hour of the timestamp, if it exists.
+ :param minute: Minute of the timestamp, if it exists.
+ :param second: Second of the timestamp, if it exists.
:param precision: The unit of the precision of the time.
:param before: Number of units after the given time it could be, if
uncertain. The unit is given by the precision.
:param after: Number of units before the given time it could be, if
uncertain. The unit is given by the precision.
:param timezone: Timezone information in minutes.
- :param calendarmodel: URI identifying the calendar model
- :param site: The Wikibase site
+ :param calendarmodel: URI identifying the calendar model.
+ :param site: The Wikibase site. If not provided, retrieves the data
+ repository from the default site from user-config.py.
+ Only used if calendarmodel is not given.
"""
if year is None:
raise ValueError('no year given')
@@ -431,14 +433,17 @@
:param datetimestr: Timestamp in a format resembling ISO 8601,
e.g. +2013-01-01T00:00:00Z
- :param precision: The unit of the precision of the time.
+ :param precision: The unit of the precision of the time. Defaults to
+ 14 (second).
:param before: Number of units after the given time it could be, if
uncertain. The unit is given by the precision.
:param after: Number of units before the given time it could be, if
uncertain. The unit is given by the precision.
:param timezone: Timezone information in minutes.
- :param calendarmodel: URI identifying the calendar model
- :param site: The Wikibase site
+ :param calendarmodel: URI identifying the calendar model.
+ :param site: The Wikibase site. If not provided, retrieves the data
+ repository from the default site from user-config.py.
+ Only used if calendarmodel is not given.
"""
match = re.match(r'([-+]?\d+)-(\d+)-(\d+)T(\d+):(\d+):(\d+)Z',
datetimestr)
@@ -459,14 +464,17 @@
Create a new WbTime object from a pywikibot.Timestamp.
:param timestamp: Timestamp
- :param precision: The unit of the precision of the time.
+ :param precision: The unit of the precision of the time. Defaults to
+ 14 (second).
:param before: Number of units after the given time it could be, if
uncertain. The unit is given by the precision.
:param after: Number of units before the given time it could be, if
uncertain. The unit is given by the precision.
:param timezone: Timezone information in minutes.
- :param calendarmodel: URI identifying the calendar model
- :param site: The Wikibase site
+ :param calendarmodel: URI identifying the calendar model.
+ :param site: The Wikibase site. If not provided, retrieves the data
+ repository from the default site from user-config.py.
+ Only used if calendarmodel is not given.
"""
return cls.fromTimestr(timestamp.isoformat(), precision=precision,
before=before, after=after,
@@ -524,7 +532,8 @@
Create a WbTime from the JSON data given by the Wikibase API.
:param data: Wikibase JSON
- :param site: The Wikibase site
+ :param site: The Wikibase site. If not provided, retrieves the data
+ repository from the default site from user-config.py.
"""
return cls.fromTimestr(data['time'], data['precision'],
data['before'], data['after'],
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/863293
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: I24cf00e74282a94b15af93b352031c3783ad8c41
Gerrit-Change-Number: 863293
Gerrit-PatchSet: 6
Gerrit-Owner: RPI2026F1 <sarkaraoyan+rpi2026f1(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/+/862279 )
Change subject: [IMPR] use pathlib instead of codecs for replace.py
......................................................................
[IMPR] use pathlib instead of codecs for replace.py
- use pathlib.Path instead of codecs to open a file
- use readlines() instead of splitlines to read the file
- use f-strings instead of format()
Change-Id: I3095f2bac704344ea1fa850649e99b2fa0e7cdc0
---
M scripts/replace.py
1 file changed, 18 insertions(+), 7 deletions(-)
Approvals:
D3r1ck01: Looks good to me, approved
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/replace.py b/scripts/replace.py
index d44ff14..9a3c511 100755
--- a/scripts/replace.py
+++ b/scripts/replace.py
@@ -146,10 +146,10 @@
#
# Distributed under the terms of the MIT license.
#
-import codecs
import re
from collections.abc import Sequence
from contextlib import suppress
+from pathlib import Path
from typing import Any, Optional
import pywikibot
@@ -807,7 +807,7 @@
return local_args, exceptions
-def handle_pairsfile(filename: str) -> List[str]:
+def handle_pairsfile(filename: str) -> Optional[List[str]]:
"""Handle -pairsfile argument.
.. versionadded:: 7.0
@@ -817,9 +817,8 @@
'Please enter the filename to read replacements from:')
try:
- with codecs.open(filename, 'r', 'utf-8') as f:
- # strip newlines, but not other characters
- replacements = f.read().splitlines()
+ with Path(filename).open(encoding='utf-8') as f:
+ replacements = f.readlines()
if not replacements:
raise OSError(f'{filename} is empty.')
except OSError as e:
@@ -828,8 +827,7 @@
if len(replacements) % 2:
pywikibot.error(
- '{} contains an incomplete pattern replacement pair.'.format(
- filename))
+ f'{filename} contains an incomplete pattern replacement pair.')
return None
# Strip BOM from first line
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/862279
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: I3095f2bac704344ea1fa850649e99b2fa0e7cdc0
Gerrit-Change-Number: 862279
Gerrit-PatchSet: 1
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/+/863023 )
Change subject: [bugfix]: unquote title for red-links in Index"
......................................................................
[bugfix]: unquote title for red-links in Index"
When getting titles from Index page HTML code, characters
can be url-encoded (e.g. when an "'" is present in the title page).
Unquote to obtain the correct page title.
Change-Id: If1d6dfc0e411796df3d2b8ae1c673f76d99911ce
---
M pywikibot/proofreadpage.py
1 file changed, 16 insertions(+), 0 deletions(-)
Approvals:
Mpaa: Looks good to me, approved
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/proofreadpage.py b/pywikibot/proofreadpage.py
index 35ff2dd..56181aa 100644
--- a/pywikibot/proofreadpage.py
+++ b/pywikibot/proofreadpage.py
@@ -32,6 +32,7 @@
from functools import partial
from http import HTTPStatus
from typing import Any, Optional, Union
+from urllib.parse import unquote
from requests.exceptions import ReadTimeout
@@ -974,6 +975,7 @@
title = self._parse_redlink(href) # non-existing page
if title is None: # title not conforming to required format
continue
+ title = unquote(title)
else:
title = a_tag.get('title') # existing page
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/863023
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: If1d6dfc0e411796df3d2b8ae1c673f76d99911ce
Gerrit-Change-Number: 863023
Gerrit-PatchSet: 2
Gerrit-Owner: Mpaa <mpaa.wiki(a)gmail.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/+/863230 )
Change subject: [bugfix] Timestripper find month with first letter uppercase or lowercase
......................................................................
[bugfix] Timestripper find month with first letter uppercase or lowercase
Bug: T324310
Change-Id: I79d9cc68a952f2d213aafe4987fc394226aa83ea
---
M pywikibot/textlib.py
1 file changed, 28 insertions(+), 8 deletions(-)
Approvals:
Matěj Suchánek: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/textlib.py b/pywikibot/textlib.py
index 7bee53a..8b252a8 100644
--- a/pywikibot/textlib.py
+++ b/pywikibot/textlib.py
@@ -25,7 +25,12 @@
from pywikibot.exceptions import InvalidTitleError, SiteDefinitionError
from pywikibot.family import Family
from pywikibot.time import TZoneFixedOffset
-from pywikibot.tools import ModuleDeprecationWrapper, deprecated
+from pywikibot.tools import (
+ ModuleDeprecationWrapper,
+ deprecated,
+ first_lower,
+ first_upper,
+)
from pywikibot.userinterfaces.transliteration import NON_LATIN_DIGITS
@@ -1836,13 +1841,18 @@
self.site = pywikibot.Site() if site is None else site
self.origNames2monthNum = {}
- for n, (_long, _short) in enumerate(self.site.months_names, start=1):
- self.origNames2monthNum[_long] = n
- self.origNames2monthNum[_short] = n
- # in some cases month in ~~~~ might end without dot even if
- # site.months_names do not.
- if _short.endswith('.'):
- self.origNames2monthNum[_short[:-1]] = n
+ # use first_lower/first_upper for 'vi' language because monthsnames
+ # were changed: T324310
+ functions = [first_upper,
+ first_lower] if self.site.lang == 'vi' else [str]
+ for n, (long, short) in enumerate(self.site.months_names, start=1):
+ for func in functions:
+ self.origNames2monthNum[func(long)] = n
+ self.origNames2monthNum[func(short)] = n
+ # in some cases month in ~~~~ might end without dot even if
+ # site.months_names do not.
+ if short.endswith('.'):
+ self.origNames2monthNum[func(short[:-1])] = n
self.groups = ['year', 'month', 'hour', 'time', 'day', 'minute',
'tzinfo']
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/863230
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: I79d9cc68a952f2d213aafe4987fc394226aa83ea
Gerrit-Change-Number: 863230
Gerrit-PatchSet: 6
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: D3r1ck01 <xsavitar.wiki(a)aol.com>
Gerrit-Reviewer: Matěj Suchánek <matejsuchanek97(a)gmail.com>
Gerrit-Reviewer: Mpaa <mpaa.wiki(a)gmail.com>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged