Message265128
| Author |
davide.rizzo |
| Recipients |
davide.rizzo |
| Date |
2016年05月08日.11:15:47 |
| SpamBayes Score |
-1.0 |
| Marked as misclassified |
Yes |
| Message-id |
<1462706148.1.0.443359172953.issue26976@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
pathlib doesn't provide an exact replacement for os.path.realpath().
Path.resolve() is the closest equivalent, but differs in behavior in one case: when the path does not exist.
>>> os.path.realpath('/foo')
'/foo'
>>> Path('/foo').resolve()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/pathlib.py", line 1094, in resolve
s = self._flavour.resolve(self)
File "/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/pathlib.py", line 330, in resolve
return _resolve(base, str(path)) or sep
File "/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/pathlib.py", line 315, in _resolve
target = accessor.readlink(newpath)
File "/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/pathlib.py", line 422, in readlink
return os.readlink(path)
FileNotFoundError: [Errno 2] No such file or directory: '/foo'
This impairs pathlib usefulness to sanitize user input when I am about to create a file or a directory. The file does not exist yet, and pathlib doesn't provide an easy mean to validate whether the provided input is safe. |
|
History
|
|---|
| Date |
User |
Action |
Args |
| 2016年05月08日 11:15:48 | davide.rizzo | set | recipients:
+ davide.rizzo |
| 2016年05月08日 11:15:48 | davide.rizzo | set | messageid: <1462706148.1.0.443359172953.issue26976@psf.upfronthosting.co.za> |
| 2016年05月08日 11:15:48 | davide.rizzo | link | issue26976 messages |
| 2016年05月08日 11:15:47 | davide.rizzo | create |
|