User talk:Cmglee/extract lang.py

Some comments can break the script
Hello Cmglee! I've stumbled upon a bug in this script. Say, the below SVG code (simplified testcase) is in a file named test.svg:

Then, when I run, I get: Traceback (most recent call last): File "/usr/local/bin/extract_lang.py", line 26, in    svg_out = re.sub(r'(<\s*switch[^>]*>)(.*?)(\s*<\s*/\s*switch[^>]*>)',  File "/usr/local/Cellar/python@3.9/3.9.0_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/re.py", line 210, in sub    return _compile(pattern, flags).sub(repl, string, count)  File "/usr/local/bin/extract_lang.py", line 27, in     lambda matchs:extract_lang(matchs.group(2), lang), svg_in, flags=re.I | re.DOTALL) File "/usr/local/bin/extract_lang.py", line 18, in extract_lang return re_lang.sub('', svg_langs[lang] if lang in svg_langs else svg_langs[None]) KeyError: None (I'm running macOS, if it matters)

If I delete  from the file, the script works fine.

In general, a comment right before the tag that contains  breaks the script. Hope this can be fixed. DmitTrix (talk) 20:01, 13 November 2020 (UTC)

pinging, just in case you don't monitor this page… DmitTrix (talk) 20:42, 16 November 2020 (UTC)
 * Thanks very much for your interest in my script and your feedback.
 * I hadn't considered SVG comments, so have modified my script on the parent page to strip out comments. Hope that's OK.
 * Can you please try again? Thanks, cm&#610;&#671;ee&#9094;&#964;a&#671;&#954; 22:12, 16 November 2020 (UTC)
 * Hi! Thanks a lot for looking into this. Sorry, I'm a bit busy IRL these days; will test as soon as I manage to get back to it. DmitTrix (talk) 11:19, 18 November 2020 (UTC)
 * Sorry for not getting back to you on this for so long. I've re-tested it on a few files that were making problems, and the latest version of the script worked fine. Thanks for fixing! DmitTrix (talk) 11:06, 30 November 2020 (UTC)
 * My pleasure, : glad it works. By the way, I'd have preferred if the relevant comment was retained, but it's hard to tell whether the relevant comment comes before or after the extracted section. Easiest was to just remove all comments. Cheers, cm&#610;&#671;ee&#9094;&#964;a&#671;&#954; 18:23, 30 November 2020 (UTC)