equal
deleted
inserted
replaced
132 assert not (required in funcs and optional in funcs), "optional and required checks are exclusive" |
132 assert not (required in funcs and optional in funcs), "optional and required checks are exclusive" |
133 res[dest] = row[src] |
133 res[dest] = row[src] |
134 try: |
134 try: |
135 for func in funcs: |
135 for func in funcs: |
136 res[dest] = func(res[dest]) |
136 res[dest] = func(res[dest]) |
137 if res[dest] is None or res[dest]==False: |
137 if res[dest] is None: |
138 raise AssertionError('undetermined value') |
138 raise AssertionError('undetermined value') |
139 except AssertionError, err: |
139 except AssertionError, err: |
140 if optional in funcs: |
140 if optional in funcs: |
141 # Forget this field if exception is coming from optional function |
141 # Forget this field if exception is coming from optional function |
142 del res[dest] |
142 del res[dest] |
218 |
218 |
219 def strip(txt): |
219 def strip(txt): |
220 return txt.strip() |
220 return txt.strip() |
221 |
221 |
222 def yesno(value): |
222 def yesno(value): |
223 return value.lower()[0] in 'yo1' |
223 """simple heuristic that returns boolean value |
|
224 |
|
225 >>> yesno("Yes") |
|
226 True |
|
227 >>> yesno("oui") |
|
228 True |
|
229 >>> yesno("1") |
|
230 True |
|
231 >>> yesno("11") |
|
232 True |
|
233 >>> yesno("") |
|
234 False |
|
235 >>> yesno("Non") |
|
236 False |
|
237 >>> yesno("blablabla") |
|
238 False |
|
239 """ |
|
240 if value: |
|
241 return value.lower()[0] in 'yo1' |
|
242 return False |
224 |
243 |
225 def isalpha(value): |
244 def isalpha(value): |
226 if value.isalpha(): |
245 if value.isalpha(): |
227 return value |
246 return value |
228 raise AssertionError("not all characters in the string alphabetic") |
247 raise AssertionError("not all characters in the string alphabetic") |