This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: PySys_SetArgv escapes quotes in argv[]
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 2.6
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: RMBianchi, christian.heimes, r.david.murray, zach.ware
Priority: normal Keywords:

Created on 2012-06-07 17:13 by RMBianchi, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (3)
msg162478 - (view) Author: R.M.Bianchi (RMBianchi) Date: 2012-06-07 17:13
Embedding Python in C++ I saw that if I pass this string below to the PySys_SetArgv, as one of the command-line arguments passed to an embedded script:

"--net-label-name='("DC1","eth1")'"

PySys_Argv transforms it escaping the single quotes, and in the Python side I get this value for sys.argv[i]:

'--net-label-name=\'("DC1","eth1")\''

It does not seem a problem of converting strings or char in the C++ sides, I checked them.

The problem appears just after the PySys_Argv call.

=== cut ===
Qt-Debug: python script command-line args: ("/afs/cern.ch/work/r/rbianchi/private/tdaq_4_0_0/dbe/cmt/pm_farm.py", "--safe-hw-tags", "--add='pcatd143'", "--net-label-name='("DC1","eth1")'", "newdb.data.xml")
[...]
pyout: sys.argv:
pyout:
pyout: ['/afs/cern.ch/work/r/rbianchi/private/tdaq_4_0_0/dbe/cmt/pm_farm.py', '--safe-hw-tags', "--add='pcatd143'", '--net-label-name=\'("DC1","eth1")\'', 'newdb.data.xml']
=== cut ===

Please notice that the same script works perfectly with the same argument list in stand-alone mode (i.e. not embedded in C++).

Please also notice that in the embedded side the problem does not appear if I substitute the string passed as command line parameter from the original one:

"--net-label-name='("DC1","eth1")'"

to this one below, where I omit a level of quotes and I skip the double quotes:

"--net-label-name=('DC1','eth1')"

In this last case the embedded script also works fine in the embedded world.

It seems to me an issue in PySys_SetArgv, while parsing the strings. But maybe I'm missing something.

Best regards,

  R.M.Bianchi
msg162492 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2012-06-07 19:41
Could you please clarify the inputs and outputs.  I can't tell from your description what exact byte string you are passing in from C++ or what exact string you are seeing on the Python side.  For example, if:

  '--net-label-name=\'("DC1","eth1")\''

is the python repr of a string, it is equivalent to the ASCII byte sequence:

  --net-label-name='("DC1","eth1")'

Most likely that is what you are passing in from C++, in which case everything seems to be to be working as expected.  So if that is not the case, please clarify.
msg367397 - (view) Author: Zachary Ware (zach.ware) * (Python committer) Date: 2020-04-27 05:13
Lacking a response from the OP, I'm closing the issue.
History
Date User Action Args
2022-04-11 14:57:31adminsetgithub: 59233
2020-04-27 05:13:33zach.waresetstatus: languishing -> closed

nosy: + zach.ware
messages: + msg367397

resolution: not a bug
stage: resolved
2013-07-07 16:08:15christian.heimessetstatus: open -> languishing
nosy: + christian.heimes
2012-06-07 19:41:52r.david.murraysetnosy: + r.david.murray
messages: + msg162492
2012-06-07 17:13:54RMBianchicreate