Issue 28817: Provide method PurePath.quote() that calls shlex.quote (original) (raw)

Issue28817

Created on 2016-11-28 10:41 by cool-RR, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (3)
msg281858 - (view) Author: Ram Rachum (cool-RR) * Date: 2016-11-28 10:41
I have a a PurePath object like so: path = PurePath('/home/my awesome user/file.txt') I'm SSHing into a server and I want to remove the file. So I have to do this: ssh_client.run(f'/bin/rm {shlex.quote(str(path))}') Which is really long and ugly. I suggested in that shlex.quote could just take a Path argument, and in that __str__ would use shlex.quote, and it was rejected too. My next suggestion: Implement PurePath.quote() method that calls shlex.quote() on the path. What do you think?
msg281859 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-11-28 10:55
Please no. The interface of pathlib is already overburdened. We shouldn't add every function that is applicable to string paths as a Path method.
msg281876 - (view) Author: Zachary Ware (zach.ware) * (Python committer) Date: 2016-11-28 13:59
You already have a short, simple, one-line solution, and have had suggestions for shortening it yourself if you absolutely need to do so. If you can provide proof that this is an extremely common use case (and considering how short the solution already is, it would need to be completely ubiquitous), we might reconsider this, but in the absence of such proof these suggestions are trying to solve a problem that doesn't exist.
History
Date User Action Args
2022-04-11 14:58:40 admin set github: 73003
2016-11-28 13:59:16 zach.ware set status: open -> closednosy: + zach.waremessages: + resolution: rejectedstage: resolved
2016-11-28 10:55:25 serhiy.storchaka set nosy: + serhiy.storchakamessages: +
2016-11-28 10:41:50 cool-RR set versions: + Python 3.7, - Python 3.6
2016-11-28 10:41:44 cool-RR create