[SQL-CVS] SQLObject/examples codebits.py,1.2,1.3
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: <ian...@us...> - 2003-09-07 19:14:46
|
Update of /cvsroot/sqlobject/SQLObject/examples In directory sc8-pr-cvs1:/tmp/cvs-serv1609/examples Modified Files: codebits.py Log Message: Added FAQ about binary files Index: codebits.py =================================================================== RCS file: /cvsroot/sqlobject/SQLObject/examples/codebits.py,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** codebits.py 21 Aug 2003 05:02:17 -0000 1.2 --- codebits.py 7 Sep 2003 19:14:43 -0000 1.3 *************** *** 221,222 **** --- 221,248 ---- longitude = property(_get_longitude, set_longitude) ## end snippet + + ## Snippet "image-binary" + class Image(SQLObject): + + data = StringCol() + height = IntCol() + width = IntCol() + + def _set_data(self, value): + self._SO_set_data(value.encode('base64')) + + def _get_data(self, value): + return self._SO_get_data().decode('base64') + ## end snippet + + ## Snippet "image-binary-sqlite" + class Image(SQLObject): + data = StringCol() + + def _set_data(self, value): + # base64 just ignores whitespace, so we can get rid of \n's + self._SO_set_data(value.encode('base64').replace('\n', '')) + + def _get_data(self): + return self._SO_get_data().decode('base64') + ## end snippet |