Is there a function in urllib or the stdlib that recognizes a SSH-like URL vs. a local path?

172 Views Asked by At

rsync recognizes if a destination is local rsync a/ /local/path/ or if it is remote rsync a/ [email protected]:/path/to/.

Is there a similar URL parsing tool, built-in in Python's stdlib?

The key thing with rsync or scp is that we don't want to prepend a ssh://, it automatically parses it as local or remote, that's the requirement I have.

urllib.parse does not seem to be what I'm looking for:

import urllib.parse
print(urllib.parse.urlsplit('[email protected]:/home'))  # SplitResult(scheme='', netloc='', path='[email protected]:/home', query='', fragment='')
print(urllib.parse.urlsplit('./[email protected]:/home')) # could be both a local path with @ and : in dirname
print(urllib.parse.urlsplit('./[email protected]:/home')) # or a remote with valid unix username "./slash"

Note: SCP's implementation and IETF draft about this.

0

There are 0 best solutions below