Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make pathlib.PurePath.__str__ use shlex.quote #72997

Closed
cool-RR mannequin opened this issue Nov 27, 2016 · 5 comments
Closed

Make pathlib.PurePath.__str__ use shlex.quote #72997

cool-RR mannequin opened this issue Nov 27, 2016 · 5 comments
Labels
3.7 (EOL) end of life stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@cool-RR
Copy link
Mannequin

cool-RR mannequin commented Nov 27, 2016

BPO 28811
Nosy @pitrou, @cool-RR, @serhiy-storchaka

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2016-11-27.10:09:11.521>
created_at = <Date 2016-11-27.09:33:13.278>
labels = ['3.7', 'type-feature', 'library']
title = 'Make pathlib.PurePath.__str__ use shlex.quote'
updated_at = <Date 2016-11-28.10:25:38.479>
user = 'https://github.com/cool-RR'

bugs.python.org fields:

activity = <Date 2016-11-28.10:25:38.479>
actor = 'cool-RR'
assignee = 'none'
closed = True
closed_date = <Date 2016-11-27.10:09:11.521>
closer = 'serhiy.storchaka'
components = ['Library (Lib)']
creation = <Date 2016-11-27.09:33:13.278>
creator = 'cool-RR'
dependencies = []
files = []
hgrepos = []
issue_num = 28811
keywords = []
message_count = 5.0
messages = ['281812', '281814', '281815', '281818', '281856']
nosy_count = 3.0
nosy_names = ['pitrou', 'cool-RR', 'serhiy.storchaka']
pr_nums = []
priority = 'normal'
resolution = 'rejected'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue28811'
versions = ['Python 3.7']

@cool-RR
Copy link
Mannequin Author

cool-RR mannequin commented Nov 27, 2016

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 might have been able to remove the str from there if bpo-28623 wasn't rejected.)

I wish I could do this:

    ssh_client.run(f'/bin/rm {path}')
    
But since my path has a space, that would only be possible if PurePath.__str__ were to use shlex.quote, and put quotes around my path (only if it includes a space).

What do you think about that?

@cool-RR cool-RR mannequin added 3.7 (EOL) end of life stdlib Python modules in the Lib dir type-feature A feature request or enhancement labels Nov 27, 2016
@serhiy-storchaka
Copy link
Member

This will break any code that pass str(path) to API that doesn't support pathlib.

In your case you can introduce a short alias:

    q = shlex.quote
    ssh_client.run(f'/bin/rm {q(str(path))}')

Or add more convenient helper:

    def q(path):
        return shlex.quote(str(path))
ssh_client.run(f'/bin/rm {q(path)}')

@cool-RR
Copy link
Mannequin Author

cool-RR mannequin commented Nov 27, 2016

"This will break any code that pass str(path) to API that doesn't support pathlib."

I don't understand. Can you give a concrete example of code it would break?

@serhiy-storchaka
Copy link
Member

open(str(path))

@cool-RR
Copy link
Mannequin Author

cool-RR mannequin commented Nov 28, 2016

I understand now, you're completely right. This change would break the entire world :)

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.7 (EOL) end of life stdlib Python modules in the Lib dir type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

1 participant