Opened 2 years ago
Closed 13 months ago
#119 closed enhancement (fixed)
Allow "pathlike" objects for paths
Reported by: | ftputiluser | Owned by: | schwa |
---|---|---|---|
Priority: | major | Milestone: | 4.0.0 |
Component: | Library | Version: | 3.4 |
Keywords: | pathlib pathlike | Cc: |
Description (last modified by )
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/"))
Change History (6)
comment:1 Changed 2 years ago by
comment:2 Changed 2 years ago by
Description: | modified (diff) |
---|
comment:3 Changed 13 months ago by
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/
comment:4 Changed 13 months ago by
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.
comment:5 Changed 13 months ago by
As of [a3f58fa3920e], 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.
comment:6 Changed 13 months ago by
Keywords: | pathlib pathlike added |
---|---|
Milestone: | → 4.0.0 |
Resolution: | → fixed |
Status: | new → closed |
Summary: | support for the Pathlib → Allow "pathlike" objects for paths |
Version: | → 3.4 |
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.
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.