tweaking validation

This commit is contained in:
Binh 2013-03-20 15:13:44 -05:00
parent afc4138898
commit d058e64d26

View file

@ -6,6 +6,7 @@ import pdb
class Model(object):
record_identifier = ' '
required = False
record_length = 512
def __init__(self):
for (key, value) in self.__class__.__dict__.items():
@ -52,9 +53,10 @@ class Model(object):
custom_validator(f)
def output(self):
result = ''.join([self.record_identifier] + [field.get_data() for field in self.get_sorted_fields()])
if len(result) != 512:
raise ValidationError("Record result length not equal to 512 bytes (%d)" % len(result))
result = ''.join([self.record_identifier] +
[field.get_data() for field in self.get_sorted_fields()])
if len(result) != self.record_length:
raise ValidationError("Record result length not equal to %d bytes (%d)" % (self.record_length, len(result)))
return result
def read(self, fp):