[Python-3000] fix email module for bytes/str
Victor Stinner
victor.stinner at haypocalc.com
Thu Aug 9 01:59:46 CEST 2007
Hi,
I started to work on email module, but I have trouble to understand if a
function should returns bytes or str (because I don't know email module).
Header.encode() -> bytes?
Message.as_string() -> bytes?
decode_header() -> list of (bytes, str|None) or (str, str|None)?
base64MIME.encode() -> bytes?
message_from_string() <- bytes?
Message.get_payload() -> bytes or str?
A charset name type is str, right?
---------------
Things to change to get bytes:
- replace StringIO with BytesIO
- add 'b' prefix, eg. '' becomes b''
- replace "%s=%s" % (x, y) with b''.join((x, b'=', y))
=> is it the best method to concatenate bytes?
Problems (to port python 2.x code to 3000):
- When obj.lower() is used, I expect obj to be str but it's bytes
- obj.strip() doesn't work when obj is a byte, it requires an
argument but I don't know the right value! Maybe b'\n\r\v\t '?
- iterate on a bytes object gives number and not bytes object, eg.
for c in b"small text":
if re.match("(\n|\r)", c): ...
Is it possible to 'bytes' regex? re.compile(b"x") raise an exception
--
Victor Stinner aka haypo
http://hachoir.org/
More information about the Python-3000
mailing list