34 return self.options_dict.keys()
56 error_msgs = test_fcn(cd_str)
58 errors.extend(error_msgs)
67 Code.__init__(self, options_dict)
72 tests = Code.get_tests(self)
74 def char_test(cd_str):
77 invalid_re =
'[^%s]' % ( reduce(
lambda accum, key: accum + key, self.options_dict.keys()) )
78 it = re.finditer(invalid_re, cd_str)
82 for i
in range(len(matches)):
83 invalid_cds +=
'"' + matches[i].group() +
'"'
84 if i < len(matches) - 1:
87 errors.append(
'Invalid code character(s): %s' % (invalid_cds))
95 errors.append(
'This code should not contain more than one character.')
99 tests.extend([char_test, len_test])
107 Code.__init__(self, options_dict)
112 tests = Code.get_tests(self)
114 def char_test(cd_str):
117 invalid_re =
r'[^%s0-9]' % ( reduce(
lambda accum, key: accum + key, self.options_dict.keys()) )
118 it = re.finditer(invalid_re, cd_str)
121 invalid_re2 =
r'([^IC][0-9]+)'
122 it2 = re.finditer(invalid_re2, cd_str)
128 if matches
is not None:
129 all_matches.extend(matches)
130 if matches2
is not None:
131 all_matches.extend(matches2)
135 for i
in range(len(all_matches)):
136 invalid_cds +=
'"' + all_matches[i].group() +
'"'
137 if i < len(all_matches) - 1:
140 errors.append(
'Invalid code character(s): %s' % (invalid_cds))
145 def freq_test(cd_str):
149 if c
in freq_dict
and not c.isdigit():
150 errors.append(
'Code contains more than one "%c".' % c)
158 def link_test(cd_str):
160 if 'U' in cd_str and 'F' in cd_str and ('I' in cd_str or 'C' in cd_str):
161 errors.append(
'Codes containing U and F may not contain C or I')
166 tests.extend([char_test, freq_test, link_test])