Re: [Python-Dev] Why can't I encode/decode base64 without importing a module?

2013-04-22 Thread Greg Ewing
Steven D'Aprano wrote: - If it is no burden to have to import a module and call an external function for some transformations, why have encode and decode methods at all? Now that all text strings are unicode, the unicode codecs are in a sense special, in that you can't do any string I/O at all

Re: [Python-Dev] Why can't I encode/decode base64 without importing a module?

2013-04-22 Thread Fábio Santos
Using decode() and encode() would break that predictability. But someone suggested the use of transform() and untransform() instead. That would clarify that the transformation is bytes > bytes and Unicode string > Unicode string. On 23 Apr 2013 05:50, "Lennart Regebro" wrote: > On Tue, Apr 23, 20

Re: [Python-Dev] Why can't I encode/decode base64 without importing a module?

2013-04-22 Thread Lennart Regebro
On Tue, Apr 23, 2013 at 4:04 AM, Steven D'Aprano wrote: > As others have pointed out in the past, repeatedly, the codec system is > completely general and can transform bytes->bytes and text->text just as > easily as bytes<->text. Yes, but the encode()/decode() methods are not, and the fact that

Re: [Python-Dev] Why can't I encode/decode base64 without importing a module?

2013-04-22 Thread Guido van Rossum
On Mon, Apr 22, 2013 at 7:04 PM, Steven D'Aprano wrote: > As others have pointed out in the past, repeatedly, the codec system is > completely general and can transform bytes->bytes and text->text just as > easily as bytes<->text. Or indeed any bijection, as the docs for 2.7 point > out. The quest

Re: [Python-Dev] Why can't I encode/decode base64 without importing a module?

2013-04-22 Thread Donald Stufft
On Apr 22, 2013, at 10:04 PM, Steven D'Aprano wrote: > On 23/04/13 09:16, Greg Ewing wrote: >> Victor Stinner wrote: >>> The last proposition is to add transform() and untransform() methods >>> to bytes and str types. ... If I remember >>> correctly, the missing point is how to define which type

Re: [Python-Dev] Why can't I encode/decode base64 without importing a module?

2013-04-22 Thread Steven D'Aprano
On 23/04/13 09:16, Greg Ewing wrote: Victor Stinner wrote: The last proposition is to add transform() and untransform() methods to bytes and str types. ... If I remember correctly, the missing point is how to define which types are supported by a codec Also, for any given codec, which directio

Re: [Python-Dev] Why can't I encode/decode base64 without importing a module?

2013-04-22 Thread Guido van Rossum
--Guido van Rossum (sent from Android phone) On Apr 22, 2013 6:09 PM, "R. David Murray" wrote: > > On Tue, 23 Apr 2013 11:16:20 +1200, Greg Ewing < greg.ew...@canterbury.ac.nz> wrote: > > Victor Stinner wrote: > > > The last proposition is to add transform() and untransform() methods > > > to byte

Re: [Python-Dev] Why can't I encode/decode base64 without importing a module?

2013-04-22 Thread R. David Murray
On Tue, 23 Apr 2013 11:16:20 +1200, Greg Ewing wrote: > Victor Stinner wrote: > > The last proposition is to add transform() and untransform() methods > > to bytes and str types. ... If I remember > > correctly, the missing point is how to define which types are > > supported by a codec > > Also

Re: [Python-Dev] Why can't I encode/decode base64 without importing a module?

2013-04-22 Thread Greg Ewing
Victor Stinner wrote: The last proposition is to add transform() and untransform() methods to bytes and str types. ... If I remember correctly, the missing point is how to define which types are supported by a codec Also, for any given codec, which direction is "transform" and which is "untrans

Re: [Python-Dev] cpython: Simplify the code of get_attrib_from_keywords somewhat.

2013-04-22 Thread Eli Bendersky
On Mon, Apr 22, 2013 at 10:13 AM, Serhiy Storchaka wrote: > On 22.04.13 15:52, eli.bendersky wrote: > >> http://hg.python.org/cpython/**rev/c9674421d78e >> changeset: 83494:c9674421d78e >> user:Eli Bendersky >> date:Mon Apr 22 05:52

