gpython: Fix how --long-option=value=something is processed
Carlos reports that when pymain is invoked as
> python --login='uid=username,ou=people,dc=something,dc=de' my_script.py
it crashes as
Traceback (most recent call last):
File "/srv/slapgrid/slappart5/software_release/bin/python", line 312, in <module>
pymain(sys.argv)
File "/opt/slapgrid/133edb8b6bfc135bce30900e2b50555e/parts/pygolang/gpython/__init__.py", line 113, in pymain
for (opt, arg) in igetopt:
File "/opt/slapgrid/133edb8b6bfc135bce30900e2b50555e/parts/pygolang/gpython/__init__.py", line 552, in __next__
opt, arg = opt.split('=')
While @jerome correctly notices that the problem here is due to --login is passed to python instead of my_script.py it still highlights a problem on gpython side in its _IGetOpt parser for which I made a thinko in 26058b5b (gpython: Factor-out options parsing into getopt-style _IGetOpt helper) without considering that a value for --long-option=value could itself contain another '=' symbols.
-> Fix this thinko.
Without the fix gpython --unknown=x=y crashes as
Traceback (most recent call last):
File "/home/kirr/src/wendelin/venv/py39.venv/bin/gpython", line 8, in <module>
sys.exit(main())
File "/home/kirr/src/tools/go/pygolang-master/gpython/__init__.py", line 402, in main
for (opt, arg) in igetopt:
File "/home/kirr/src/tools/go/pygolang-master/gpython/__init__.py", line 562, in __next__
opt, arg = opt.split('=')
ValueError: too many values to unpack (expected 2)
but after the fix it reports more user-friendly
RuntimeError: unexpected option --unknown
/reported-by @vnmabus
/reported-on https://lab.nexedi.com/nexedi/pygolang/-/issues/1