Page MenuHomePhabricator

cosmetic_changes.py: Exiting due to uncaught exception <class 're.error'>
Closed, ResolvedPublicBUG REPORT

Description

Background information:

Steps to replicate the issue (include links if applicable):

python pwb.py cosmetic_changes -page:"قالب:\w" -lang:arz

What happens?:

Retrieving 1 pages from wikipedia:arz.


>>> قالب:\w <<<

1 read operation
Execution time: 0 seconds
Read operation time: 0.0 seconds
Script terminated by exception:

ERROR: bad escape \w at position 14 (line 1, column 15) (error)
Traceback (most recent call last):
  File "C:\Users\Mohammed\Downloads\core\pwb.py", line 39, in <module>
    sys.exit(main())
             ^^^^^^
  File "C:\Users\Mohammed\Downloads\core\pwb.py", line 35, in main
    runpy.run_path(str(path), run_name='__main__')
  File "<frozen runpy>", line 291, in run_path
  File "<frozen runpy>", line 98, in _run_module_code
  File "<frozen runpy>", line 88, in _run_code
  File "C:\Users\Mohammed\Downloads\core\pywikibot\scripts\wrapper.py", line 516, in <module>
    main()
  File "C:\Users\Mohammed\Downloads\core\pywikibot\scripts\wrapper.py", line 500, in main
    if not execute():
           ^^^^^^^^^
  File "C:\Users\Mohammed\Downloads\core\pywikibot\scripts\wrapper.py", line 487, in execute
    run_python_file(filename, script_args, module)
  File "C:\Users\Mohammed\Downloads\core\pywikibot\scripts\wrapper.py", line 147, in run_python_file
    exec(compile(source, filename, 'exec', dont_inherit=True),
  File "C:\Users\Mohammed\Downloads\core\scripts\cosmetic_changes.py", line 131, in <module>
    main()
  File "C:\Users\Mohammed\Downloads\core\scripts\cosmetic_changes.py", line 127, in main
    bot.run()
  File "C:\Users\Mohammed\Downloads\core\pywikibot\bot.py", line 1702, in run
    self.treat(page)
  File "C:\Users\Mohammed\Downloads\core\pywikibot\bot.py", line 1956, in treat
    self.treat_page()
  File "C:\Users\Mohammed\Downloads\core\scripts\cosmetic_changes.py", line 84, in treat_page
    new_text = cc_toolkit.change(old_text)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Mohammed\Downloads\core\pywikibot\cosmetic_changes.py", line 302, in change
    new_text = self._change(text)
               ^^^^^^^^^^^^^^^^^^
  File "C:\Users\Mohammed\Downloads\core\pywikibot\cosmetic_changes.py", line 296, in _change
    text = self.safe_execute(method, text)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Mohammed\Downloads\core\pywikibot\cosmetic_changes.py", line 283, in safe_execute
    result = method(text)
             ^^^^^^^^^^^^
  File "C:\Users\Mohammed\Downloads\core\pywikibot\cosmetic_changes.py", line 384, in standardizePageFooter
    text = textlib.replaceLanguageLinks(text, interwiki_links,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Mohammed\Downloads\core\pywikibot\tools\_deprecate.py", line 396, in wrapper
    return obj(*__args, **__kw)
           ^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Mohammed\Downloads\core\pywikibot\textlib.py", line 1217, in replaceLanguageLinks
    newtext = regexp.sub(s + includeOff, s2)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.752.0_x64__qbz5n2kfra8p0\Lib\re\__init__.py", line 317, in _subx
    template = _compile_repl(template, pattern)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.752.0_x64__qbz5n2kfra8p0\Lib\re\__init__.py", line 308, in _compile_repl
    return _parser.parse_template(repl, pattern)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.752.0_x64__qbz5n2kfra8p0\Lib\re\_parser.py", line 1078, in parse_template
    raise s.error('bad escape %s' % this, len(this)) from None
re.error: bad escape \w at position 14 (line 1, column 15)
CRITICAL: Exiting due to uncaught exception <class 're.error'>

What should have happened instead?:

The script should have skipped this page (when working on a whole namespace) and continued working on other pages normally.

Software version :

Pywikibot: [https] r-pywikibot-core (3eb032e, g17569, 2023/02/16, 13:17:24, master)
Release version: 8.1.0.dev0
setuptools version: 67.3.2
mwparserfromhell version: 0.6.4
wikitextparser version: n/a
requests version: 2.28.2
    certificate test: ok
Python: 3.11.2 (tags/v3.11.2:878ead1, Feb  7 2023, 16:38:35) [MSC v.1934 64 bit (AMD64)]

Event Timeline

Change 892044 had a related patch set uploaded (by Matěj Suchánek; author: Matěj Suchánek):

[pywikibot/core@master] [FIX] Avoid error when replacement includes backslash

https://gerrit.wikimedia.org/r/892044

Xqt triaged this task as High priority.Feb 27 2023, 11:50 AM

I wasn't able to reproduce it:

Microsoft Windows [Version 10.0.17763.1577]
(c) 2018 Microsoft Corporation. Alle Rechte vorbehalten.

D:\>cd pwb/git/core

D:\pwb\GIT\core>pwb cosmetic_changes  -page:"قالب:\w" -lang:arz
ATTENTION: You can run this script as a stand-alone for testing purposes.
However, the changes that are made are only minor, and other users might get
angry if you fill the version histories and watchlists with such irrelevant
changes. Some wikis prohibit stand-alone running. Do you really want to
continue? ([y]es, [N]o): y
Retrieving 1 pages from wikipedia:arz.


>>> قالب:\w <<<
@@ -1,2 +0,0 @@
-
-

Edit summary: بوت: تغييرات تجميلية
Do you want to accept these changes? ([y]es, [N]o, [a]ll, [q]uit): y
WARNING: No user is logged in on site wikipedia:arz
Page [[قالب:\w]] saved

1 read operation
1 write operation
Execution time: 5 seconds
Read operation time: 5.0 seconds
Write operation time: 5.0 seconds
Script terminated successfully.

D:\pwb\GIT\core>
D:\pwb\GIT\core>pwb version
Pywikibot: [ssh] pywikibot-core (75ce04f, g17577, 2023/02/26, 12:56:26, master)
Release version: 8.1.0.dev0
setuptools version: 66.1.1
mwparserfromhell version: 0.6.3
wikitextparser version: 0.51.1
requests version: 2.28.1
  cacerts: C:\Python311\Lib\site-packages\certifi\cacert.pem
    certificate test: ok
Python: 3.11.0 (main, Oct 24 2022, 18:26:48) [MSC v.1933 64 bit (AMD64)]
PYWIKIBOT_DIR: Not set
PYWIKIBOT_DIR_PWB: D:\pwb\GIT\core\pywikibot\scripts
PYWIKIBOT_NO_USER_CONFIG: Not set
Config base dir: D:\pwb\GIT\core

https://arz.wikipedia.org/w/index.php?title=%D9%82%D8%A7%D9%84%D8%A8%3A%5Cw&diff=7847013&oldid=7847010

Ah, I should test it with this version

Xqt assigned this task to matej_suchanek.

Change 892044 merged by jenkins-bot:

[pywikibot/core@master] [FIX] Avoid error when replacement includes backslash

https://gerrit.wikimedia.org/r/892044