[Mpuls-commits] r4203 - in base/trunk: . mpulsweb/lib
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Tue Nov 16 20:23:36 CET 2010
Author: bh
Date: 2010-11-16 20:23:34 +0100 (Tue, 16 Nov 2010)
New Revision: 4203
Modified:
base/trunk/ChangeLog
base/trunk/mpulsweb/lib/export.py
Log:
* mpulsweb/lib/export.py: Add a comment explaining the
pyExcelerator kludge for writing to a StringIO instance.
(fake_file): Add a doc-string.
Modified: base/trunk/ChangeLog
===================================================================
--- base/trunk/ChangeLog 2010-11-16 17:35:37 UTC (rev 4202)
+++ base/trunk/ChangeLog 2010-11-16 19:23:34 UTC (rev 4203)
@@ -1,5 +1,11 @@
2010-11-16 Bernhard Herzog <bh at intevation.de>
+ * mpulsweb/lib/export.py: Add a comment explaining the
+ pyExcelerator kludge for writing to a StringIO instance.
+ (fake_file): Add a doc-string.
+
+2010-11-16 Bernhard Herzog <bh at intevation.de>
+
* mpulsweb/lib/export.py (MyStringIO.real_close): Actually call
the real close method, i.e. the one from the base class.
Modified: base/trunk/mpulsweb/lib/export.py
===================================================================
--- base/trunk/mpulsweb/lib/export.py 2010-11-16 17:35:37 UTC (rev 4202)
+++ base/trunk/mpulsweb/lib/export.py 2010-11-16 19:23:34 UTC (rev 4203)
@@ -15,6 +15,12 @@
log = logging.getLogger(__name__)
+# Helpers to work around a problem in pyExcelerator. pyExcelerator can
+# only write to a file that it opens itself using the filename passed to
+# the Workbook.save method. We want the output in a StringIO object,
+# though. To achieve that we override the built-in "file" with the
+# fake_file function defined below in pyExcelerator.CompoundDoc.
+
class MyStringIO(StringIO):
def close(self):
@@ -30,6 +36,12 @@
self.buf = buf
def fake_file(x, *args):
+ """Wrapper around the built-in 'file' which treats FakeStr specially.
+ If the filename argument is an instance of FakeStr, simply return
+ its buf attribute. Otherwise delegate to file. This allows us to
+ pass e.g. a MyStringIO instance to pyExcelerator as a 'filename'
+ when we wrap it in a FakeStr.
+ """
return isinstance(x, FakeStr) and x.buf or file(x, *args)
pyExcelerator.CompoundDoc.file = fake_file
More information about the Mpuls-commits
mailing list