Message71624
| Author |
vstinner |
| Recipients |
HWJ, amaury.forgeotdarc, benjamin.peterson, pitrou, vstinner |
| Date |
2008年08月21日.10:59:26 |
| SpamBayes Score |
1.0547119e-15 |
| Marked as misclassified |
No |
| Message-id |
<1219316369.16.0.371557599728.issue3187@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
I wrote a Filename class. I tries different methods:
* no parent class "class Filename: ..." -> I don't know how to make
bytes(filename) works!? But it's the best option to avoid strange bugs
(mix bytes/str, remember Python 2.x...)
* str parent class "class Filename(str): ..." -> doesn't work because
os functions uses the fake unicode filename before testing the bytes
(real) filename
* bytes parent class "class Filename(bytes): ..." -> that's the
current implementation
The idea is to encode str -> bytes (and not bytes -> str because we
want to avoid problems with such conversions). So I reimplemented most
bytes methods: __addr__, __raddr__, __contains__, startswith, endswith
and index. index method has no start/end arguments since the behaviour
would be different than a real unicode string :-/
I added an example of fixed os.listdir(): create Filename() object if
we get bytes. Should we always create Filename objects? I don't think
so. |
|