Renamed "verify" functions to "validate".
Another idea for defining the fields in records would be to create a class method that would instantiate the individual fields at instance creation rather than during class definition. This would use less memory when there are no Record objects being used. Storing each Field after it's instantiated into a List, as well as a Dict would remove the necessity for counting the Field instantiation order, since the List would hold them in their proper order.
This commit is contained in:
parent
ea492c2f56
commit
7772ec679f
2 changed files with 12 additions and 9 deletions
|
@ -1,4 +1,4 @@
|
|||
from fields import Field
|
||||
from fields import Field, ValidationError
|
||||
import copy
|
||||
import pdb
|
||||
|
||||
|
@ -51,8 +51,11 @@ class Model(object):
|
|||
custom_validator(f)
|
||||
|
||||
def output(self):
|
||||
return ''.join([self.record_identifier] + [field.get_data() for field in self.get_sorted_fields()])
|
||||
|
||||
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")
|
||||
return result
|
||||
|
||||
def read(self, fp):
|
||||
for field in self.get_sorted_fields():
|
||||
field.read(fp)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue