Better layout handling in pyrocket

This commit is contained in:
Jim Paris 2013-03-03 13:34:43 -05:00
parent 4406d51a98
commit 402234dfc3

View File

@ -8,8 +8,13 @@ class Rocket(object):
# For packing/unpacking into a binary file.
# This will change in the C version
(self.ltype, lcount) = layout.split('_', 2)
self.lcount = int(lcount)
try:
(self.ltype, lcount) = layout.split('_', 2)
self.lcount = int(lcount)
except:
raise ValueError("no such layout: badly formatted string")
if self.lcount < 1:
raise ValueError("no such layout: bad count")
try:
struct_fmt = '<d' # Little endian, double timestamp
struct_mapping = {
@ -26,7 +31,7 @@ class Rocket(object):
}
struct_fmt += struct_mapping[self.ltype] * self.lcount
except KeyError:
raise ValueError("no such layout, or bad data types")
raise ValueError("no such layout: bad data type")
self.packer = struct.Struct(struct_fmt)
@property