Message2373

Author nobody
Recipients
Date 2004-03-07.05:10:42
SpamBayes Score
Marked as misclassified
Message-id
In-reply-to
Content
re:
http://sourceforge.net/tracker/index.php?func=detail&aid=674932&group_id=12867&atid=112867

[Note, this patch creates a new package,
core.printhelper.  cvs diff doesn't
include these so I've had to create the patch as a zip
file incorporating these
files with the diffed patch file.]

There's a couple problems with the code involved here.
 First, Py.print
is wrapping the file target in a new FixedFileWrapper
with _each_ call
to print.  Second, StdoutWrapper, the base class of
FFW, flushes after
each write as Samuele suspected.

   - The main fix is that StdoutWrapper should inherit
from a base
   class.  The base class will never call flush(), but
Stdout will
   continue to do so.

   - renamed these *Wrapper classes to *PrintHelper
classes, because
   PyFile uses FileWrapper classes to mean something
different.  So
   there are the base (abstract) PrintHelper class,
   FixedFilePrintHelper, StdoutPrintHelper, and
   StderrPrintHelper.

   - PrintHelper now has static helper methods to avoid
code
   duplication, e.g. instead of

     public static void print(PyObject file, PyObject o) {
         if (file == None)
             print(o);
         else
             new FixedFileWrapper(file).print(o);
     }

     it now reads

     public static void print(PyObject file, PyObject o) {
         PrintHelper.getPrintHelper(file).print(o);
     }

   - getPrintHelper allows us to cache PrintHelper
objects so that a loop
that does 1000 prints to a file won't create 1000
PrintHelper wrappers.
Caching uses WeakHashMap so GC behavior is unchanged.
History
Date User Action Args
2008-02-20 17:18:24adminlinkissue911242 messages
2008-02-20 17:18:24admincreate