Message71624
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. |
|
Date |
User |
Action |
Args |
2008-08-21 10:59:29 | vstinner | set | recipients:
+ vstinner, amaury.forgeotdarc, pitrou, benjamin.peterson, HWJ |
2008-08-21 10:59:29 | vstinner | set | messageid: <1219316369.16.0.371557599728.issue3187@psf.upfronthosting.co.za> |
2008-08-21 10:59:28 | vstinner | link | issue3187 messages |
2008-08-21 10:59:27 | vstinner | create | |
|