@@ -56,21 +56,31 @@ def _convert_fields_to_long_format(self) -> typing.List[Field]:
56
56
return fields
57
57
58
58
def read (self , buf : typing .TextIO , parameter_set : ParameterSet = None ) -> bool :
59
- if not self ._is_active () :
59
+ if not self .active :
60
60
return False
61
61
line , to_exit = read_line (buf )
62
62
if to_exit :
63
63
return True
64
64
self ._load (line , parameter_set )
65
65
return False
66
66
67
+ def _get_format_spec (self , fields ):
68
+ format_spec = []
69
+ for field in fields :
70
+ if field ._is_flag ():
71
+ field_type = field ._value
72
+ else :
73
+ field_type = field .type
74
+ format_spec .append ((field .offset , field .width , field_type ))
75
+ return format_spec
76
+
67
77
def _load (self , data_line : str , parameter_set : ParameterSet ) -> None :
68
78
"""loads the card data from a list of strings"""
69
79
fields = self ._fields
70
80
if self .format == format_type .long :
71
81
fields = self ._convert_fields_to_long_format ()
72
- format = [( field . offset , field . width , field . type ) for field in fields ]
73
- values = load_dataline (format , data_line , parameter_set )
82
+ format_spec = self . _get_format_spec ( fields )
83
+ values = load_dataline (format_spec , data_line , parameter_set )
74
84
num_fields = len (fields )
75
85
for field_index in range (num_fields ):
76
86
self ._fields [field_index ].value = values [field_index ]
@@ -85,15 +95,16 @@ def write(
85
95
format = self ._format_type
86
96
87
97
def _write (buf : typing .TextIO ):
88
- if self ._is_active () :
98
+ if self .active :
89
99
if comment :
90
100
write_comment_line (buf , self ._fields , format )
91
101
buf .write ("\n " )
92
102
write_fields (buf , self ._fields , None , format )
93
103
94
104
return write_or_return (buf , _write )
95
105
96
- def _is_active (self ) -> bool :
106
+ @property
107
+ def active (self ) -> bool :
97
108
if self ._active_func == None :
98
109
return True
99
110
return True if self ._active_func () else False
0 commit comments