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/"))
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, anFTPPath
could be aliased to aPurePosixPath
, but havingisinstance(FTPPath(...), PurePosixPath)
evaluate toTrue
would be confusing. Although most FTP servers will run on a Posix system, anFTPPath
shouldn't assume this. Also, somePurePosixPath
operations may not make sense for a remote filesystem.
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/
TODO:
Change
tool.as_unicode
totool.as_str
and let it acceptPathLike
objectsImplement 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
methodscwd 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 internalPurePosixPath
object.
As of a2267f4e11fd2acbd83b3e58c03963ff896cc4d2, methods that used to accept "only"
bytes
andstr
objects now also acceptPathLike
objects that can be converted tobytes
andstr
. Actually, this is the functionality the description asked for.Implementing an
FTPPath
class as described above is much more effort.
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.