jenkins-bot has submitted this change. ( 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1154358?usp=email )

Change subject: IMPR: replace codecs.open with open or Path.read_text method in 
upload.py
......................................................................

IMPR: replace codecs.open with open or Path.read_text method in upload.py

Also validate whether -descfile exists

Bug: T395187
Change-Id: I0835072deae9e6661cc16d7fbf883a4a267153ff
---
M scripts/upload.py
1 file changed, 12 insertions(+), 6 deletions(-)

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




diff --git a/scripts/upload.py b/scripts/upload.py
index c766801..20b854e 100755
--- a/scripts/upload.py
+++ b/scripts/upload.py
@@ -45,7 +45,8 @@

 -summary:      [str] Pick a custom edit summary for the bot.

--descfile:     [str] Specify a filename where the description is stored
+-descfile:     [str] Specify a filename where the description is stored.
+               An error message is printed if the file does not exist.


 It is possible to combine ``-abortonwarn`` and ``-ignorewarn`` so that
@@ -66,16 +67,16 @@
 parameter, and for a description.
 """
 #
-# (C) Pywikibot team, 2003-2024
+# (C) Pywikibot team, 2003-2025
 #
 # Distributed under the terms of the MIT license.
 #
 from __future__ import annotations

-import codecs
 import math
 import os
 import re
+from pathlib import Path

 import pywikibot
 from pywikibot.bot import suggest_help
@@ -183,9 +184,14 @@
             pywikibot.error('Both a description and a -descfile were '
                             'provided. Please specify only one of those.')
             return
-        with codecs.open(description_file,
-                         encoding=pywikibot.config.textfile_encoding) as f:
-            description = f.read().replace('\r\n', '\n')
+
+        filepath = Path(description_file)
+        if not filepath.is_file() or filepath.is_symlink():
+            pywikibot.Error('Invalid filename given with -descfile')
+            return
+
+        description = filepath.read_text(
+            encoding=pywikibot.config.textfile_encoding).replace('\r\n', '\n')

     while not ('://' in url or os.path.exists(url)):
         if not url:

--
To view, visit 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1154358?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.wikimedia.org/r/settings?usp=email

Gerrit-MessageType: merged
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I0835072deae9e6661cc16d7fbf883a4a267153ff
Gerrit-Change-Number: 1154358
Gerrit-PatchSet: 2
Gerrit-Owner: Xqt <[email protected]>
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
Pywikibot-commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to