STINNER Victor <[EMAIL PROTECTED]> added the comment: After testing many different emails servers (POP3, IMAP4 and NNTP), I think that the best type is bytes and not str (unicode). Attached patch changes nntplib to use bytes: - write tests using Gmane NNTP public server - use bytes everywhere except for the commands (str), converted to bytes using ASCII charset - factorizy post() + ihave(): create _post() - replace line[-1] == '\n' by line.endswith(b'\n') - replace e.response[:3] == '480' by e.response.startswith(b'480') - use format() method because str+int is forbidden. Eg. see body() method: id can be an integer (or an unicode string).
I like startswith() / endswith() because it's more readable and it works with string of 1 byte: line[-1:] == b'\n' vs line.endswith(b'\n'). TODO: - test authentication - test methods marked as "TODO" in the testcase: * Check newgroups(), newnews(), list() * Check xhdr(), xover(), xgtitle(), xpath() * Check post(), ihave() - does .format() work with bytes? body(b'1') may creates the command "BODY b'1'" which is wrong <= should I also use bytes for the commands? I don't know NNTP enough to test all methods, and I don't have any account to test the authentication :-/ But most common commands should work (see the testcase). Added file: http://bugs.python.org/file11913/nntp-bytes.patch _______________________________________ Python tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue3714> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com