[Python-ideas] Updated PEP 428 (pathlib)

Charles-François Natali cf.natali at gmail.com
Sun Mar 3 15:12:09 CET 2013


> Yes. We could call it
> "root" (http://en.wikipedia.org/wiki/Root_%28linguistics%29) but in
> this context it would be confusing. Also, it's not exactly the root
> since as you point there can still be a remaining suffix.

Indeed, "root" would be even more confusing.

> There's "stem", too (http://en.wikipedia.org/wiki/Word_stem). With the
> same provision about not being the actual stem.

Also, it doesn't sound familiar (at least to me).

How about "rootname", or "stripped_name" (the last one is a little too long)?

> You mean for glob() (match() is just a regex-like matcher, it doesn't
> do any I/O).

Yes, I meant glob() (fnmatch() implementations can also be subject to
DoS through stack exhaustion, but Python's implementation is based on
regex).

> Yes, I think we could add a `allow_recursive` argument.
> Is there any other DoS issue?

If by recursive you mean the '**' pattern (cross-directory match),
then I'm afraid that's not enough.
For example, a pattern like '*/../*/../*/../*/../*' would have the same problem:

"""
$ mkdir -p /tmp/foo/a /tmp/foo/b
$ ~/python/cpython/python -c "from pathlib import *; p =
Path('/tmp/foo'); print(list(p.glob('*/../*/../*/../*')))"
[PosixPath('/tmp/foo/a/../a/../a/../a'),
PosixPath('/tmp/foo/a/../a/../a/../b'),
PosixPath('/tmp/foo/a/../a/../b/../a'),
PosixPath('/tmp/foo/a/../a/../b/../b'),
PosixPath('/tmp/foo/a/../b/../a/../a'),
PosixPath('/tmp/foo/a/../b/../a/../b'),
PosixPath('/tmp/foo/a/../b/../b/../a'),
PosixPath('/tmp/foo/a/../b/../b/../b'),
PosixPath('/tmp/foo/b/../a/../a/../a'),
PosixPath('/tmp/foo/b/../a/../a/../b'),
PosixPath('/tmp/foo/b/../a/../b/../a'),
PosixPath('/tmp/foo/b/../a/../b/../b'),
PosixPath('/tmp/foo/b/../b/../a/../a'),
PosixPath('/tmp/foo/b/../b/../a/../b'),
PosixPath('/tmp/foo/b/../b/../b/../a'),
PosixPath('/tmp/foo/b/../b/../b/../b')]
"""

cf



More information about the Python-ideas mailing list