New submission from Jonas Thiem:

Demonstration:

>>> import shlex
>>> shlex.quote(b"abc")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib64/python3.4/shlex.py", line 285, in quote
    if _find_unsafe(s) is None:
TypeError: can't use a string pattern on a bytes-like object
>>>

Your question is now probably, why would anyone not want to use unicode strings 
here?

The reason is that for some operations (e.g. file access to some known paths) 
decoding and encoding from/to any sort of unicode interpretation can be lossy, 
specifically when the file path on the filesystem has broken/mixed encoding 
characters. In such a case, the shell command might need to be supplied as 
bytestring to ensure it is sent exactly as-is so such broken files can still be 
dealt with, without the Unicode interpretation possibly deforming the path in 
some bytes.

Since shlex.quote seems targeted at shell usage, it should therefore support 
this.

----------
components: Library (Lib)
messages: 254186
nosy: Jonas Thiem, The Compiler
priority: normal
severity: normal
status: open
title: shlex.quote doesn't work on bytestrings
type: behavior
versions: Python 3.4

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue25567>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to