[Python-bugs-list] [ python-Bugs-546434 ] buffer slice type inconsistant
noreply@sourceforge.net
noreply@sourceforge.net
Sat, 20 Apr 2002 00:36:18 -0700
Bugs item #546434, was opened at 2002-04-20 03:21
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=546434&group_id=5470
Category: Python Interpreter Core
Group: Python 2.2.1 candidate
Status: Open
Resolution: None
Priority: 5
Submitted By: Donald Wallace Rouse II (dwr2)
Assigned to: Nobody/Anonymous (nobody)
Summary: buffer slice type inconsistant
Initial Comment:
The type of a buffer slice is either 'buffer'
or 'str', depending on the slice parameters.
If the slice encompasses the entire buffer, the buffer
itself is returned.
Otherwise, a string is returned.
Here is a sample session:
--------------------------
Python 2.2.1 (#34, Apr 9 2002, 19:34:33) [MSC 32 bit
(Intel)] on win32
Type "copyright", "credits" or "license" for more
information.
IDLE 0.8 -- press F1 for help
>>> a="0123456789"
>>> b = buffer(a, 1, 8)
>>> b
<read-only buffer for 0x0079B4B0, ptr 0x0079B4C5, size
8 at 0x00A99F30>
>>> b[:]
<read-only buffer for 0x0079B4B0, ptr 0x0079B4C5, size
8 at 0x00A99F30>
>>> b[:8]
<read-only buffer for 0x0079B4B0, ptr 0x0079B4C5, size
8 at 0x00A99F30>
>>> b[2:4]
'34'
>>> b[5]
'6'
>>> c = buffer(a, 4, 1)
>>> c
<read-only buffer for 0x0079B4B0, ptr 0x0079B4C8, size
1 at 0x00AAA370>
>>> c[0]
'4'
>>> c[0:1]
<read-only buffer for 0x0079B4B0, ptr 0x0079B4C8, size
1 at 0x00AAA370>
--------------------------
Either b[:] should produce a string, or, more
preferably, b[x:y] should be equivalent to buffer(b,
x, y), and c[0] should be equivalent to buffer(c, 0,
1).
The reason that the types should be similar is because
if a buffer is passed to a function that's checking
for strings, the function should always fail or always
succeed.
This is especially important because types.BufferType
isn't in the types.StringTypes list, so the
expression "type(b) in types.StringTypes" will also
behave inconsistantly.
----------------------------------------------------------------------
>Comment By: Donald Wallace Rouse II (dwr2)
Date: 2002-04-20 03:36
Message:
Logged In: YES
user_id=111611
Sorry about the formatting; the form wrapped the lines.
A slight correction:
"b[x:y] should be equivalent to buffer(b, x, y)"
should be
"b[x:y] should be equivalent to buffer(b, x1, y1 - x1),
where x1 == x if x is positive and len(b) + x if x is
negative, and similarly for y and y1".
----------------------------------------------------------------------
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=546434&group_id=5470