Re: [Python-Dev] cpython: Simplify the code of get_attrib_from_keywords somewhat.

2013-04-22 Thread Serhiy Storchaka
On 22.04.13 15:52, eli.bendersky wrote: http://hg.python.org/cpython/rev/c9674421d78e changeset: 83494:c9674421d78e user:Eli Bendersky date:Mon Apr 22 05:52:16 2013 -0700 summary: Simplify the code of get_attrib_from_keywords somewhat. -PyDict_DelItem(kwds, attrib

Re: [Python-Dev] Why can't I encode/decode base64 without importing a module?

2013-04-22 Thread R. David Murray
On Mon, 22 Apr 2013 09:50:14 -0400, Devin Jeanpierre wrote: > On Mon, Apr 22, 2013 at 7:39 AM, Calvin Spealman wrote: > > if two lines is cumbersome, you're in for a cumbersome life a programmer. > > Other encodings are either missing completely from the stdlib, or have > corrupted behavior. Fo

Re: [Python-Dev] Why can't I encode/decode base64 without importing a module?

2013-04-22 Thread Stephen J. Turnbull
Devin Jeanpierre writes: > why does 'abc'.encode('unicode_escape') return bytes? Duck-typing: encode always turns unicode into bytes. ___ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: ht

Re: [Python-Dev] Why can't I encode/decode base64 without importing a module?

2013-04-22 Thread Oleg Broytman
On Mon, Apr 22, 2013 at 09:50:14AM -0400, Devin Jeanpierre wrote: > unicode_escape doesn't make any sense anymore -- python code is text, > not bytes, so why does 'abc'.encode('unicode_escape') return bytes? AFAIU the situation is simple: unicode.encode(encoding) returns bytes, bytes.decode(e

Re: [Python-Dev] Why can't I encode/decode base64 without importing a module?

2013-04-22 Thread Devin Jeanpierre
On Mon, Apr 22, 2013 at 7:39 AM, Calvin Spealman wrote: > if two lines is cumbersome, you're in for a cumbersome life a programmer. Other encodings are either missing completely from the stdlib, or have corrupted behavior. For example, string_escape is gone, and unicode_escape doesn't make any se

Re: [Python-Dev] Why can't I encode/decode base64 without importing a module?

2013-04-22 Thread Paul Moore
On 22 April 2013 12:39, Calvin Spealman wrote: > if two lines is cumbersome, you're in for a cumbersome life a programmer. > One of which is essentially Python's equivalent of a declaration... Paul ___ Python-Dev mailing list Python-Dev@python.org http

Re: [Python-Dev] Why can't I encode/decode base64 without importing a module?

2013-04-22 Thread Calvin Spealman
if two lines is cumbersome, you're in for a cumbersome life a programmer. On Apr 22, 2013 7:31 AM, "Ram Rachum" wrote: > Hi everyone, > > Take a look at this question: > > > http://stackoverflow.com/questions/16122435/python-3-how-do-i-use-bytes-to-bytes-and-string-to-string-encodings/16122472?no

Re: [Python-Dev] Why can't I encode/decode base64 without importing a module?

2013-04-22 Thread Victor Stinner
Hi, Your question is discussed since 4 years in the following issue: http://bugs.python.org/issue7475 The last proposition is to add transform() and untransform() methods to bytes and str types. But nobody implemented the idea. If I remember correctly, the missing point is how to define which typ

[Python-Dev] Why can't I encode/decode base64 without importing a module?

2013-04-22 Thread Ram Rachum
Hi everyone, Take a look at this question: http://stackoverflow.com/questions/16122435/python-3-how-do-i-use-bytes-to-bytes-and-string-to-string-encodings/16122472?noredirect=1#comment23034787_16122472 Is there really no way to use base64 that's as short as: b'whatever'.encode('base64') Be