From: alexander s. <a1...@us...> - 2007-02-11 08:57:38
|
Update of /cvsroot/dbfpy/dbfpy/dbfpy In directory sc8-pr-cvs12.sourceforge.net:/tmp/cvs-serv8683 Modified Files: utils.py Log Message: added INVALID_VALUE Index: utils.py =================================================================== RCS file: /cvsroot/dbfpy/dbfpy/dbfpy/utils.py,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** utils.py 10 Feb 2007 19:00:37 -0000 1.3 --- utils.py 11 Feb 2007 08:57:17 -0000 1.4 *************** *** 5,8 **** --- 5,9 ---- """ """History (most recent first): + 11-feb-2007 [als] added INVALID_VALUE 10-feb-2007 [als] allow date strings padded with spaces instead of zeroes 20-dec-2005 [yc] handle long objects in getDate/getDateTime *************** *** 125,127 **** --- 126,170 ---- + class _InvalidValue(object): + + """Value returned from DBF records when field validation fails + + The value is not equal to anything except for itself + and equal to all empty values: None, 0, empty string etc. + In other words, invalid value is equal to None and not equal + to None at the same time. + + This value yields zero upon explicit conversion to a number type, + empty string for string types, and False for boolean. + + """ + + def __eq__(self, other): + return not other + + def __ne__(self, other): + return not (other is self) + + def __nonzero__(self): + return False + + def __int__(self): + return 0 + __long__ = __int__ + + def __float__(self): + return 0.0 + + def __str__(self): + return "" + + def __unicode__(self): + return u"" + + def __repr__(self): + return "<INVALID>" + + # invalid value is a constant singleton + INVALID_VALUE = _InvalidValue() + # vim: set et sts=4 sw=4 : |