~sschwarzer/ftputil#119: 
Allow "pathlike" objects for paths

It will be very useful to have a support for the Pathlib acts like input parameters for methods. E.g. you can do something like ftp_host.chdir(Path("/my/dir/"))

Status
RESOLVED FIXED
Submitter
ftputiluser (unverified)
Assigned to
No-one
Submitted
5 years ago
Updated
5 years ago
Labels
enhancement library

schwa (unverified) 5 years ago · edit

Generally, this sounds like a sensible idea. However, according to the documentation at ​https://docs.python.org/3/library/pathlib.html , Path(...) instantiates a filesystem path for the operating system the Python process runs on.

A path object to be used as an FTP remote path should probably be an FTPPath (or something with a similar name). I'm not sure yet how to implement this. From a pure implementation perspective, an FTPPath could be aliased to a PurePosixPath, but having isinstance(FTPPath(...), PurePosixPath) evaluate to True would be confusing. Although most FTP servers will run on a Posix system, an FTPPath shouldn't assume this. Also, some PurePosixPath operations may not make sense for a remote filesystem.

schwa (unverified) 4 years ago · edit

Since Python 3.6 there's os.PathLike. I think that's what a custom path class should inherit from.

See also
​https://docs.python.org/3/library/os.html#os.PathLike
​https://docs.python.org/3/glossary.html#term-path-like-object
​https://www.python.org/dev/peps/pep-0519/

schwa (unverified) 4 years ago · edit

TODO:

Change tool.as_unicode to tool.as_str and let it accept PathLike objects

Implement an FTPPath class with the following attributes and methods:

Attributes

parts
drive
root
anchor
parents
parent
name
suffix
suffixes
stem

PurePath attributes

__truediv__
as_posix
as_uri
is_absolute
is_reserved
joinpath
match
relative_to
with_name
with_suffix

Non-PurePath methods

cwd
home
stat
chmod
exists
expanduser
glob
group
is_dir
is_file
is_mount
is_symlink
is_socket
is_fifo
is_block_device
is_char_device
iterdir
lchmod
lstat
mkdir
open
owner
read_bytes
read_text
rename
replace
resolve
rglob
rmdir
samefile
stat
symlink_to
touch
unlink
link_to
write_bytes
write_text

I assume the attributes and PurePath methods can be implemented by delegating to an internal PurePosixPath object.

schwa (unverified) 4 years ago · edit

As of a2267f4e11fd2acbd83b3e58c03963ff896cc4d2, methods that used to accept "only" bytes and str objects now also accept PathLike objects that can be converted to bytes and str. Actually, this is the functionality the description asked for.

Implementing an FTPPath class as described above is much more effort.

schwa (unverified) 4 years ago · edit

I changed the title to let it reflect the ticket description. If support for a custom FTPPath is requested, this should better go into a new ticket.

Register here or Log in to comment, or comment via email.