Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upGitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
Way to specify additional encoding for options decoding #6119
Comments
|
The only problem with respecting |
|
We could define a new command line option to set the encoding only for the We basically search the sys.argv for the new option and if one is presented we extract the given encoding. Then we can use this encoding to further decode the Example: + def compat_conf(conf, encoding=preferredencoding()):
if sys.version_info < (3,):
+ return [a.decode(encoding, 'replace') for a in conf]
return conf
+ # Try to extract the encoding for the command_line_conf decode process
+ enc = sys.argv[sys.argv.index(str('--new-option')) + 1] if str('--new-option') in sys.argv else None
+ command_line_conf = compat_conf(sys.argv[1:], enc) |
Hi @dstftw
On your commit you replaced the utf-8 encoding with the preferredencoding() function. I just wanted to ask if it is possible to use an existing command line option like --encoding in order to specify an additional encoding.
For example if someone wants to call youtube-dl.exe on windows using the subprocess module (which does not support unicode on Python 2.x) he has to encode the input to the subprocess module. With your implementation the user has to use the locale.getpreferredencoding() to encode the data else the decoding on the side of youtube-dl will fail. But if the returned encoding from locale.getpreferredencoding() can't encode the input some of the characters get lost.
I am currently working on #5527 so it would be helpful if the user had the power to select the encoding both for the encoding and the decoding phase.
We can achieve this behaviour using something like this on options.py