Message71748
| Author |
vstinner |
| Recipients |
HWJ, amaury.forgeotdarc, benjamin.peterson, gvanrossum, pitrou, vstinner |
| Date |
2008年08月22日.14:21:38 |
| SpamBayes Score |
4.8058905e-07 |
| Marked as misclassified |
No |
| Message-id |
<1219414904.04.0.609279694414.issue3187@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
I implemented the "invalid filename" class feature:
- by default, os.listdir() raise an error (UnicodeDecodeError) on
invalid filename. The previous behaviour was to return bytes object
instead of str.
- if invalid_filename=True: create an InvalidFilename class instance
InvalidFilename is not a bytes string, it's not a str string, it's a
new class. It has three attributes:
- bytes: the real filename
- charset: charset (type str)
- str: fake filename (type str) used by __str__() method
My patch also fixes os.path.join() to accept InvalidFilename: if at
last one argument is an InvalidFilename, use InvalidFilename.join()
(class method).
os.listdir() and os.unlink() are patched to accept InvalidFilename.
unlink always accept InvalidFilename whereas listdir() only produces
InvalidFilename is os.listdir(path, invalid_filename=True) is used.
I added an optional argument "invalid_filename" to shutil.rmtree(),
default value is *True*.
To sum up, visible changes:
- os.listdir() raise an error on invalid filename instead of return a
mixed list of str and bytes
- shutil.rmtree() manipulate str and InvalidFilename instead of str
and bytes |
|