From fe619c54e5ec2e10a04e66ea90b4ee5dc04e57b7 Mon Sep 17 00:00:00 2001 From: wan Date: Mon, 1 Jul 2019 10:01:24 +0200 Subject: [PATCH] add support for null values in D, F and L parsing --- dbfread/field_parser.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/dbfread/field_parser.py b/dbfread/field_parser.py index e54ccb2..495d6c6 100644 --- a/dbfread/field_parser.py +++ b/dbfread/field_parser.py @@ -22,7 +22,7 @@ def __repr__(self): # Make sure the string starts with "b'" in # "InvalidValue(b'value here')". text = 'b' + text - + return 'InvalidValue({})'.format(text) class FieldParser: @@ -91,13 +91,13 @@ def parseD(self, field, data): try: return datetime.date(int(data[:4]), int(data[4:6]), int(data[6:8])) except ValueError: - if data.strip(b' 0') == b'': + if data.strip(b' 0\0') == b'': # A record containing only spaces and/or zeros is # a NULL value. return None else: raise ValueError('invalid date {!r}'.format(data)) - + def parseF(self, field, data): """Parse float field and return float or None""" # In some files * is used for padding. @@ -119,7 +119,7 @@ def parseL(self, field, data): return True elif data in b'FfNn': return False - elif data in b'? ': + elif data in b'? \0': return None else: # Todo: return something? (But that would be misleading!) @@ -162,7 +162,7 @@ def parseN(self, field, data): Returns int, float or None if the field is empty. """ # In some files * is used for padding. - data = data.strip().strip(b'*') + data = data.strip().strip(b'*\0') try: return int(data) @@ -211,7 +211,7 @@ def parseT(self, field, data): return None else: return None - + def parseY(self, field, data): """Parse currency field (Y) and return decimal.Decimal.