[Python-bugs-list] [ python-Bugs-210845 ] struct.pack not being very picky (PR#52)
noreply@sourceforge.net
noreply@sourceforge.net
Thu, 18 Jul 2002 02:18:33 -0700
Bugs item #210845, was opened at 2000-08-01 21:15
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=210845&group_id=5470
Category: Extension Modules
Group: Feature Request
Status: Closed
Resolution: Fixed
Priority: 5
Submitted By: Nobody/Anonymous (nobody)
Assigned to: David Ascher (david_ascher)
Summary: struct.pack not being very picky (PR#52)
Initial Comment:
Jitterbug-Id: 52
Submitted-By: da@ski.org
Date: Sun, 15 Aug 1999 17:52:20 -0400 (EDT)
Version: 1.5.2
OS: NT4SP3
>>> from struct import *
>>> struct.pack('B', -12)
'\364'
I expected a ValueError, the way:
>>> struct.pack('c', 123)
Traceback (innermost last):
File "<stdin>", line 1, in ?
struct.error: char format require string of length 1
works.
====================================================================
Audit trail:
Mon Aug 30 12:33:11 1999 guido moved from incoming to request
----------------------------------------------------------------------
Comment By: Armin Rigo (arigo)
Date: 2002-07-18 09:18
Message:
Logged In: YES
user_id=4771
I am afraid the fix only makes struct.pack() a little bit
more inconsistent than it already was. On Python 2.2, on a
Linux PC:
struct.pack('B', -1) -> struct.error
struct.pack('H', -1) -> struct.error
struct.pack('I', -1) -> '\xff\xff\xff\xff'
struct.pack('L', -1) -> '\xff\xff\xff\xff'
struct.pack('Q', -1) -> TypeError
struct.pack('B', -1L) -> struct.error
struct.pack('H', -1L) -> struct.error
struct.pack('I', -1L) -> OverflowError
struct.pack('L', -1L) -> OverflowError
struct.pack('Q', -1L) -> TypeError
struct.pack('=B', -1) -> '\xff'
struct.pack('=H', -1) -> '\xff\xff'
struct.pack('=I', -1) -> '\xff\xff\xff\xff'
struct.pack('=L', -1) -> '\xff\xff\xff\xff'
struct.pack('=Q', -1) -> TypeError
struct.pack('=B', -1L) -> '\xff'
struct.pack('=H', -1L) -> OverflowError
struct.pack('=I', -1L) -> OverflowError
struct.pack('=L', -1L) -> OverflowError
struct.pack('=Q', -1L) -> TypeError
Note that even -1 and -1L behave differently. And when an
exception is
raised, it can be TypeError, OverflowError or struct.error,
with a bunch
of different error messages.
Finally, some format characters accept (and truncate)
completely
out-of-bound values (for example, '=H' accepts all int
objects, as well
as all long objects that fit a C *unsigned int*).
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=210845&group_id=5470