[issue3613] base64.encodestring does not actually accept strings
Georg Brandl ge...@python.org added the comment: Applied a patch to rename (and keep old aliases) in r73204. -- resolution: - fixed status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue3613 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue3613] base64.encodestring does not actually accept strings
Matt Giuca matt.gi...@gmail.com added the comment: I've attached a patch which renames encodestring to encodebytes (keeping encodestring around as an alias). Updated test and documentation. I also renamed decodestring to decodebytes, because it also refuses to accept a string (only a bytes). I have an alternative suggestion, which I'll post in a separate comment (in a minute). -- Added file: http://bugs.python.org/file13753/encodestring_rename.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue3613 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue3613] base64.encodestring does not actually accept strings
Matt Giuca matt.gi...@gmail.com added the comment: Now, base64.encodestring and decodestring seem a bit weird because the Base64 encoded string is also required to be a bytes. It seems to me that once something is Base64-encoded, it's considered to be ASCII text, not just some byte string, and therefore it should be a str, not a bytes. (For example, they end with a '\n'. That's something which strings do, not bytes). Hence, base64.encodestring (which should be encodebytes) should take a bytes and return a str. base64.decodestring should take a str (required to be ASCII-only) and return a bytes. I've attached an alternative patch, encodebytes_new_types.patch (which, unlike my other patch, doesn't rename decodestring to decodebytes). This patch: - Renames encodestring to encodebytes. - Changes the output of encodebytes to return an ASCII str*, not a bytes. - Changes the input of decodestring to accept an ASCII str, not a bytes. * An ASCII str is a Unicode string with only ASCII characters. This isn't a proper patch (it breaks a lot of other code which I haven't bothered to fix). I'm just submitting it as an idea, in case this is something we want to do. Most likely not, due to the breakage. Also we have the same problem for the non-legacy functions, b64encode and b64decode, etc, so the problem is more widespread than just these two functions. -- Added file: http://bugs.python.org/file13754/encodebytes_new_types.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue3613 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue3613] base64.encodestring does not actually accept strings
Daniel Diniz aja...@gmail.com added the comment: We still need to solve the encodebytes/encodestring stuff. -- stage: - test needed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue3613 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue3613] base64.encodestring does not actually accept strings
Georg Brandl ge...@python.org added the comment: Applied the patch in r69575. ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue3613 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue3613] base64.encodestring does not actually accept strings
Daniel Diniz aja...@gmail.com added the comment: Here's a trivial patch for xmlrpc.client:1168. The testcase below doesn't seem to fit well in test_xmlrpc, should it just be hacked in? import xmlrpc.client transp = xmlrpc.client.Transport() transp.get_host_info(u...@host.tld) -- keywords: +patch nosy: +ajaksu2 Added file: http://bugs.python.org/file12983/get_host_info.diff ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue3613 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue3613] base64.encodestring does not actually accept strings
Changes by HiroakiKawai ka...@apache.org: -- nosy: +kawai ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue3613 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue3613] base64.encodestring does not actually accept strings
New submission from Dmitry Dvoinikov [EMAIL PROTECTED]: This quote from base64.py: --- bytes_types = (bytes, bytearray) # Types acceptable as binary data ... def encodestring(s): Encode a string into multiple lines of base-64 data. Argument and return value are bytes. if not isinstance(s, bytes_types): raise TypeError(expected bytes, not %s % s.__class__.__name__) ... --- shows that encodestring method won't accept str for an argument, only bytes. Perhaps this is by design, but then wouldn't it make sense to change the name of the method ? Anyway, this behavior clashes in (the least I know) xmlrpc.client, line 1168 when basic authentication is present: --- auth = base64.encodestring(urllib.parse.unquote(auth)) --- because unquote() returns str, not bytes. -- components: Library (Lib) messages: 71513 nosy: ddvoinikov severity: normal status: open title: base64.encodestring does not actually accept strings type: behavior versions: Python 3.0 ___ Python tracker [EMAIL PROTECTED] http://bugs.python.org/issue3613 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue3613] base64.encodestring does not actually accept strings
Antoine Pitrou [EMAIL PROTECTED] added the comment: The encodestring() function is refered to in the docs as the legacy interface. Perhaps it should be simply deprecated in 3.0? -- assignee: - georg.brandl components: +Documentation nosy: +georg.brandl, pitrou priority: - high ___ Python tracker [EMAIL PROTECTED] http://bugs.python.org/issue3613 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue3613] base64.encodestring does not actually accept strings
Matt Giuca [EMAIL PROTECTED] added the comment: Hi Dmitry, RE the method behaviour: I think it probably is correct to NOT accept a string. Given that it's base64 encoding it, it only makes sense to encode bytes, not arbitrary Unicode characters which have no well-defined binary representation. RE the method name: I agree, it should be renamed to encodestring. I argued a similar case for the array.tostring and fromstring methods (which actually act on bytes in Python 3.0) - here: http://bugs.python.org/issue3565. So far nobody replied on that issue; I think it may be too late to rename them. Best we can do is document them. RE xmlrpc.client:1168. We just checked in a patch to urllib which adds an unquote_to_bytes function (see http://docs.python.org/dev/3.0/library/urllib.parse.html#urllib.parse.unquote_to_bytes). (Unquote itself still returns a string). It should be correct to just change xmlrpc.client:1168 to call urllib.parse.unquote_to_bytes. (Though I've not tested it). -- nosy: +mgiuca ___ Python tracker [EMAIL PROTECTED] http://bugs.python.org/issue3613 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue3613] base64.encodestring does not actually accept strings
Matt Giuca [EMAIL PROTECTED] added the comment: it should be renamed to encodestring Huh ? It is already called that :) Um ... yes. I mean encodebytes :) Best we can do is document them. Oh well. But I don't know the rules. People are saying things like no new features after beta3 but I take it that backwards-compatibility-breaking changes are included in this. But maybe it's still OK for us to break code after the beta. Perhaps someone involved in the release can comment on this issue (and hopefully with a view to my array patch - http://bugs.python.org/issue3565 - as well). ___ Python tracker [EMAIL PROTECTED] http://bugs.python.org/issue3613 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue3613] base64.encodestring does not actually accept strings
Guido van Rossum [EMAIL PROTECTED] added the comment: Did someone fix xmlrpc.client:1168 yet? IMO it's okay to add encodebytes(), but let's leave encodestring() around with a deprecation warning, since it's so late in the release cycle. -- nosy: +gvanrossum ___ Python tracker [EMAIL PROTECTED] http://bugs.python.org/issue3613 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com