From: alexander s. <a1...@us...> - 2007-02-11 09:08:26
|
Update of /cvsroot/dbfpy/dbfpy/dbfpy In directory sc8-pr-cvs12.sourceforge.net:/tmp/cvs-serv12619 Modified Files: fields.py Log Message: handle value conversion errors Index: fields.py =================================================================== RCS file: /cvsroot/dbfpy/dbfpy/dbfpy/fields.py,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** fields.py 10 Feb 2007 19:36:52 -0000 1.9 --- fields.py 11 Feb 2007 09:08:11 -0000 1.10 *************** *** 5,8 **** --- 5,9 ---- """ """History (most recent first): + 11-feb-2007 [als] handle value conversion errors 10-feb-2007 [als] DbfFieldDef: added .rawFromRecord() 01-dec-2006 [als] Timestamp columns use None for empty values *************** *** 51,55 **** """ ! __slots__ = "name", "length", "decimalCount", "start", "end" # length of the field, None in case of variable-length field, --- 52,57 ---- """ ! __slots__ = ("name", "length", "decimalCount", ! "start", "end", "ignoreErrors") # length of the field, None in case of variable-length field, *************** *** 67,71 **** def __init__(self, name, length=None, decimalCount=None, ! start=None, stop=None ): """Initialize instance.""" --- 69,73 ---- def __init__(self, name, length=None, decimalCount=None, ! start=None, stop=None, ignoreErrors=False, ): """Initialize instance.""" *************** *** 91,94 **** --- 93,97 ---- self.length = length self.decimalCount = decimalCount + self.ignoreErrors = ignoreErrors self.start = start self.end = stop *************** *** 100,104 **** return hash(self.name) ! def fromString(cls, string, start): """Decode dbf field definition from the string data. --- 103,107 ---- return hash(self.name) ! def fromString(cls, string, start, ignoreErrors=False): """Decode dbf field definition from the string data. *************** *** 109,117 **** start: position in the database file. """ assert len(string) == 32 _length = ord(string[16]) return cls(utils.unzfill(string)[:11], _length, ord(string[17]), ! start, start + _length) fromString = classmethod(fromString) --- 112,123 ---- start: position in the database file. + ignoreErrors: + initial error processing mode for the new field (boolean) + """ assert len(string) == 32 _length = ord(string[16]) return cls(utils.unzfill(string)[:11], _length, ord(string[17]), ! start, start + _length, ignoreErrors=ignoreErrors) fromString = classmethod(fromString) *************** *** 157,169 **** def decodeFromRecord(self, record): """Return decoded field value from the record string.""" ! return self.decodeValue(self.rawFromRecord(record)) def decodeValue(self, value): """Return decoded value from string value. ! This method shouldn't be used publicaly. It's called from the `decodeFromRecord` method. ! This is an abstract method and it must be overriden in child classes. """ raise NotImplementedError --- 163,181 ---- def decodeFromRecord(self, record): """Return decoded field value from the record string.""" ! try: ! return self.decodeValue(self.rawFromRecord(record)) ! except: ! if self.ignoreErrors: ! return utils.INVALID_VALUE ! else: ! raise def decodeValue(self, value): """Return decoded value from string value. ! This method shouldn't be used publicly. It's called from the `decodeFromRecord` method. ! This is an abstract method and it must be overridden in child classes. """ raise NotImplementedError |