summaryrefslogtreecommitdiff
path: root/qpid/python
diff options
context:
space:
mode:
authorKenneth Anthony Giusti <kgiusti@apache.org>2010-10-28 21:33:52 +0000
committerKenneth Anthony Giusti <kgiusti@apache.org>2010-10-28 21:33:52 +0000
commit7da23f2ec7b60e6a68e0a735b7aa3e1910605ffd (patch)
tree12d8dfc445e2ed1732d19fddeb77006fe61c39d8 /qpid/python
parenta6bb93082956780c68c34a0f44a73911a463ae42 (diff)
downloadqpid-python-7da23f2ec7b60e6a68e0a735b7aa3e1910605ffd.tar.gz
QPID-2916: throw an exception when a data value cannot be encoded correctly as its type.
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1028501 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/python')
-rw-r--r--qpid/python/qpid/codec010.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/qpid/python/qpid/codec010.py b/qpid/python/qpid/codec010.py
index 5ad1ef14c1..0846db6bf7 100644
--- a/qpid/python/qpid/codec010.py
+++ b/qpid/python/qpid/codec010.py
@@ -85,11 +85,15 @@ class Codec(Packer):
def read_uint8(self):
return self.unpack("!B")
def write_uint8(self, n):
+ if n < 0 or n > 255:
+ raise CodecException("Cannot encode %d as uint8" % n)
return self.pack("!B", n)
def read_int8(self):
return self.unpack("!b")
def write_int8(self, n):
+ if n < -128 or n > 127:
+ raise CodecException("Cannot encode %d as int8" % n)
self.pack("!b", n)
def read_char(self):
@@ -108,22 +112,30 @@ class Codec(Packer):
def read_uint16(self):
return self.unpack("!H")
def write_uint16(self, n):
+ if n < 0 or n > 65535:
+ raise CodecException("Cannot encode %d as uint16" % n)
self.pack("!H", n)
def read_int16(self):
return self.unpack("!h")
def write_int16(self, n):
+ if n < -32768 or n > 32767:
+ raise CodecException("Cannot encode %d as int16" % n)
self.pack("!h", n)
def read_uint32(self):
return self.unpack("!L")
def write_uint32(self, n):
+ if n < 0 or n > 4294967295:
+ raise CodecException("Cannot encode %d as uint32" % n)
self.pack("!L", n)
def read_int32(self):
return self.unpack("!l")
def write_int32(self, n):
+ if n < -2147483648 or n > 2147483647:
+ raise CodecException("Cannot encode %d as int32" % n)
self.pack("!l", n)
def read_float(self):