[Email-SIG] fix email module for python 3000 (bytes/str)
Victor Stinner
victor.stinner at haypocalc.com
Thu Aug 9 02:41:08 CEST 2007
(This email was first sent to python-3000 mailing list. Guido van Rossum
proposed me to send it to email-sig and that's what I do :-))
Hi,
I started to work on email module to port it for Python 3000, 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 Email-SIG
mailing list