06.01.14 12:38, Vajrasky Kok написав(ла):
This is related with ticket 19717: "resolve() fails when the path
doesn't exist".

Assuming /home/cutecat exists but not /home/cutecat/aa,

what is the desired output of
Path('/home/cutecat/aa/bb/cc').resolve(strict=False)?

Should it be:

"/home/cutecat" (the existed path only),
"/home/cutecat/aa" (the first non-existed path; my current strategy), or
"/home/cutecat/aa/bb/cc" (the default behaviour of os.path.realpath)?

The readlink command has three canonicalize modes

`-f'
`--canonicalize'
     Activate canonicalize mode.  If any component of the file name
     except the last one is missing or unavailable, `readlink' produces
     no output and exits with a nonzero exit code.  A trailing slash is
     ignored.

`-e'
`--canonicalize-existing'
     Activate canonicalize mode.  If any component is missing or
     unavailable, `readlink' produces no output and exits with a
     nonzero exit code.  A trailing slash requires that the name
     resolve to a directory.

`-m'
`--canonicalize-missing'
     Activate canonicalize mode.  If any component is missing or
     unavailable, `readlink' treats it as a directory.

Behavior of os.path.realpath() is equivalent to --canonicalize-missing. Current behavior of pathlib.Path.resolve() is equivalent to --canonicalize-existing.

Behavior of --canonicalize-existing can be derived from --canonicalize, just check that resulting patch exists. But other modes can't be derived from --canonicalize-existing.

def resolve_existing(path):
    path = path.resolve()
    if not path.exists():
raise FileNotFoundError(errno.ENOENT, 'No such file or directory: %r' % str(path))
    return path

So perhaps two main modes should be --canonicalize (default) and --canonicalize-missing (with missing=True)?

_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to