[issue2415] bytes() should respect __bytes__

2008-08-26 Thread Benjamin Peterson

Benjamin Peterson <[EMAIL PROTECTED]> added the comment:

Thanks for the review, Barry! Committed in r66038. Sort of backported in
r66039 by aliasing PyObject_Bytes to PyObject_Str.

--
resolution:  -> fixed
status: open -> closed

___
Python tracker <[EMAIL PROTECTED]>

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue2415] bytes() should respect __bytes__

2008-08-26 Thread Barry A. Warsaw

Barry A. Warsaw <[EMAIL PROTECTED]> added the comment:

yep, that's all i meant.  it might not be worth it though.

___
Python tracker <[EMAIL PROTECTED]>

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue2415] bytes() should respect __bytes__

2008-08-26 Thread Antoine Pitrou

Antoine Pitrou <[EMAIL PROTECTED]> added the comment:

> Should __bytes__ support be backported to 2.6?

Isn't it already there in __str__?
Or do you mean just add support for the alternate method name?

___
Python tracker <[EMAIL PROTECTED]>

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue2415] bytes() should respect __bytes__

2008-08-26 Thread Barry A. Warsaw

Barry A. Warsaw <[EMAIL PROTECTED]> added the comment:

Well, if I figured out how to use Rietveld correctly, I've left some
questions for you in the review.  It looks basically pretty good, so if
you could answer those questions, you can commit the change.

Should __bytes__ support be backported to 2.6?

___
Python tracker <[EMAIL PROTECTED]>

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue2415] bytes() should respect __bytes__

2008-08-21 Thread Benjamin Peterson

Benjamin Peterson <[EMAIL PROTECTED]> added the comment:

Well, yes I suppose. However, I think it's a serious enough deficiency
that it should block. I'll let Barry decide, though.

--
assignee:  -> barry

___
Python tracker <[EMAIL PROTECTED]>

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue2415] bytes() should respect __bytes__

2008-08-21 Thread Antoine Pitrou

Antoine Pitrou <[EMAIL PROTECTED]> added the comment:

Isn't it a new feature and, therefore, should wait for 3.1?

--
nosy: +pitrou

___
Python tracker <[EMAIL PROTECTED]>

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue2415] bytes() should respect __bytes__

2008-08-21 Thread Benjamin Peterson

Changes by Benjamin Peterson <[EMAIL PROTECTED]>:


--
keywords: +needs review

___
Python tracker <[EMAIL PROTECTED]>

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue2415] bytes() should respect __bytes__

2008-08-21 Thread Benjamin Peterson

Benjamin Peterson <[EMAIL PROTECTED]> added the comment:

Here's a patch. It's only implemented for bytes. Doing this for
bytearray would require a bit of refactoring, and can I think wait for
3.1. I added two new C functions. PyObject_Bytes and PyBytes_FromObject.
You can review it at http://codereview.appspot.com/3245.

--
keywords: +patch
Added file: http://bugs.python.org/file11194/2415.diff

___
Python tracker <[EMAIL PROTECTED]>

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue2415] bytes() should respect __bytes__

2008-08-21 Thread Benjamin Peterson

Changes by Benjamin Peterson <[EMAIL PROTECTED]>:


--
priority: normal -> release blocker

___
Python tracker <[EMAIL PROTECTED]>

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue2415] bytes() should respect __bytes__

2008-03-19 Thread Benjamin Peterson

Benjamin Peterson <[EMAIL PROTECTED]> added the comment:

I took a quick glance at this. It hinges on how the C-API is going to
look. Currently, bytes is known in C as PyString and gets it's
representation from __str__. Although we could just change it to
__bytes__, Christian has said that he is going to rename it to PyBytes
(and what is now PyBytes -> PyByteArray). [1] Further muddying the
waters is the fact that PyObject_Str generates the unicode
representation of an object and should really be called PyObject_Unicode.

[1] http://mail.python.org/pipermail/python-3000/2008-March/012477.html

--
nosy: +benjamin.peterson, tiran

__
Tracker <[EMAIL PROTECTED]>

__
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue2415] bytes() should respect __bytes__

2008-03-18 Thread Barry A. Warsaw

New submission from Barry A. Warsaw <[EMAIL PROTECTED]>:

The bytes() builtin should respect an __bytes__() converter if it exists.
E.g. instead of

>>> class Foo:
...  def __bytes__(self): return b'foo'
... 
>>> bytes(Foo())
Traceback (most recent call last):
  File "", line 1, in 
TypeError: 'Foo' object is not iterable
>>> 

bytes(Foo()) should return b'foo'

Here's one use case.  email.header.Header instances represent email headers
(naturally) that conceptually are bytes, but also have a string
representation.  Say for example, a Subject header comes across the wire in
RFC 2033 encoded utf-8.  The unicode representation would be the value
of the
header decoded according to the RFC.  The bytes representation would be the
raw bytes seen on the wire.

The most natural way to retrieve each representation would be

>>> header = msg['subject']
>>> str(header)
'some string with non-ascii'
>>> bytes(header)
b'the rfc 2033 encoded raw header value'

--
components: Interpreter Core
messages: 64027
nosy: barry
priority: normal
severity: normal
status: open
title: bytes() should respect __bytes__
type: feature request
versions: Python 3.0

__
Tracker <[EMAIL PROTECTED]>

__
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com