Issue 44842: String conversion of Path removes '/' from original url (original) (raw)

Created on 2021-08-05 16:15 by manish.satwani, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (5)
msg399008 - (view) Author: Manish Satwani (manish.satwani) Date: 2021-08-05 16:15
import pathlib p = pathlib.Path('adl://myblob.azuredatalakestore.net/local/abc/xyz') s = str(p) print(s) what you expect s to be?? There is a bug in path.Path.str(conversion to string) and it remove a slash s is 'adl:/myblob.azuredatalakestore.net/local/abc/xyz' <-- this is getting print....plz fix it
msg399009 - (view) Author: Manish Satwani (manish.satwani) Date: 2021-08-05 16:16
import pathlib p = pathlib.Path('adl://myblob.azuredatalakestore.net/local/abc/xyz') s = str(p) print(s) what you expect s to be?? There is a bug in path.Path.str(conversion to string) and it remove a slash s is 'adl:/myblob.azuredatalakestore.net/local/abc/xyz' <-- this is getting print....plz fix it
msg399013 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2021-08-05 16:30
pathlib is not designed to support URIs, so this behavior is not surprising. You want to use a different library, maybe urllib.
msg399036 - (view) Author: Manish Satwani (manish.satwani) Date: 2021-08-05 20:15
Thanks for the update Eric, if it is not designed to support URI it should tell to the user. It is very wired it just returns wrong data. You can detect it very well if user has specified URI or not.
msg399043 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2021-08-05 22:10
But that's a perfectly valid filename: $ mkdir -p adl://myblob.azuredatalakestore.net/local/abc/xyz $ ls -R adl: 'adl:': myblob.azuredatalakestore.net/ 'adl:/myblob.azuredatalakestore.net': local/ 'adl:/myblob.azuredatalakestore.net/local': abc/ 'adl:/myblob.azuredatalakestore.net/local/abc': xyz/ 'adl:/myblob.azuredatalakestore.net/local/abc/xyz': The pathlib module isn't going to guess whether you passed it a filename or URI of some sort, especially when it's a valid filename. That's the caller's job to get right. Removing the double slashes is a normal part of pathlib's behavior of normalizing paths, just as if you said from a bash shell "ls //etc//sysconfig", which will show the contents of "/etc/sysconfig". Although I'll admit I couldn't find this documented anywhere with a quick search.
History
Date User Action Args
2022-04-11 14:59:48 admin set github: 89005
2021-08-05 22:10:06 eric.smith set status: open -> closedresolution: not a bugmessages: + stage: resolved
2021-08-05 20:15:07 manish.satwani set messages: +
2021-08-05 16:30:00 eric.smith set nosy: + eric.smithmessages: +
2021-08-05 16:16:06 manish.satwani set messages: +
2021-08-05 16:15:08 manish.satwani create