On 10/15/07, Guido van Rossum <[EMAIL PROTECTED]> wrote:
> On 10/15/07, Jim Jewett <[EMAIL PROTECTED]> wrote:
> > On 10/12/07, Guido van Rossum <[EMAIL PROTECTED]> wrote:
> > > On 10/12/07, Gregory P. Smith <[EMAIL PROTECTED]> wrote:
> > > > > > - add missing methods to PyBytes (for list, see the PEP and compare 
> > > > > > to
> > > > > > what's already there)
> >
> > > > As I work on these..  Should the mutable PyBytes_ (buffer) objects 
> > > > implement
> > > > the following methods inplace and return an additional reference to 
> > > > self?
> >
> > > > .capitalize(), .center(), .expandtabs(), .rjust(), .swapcase(), 
> > > > .title(),
> > > > .upper(), .zfill()
> >
> > > No... That would be a huge trap to fall in at all sorts of occasions.
> >
> > So would returning a different object.  I expect a mutation operation
> > on an explicitly mutable object to mutate the object, instead of
> > creating something new.
> >
> > If it returns a new one, I can imagine doing something like:
> >
> >     obj.inqueue=bytesbuffer(100)
> >     obj.inqueue.lower()   # oh, wait, that didn't really do anything
> > after all...
> >     if obj.inqueue[:4] == b"http":   # works on my *regular* input...
> >
> > Maybe the answer is "don't do that", and to only do this sort of
> > processing before it goes in the buffer or after it comes out, but ...
> > it still looks like a major gotcha.
>
> Since these methods with these very names already exist for strings
> and return new values there, I don't see the gotcha unless you never
> use strings.

Maybe .lower() should return immutable bytes, rather than mutable
buffer?  For the use cases I can imagine this'd still work correctly,
and fits better with why it makes a copy.  buffer is all about
operating in-place, so any copy immediately doesn't fit the buffer
concept.

    obj.inqueue = bytesbuffer(100)
    # replaces existing buffer contents.  Temp copy need not be mutable
    obj.inqueue[:] = obj.inqueue.lower()
    if obj.inqueue[:4] == b"http":


    obj.inqueue = bytesbuffer(100)
    if obj.inqueue[:4].lower() == b"http":  # compares bytes with bytes

-- 
Adam Olsen, aka Rhamphoryncus
_______________________________________________
Python-3000 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-3000
Unsubscribe: 
http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com

Reply via email to