jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/768087 )
Change subject: [IMPR] Use a dictionary for modified warning keys ......................................................................
[IMPR] Use a dictionary for modified warning keys
Some upload warning keys were changed. Add a warning_keys lookup dict to get the right warning message.
See T130484 and https://www.mediawiki.org/wiki/API:Upload#Upload_warnings
Change-Id: I31098c1398b4247e72effef84266c760832af113 --- M pywikibot/site/_upload.py 1 file changed, 12 insertions(+), 4 deletions(-)
Approvals: Matěj Suchánek: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/site/_upload.py b/pywikibot/site/_upload.py index af8a96c..2a9c754 100644 --- a/pywikibot/site/_upload.py +++ b/pywikibot/site/_upload.py @@ -114,13 +114,20 @@ _file_key, response['offset']) for warning, data in response['warnings'].items()]
+ # some warning keys have been changed + warning_keys = { + 'nochange': 'no-change', + 'duplicateversions': 'duplicate-version', + 'emptyfile': 'empty-file', + } + upload_warnings = { # map API warning codes to user error messages # {msg} will be replaced by message string from API response 'duplicate-archive': 'The file is a duplicate of a deleted file {msg}.', 'was-deleted': 'The file {msg} was previously deleted.', - 'emptyfile': 'File {msg} is empty.', + 'empty-file': 'File {msg} is empty.', 'exists': 'File {msg} already exists.', 'duplicate': 'Uploaded file is a duplicate of {msg}.', 'badfilename': 'Target filename is invalid.', @@ -132,9 +139,9 @@ 'Target filename exists but with a different file {msg}.',
# API-returned message string will be timestamps, not much use here - 'nochange': 'The upload is an exact duplicate of the current ' - 'version of this file.', - 'duplicateversions': 'The upload is an exact duplicate of older ' + 'no-change': 'The upload is an exact duplicate of the current ' + 'version of this file.', + 'duplicate-version': 'The upload is an exact duplicate of older ' 'version(s) of this file.', }
@@ -489,6 +496,7 @@ UserWarning, 3) warning = list(result['warnings'].keys())[0] message = result['warnings'][warning] + warning = warning_keys.get(warning, warning) raise UploadError(warning, upload_warnings[warning] .format(msg=message),