Default repository for chkcsv.py.
Revision | fd3cad105aa5f0b31b6d0e7558857704d08e5e3b (tree) |
---|---|
Zeit | 2019-01-04 00:20:21 |
Autor | Dreas Nielsen <dnielsen@inte...> |
Commiter | Dreas Nielsen |
Merged formatting changes.
@@ -79,7 +79,7 @@ | ||
79 | 79 | |
80 | 80 | class CsvChecker(): |
81 | 81 | """Create an object to check a specific column of a defined type. |
82 | - | |
82 | + | |
83 | 83 | :param fmt_spec: A ConfigParser object. |
84 | 84 | :param colname: The name of the data column. |
85 | 85 | :param column_required_default: A Boolean indicating whether the column is required by default. |
@@ -192,16 +192,16 @@ | ||
192 | 192 | # Basic format checking functions. These return None if the data are acceptable, |
193 | 193 | # a textual description of the problem otherwise. |
194 | 194 | def chk_req(self, data): |
195 | - return "missing data" if len(data)==0 else None | |
195 | + return "missing data" if len(data) == 0 else None | |
196 | 196 | def chk_min(self, data): |
197 | - return None if (not self.data_required and len(data)==0) or \ | |
197 | + return None if (not self.data_required and len(data) == 0) or \ | |
198 | 198 | len(data) >= self.minlen else "data too short" |
199 | 199 | def chk_max(self, data): |
200 | 200 | return None if len(data) <= self.maxlen else "data too long" |
201 | 201 | def chk_pat(self, data): |
202 | - return None if len(data)==0 or self.rx.match(data) else "pattern mismatch" | |
202 | + return None if len(data) == 0 or self.rx.match(data) else "pattern mismatch" | |
203 | 203 | def chk_int(self, data): |
204 | - if len(data)==0: | |
204 | + if len(data) == 0: | |
205 | 205 | return None |
206 | 206 | try: |
207 | 207 | x = int(data) |
@@ -209,7 +209,7 @@ | ||
209 | 209 | except ValueError: |
210 | 210 | return "not an integer" |
211 | 211 | def chk_float(self, data): |
212 | - if len(data)==0: | |
212 | + if len(data) == 0: | |
213 | 213 | return None |
214 | 214 | try: |
215 | 215 | x = float(data) |
@@ -217,20 +217,20 @@ | ||
217 | 217 | except ValueError: |
218 | 218 | return "not a floating-point number" |
219 | 219 | def chk_bool(self, data): |
220 | - if len(data)==0: | |
220 | + if len(data) == 0: | |
221 | 221 | return None |
222 | 222 | return None if data in (u'True', u'true', u'TRUE', u'T', u't', u'Yes', u'yes', u'YES', u'Y', u'y', |
223 | 223 | u'False', u'false', u'FALSE', u'F', u'f', |
224 | 224 | u'No', u'no', u'NO', u'N', u'n', True, False) else u"unrecognized boolean" |
225 | 225 | def chk_datetime(self, data): |
226 | - if len(data)==0: | |
226 | + if len(data) == 0: | |
227 | 227 | return None |
228 | 228 | if type(data) == type(datetime.datetime.now()): |
229 | 229 | return None |
230 | 230 | if type(data) == type(datetime.date.today()): |
231 | 231 | return None |
232 | 232 | if type(data) != type(""): |
233 | - if data==None: | |
233 | + if data == None: | |
234 | 234 | return "missing date/time" |
235 | 235 | try: |
236 | 236 | data = str(data) |
@@ -328,7 +328,7 @@ | ||
328 | 328 | CSV file name The name of a comma-separated-values file to check.""" |
329 | 329 | vers_msg = "%prog " + "%s %s" % (_version, _vdate) |
330 | 330 | desc_msg = "Checks the content and format of a CSV file." |
331 | - parser = OptionParser(usage=usage_msg, version=vers_msg, description=desc_msg) | |
331 | + parser = OptionParser(usage = usage_msg, version=vers_msg, description = desc_msg) | |
332 | 332 | parser.add_option("-s", "--showspecs", action="store_true", dest="showspecs", |
333 | 333 | default=False, |
334 | 334 | help="Show the format specifications allowed in the configuration file, and exit.") |