[reportlab-users] Puzzling Error

Robin Becker reportlab-users@reportlab.com
Wed, 6 Nov 2002 10:30:58 +0000


In article <20021105170849.GA4507@mail.librelogiciel.com>, Jerome Alet <alet@librelogiciel.com> writes
.....
......
>Alternatively pdfdoc.py could be modified in a way similar to :
>
>        if hasattr(filename, "isupper") and callable(filename.isupper) :
>            myfile = 1
>            f = open(str(filename), "wb")
>        else :
>            myfile = 0
>            f = filename
>
>this is untested but should work
>
>but there's a similar test in canvas.py in Canvas class's save()
>method so you'll have to modify it there too.
>
......
I'm going to merge the problem into canvas
        def save(self):
                """Saves and close the PDF document in the file.
                   If there is current data a ShowPage is executed automatically.
                   After this operation the canvas must not be used further."""
                if len(self._code): self.showPage()
                self._doc.SaveToFile(self._filename, self)

pdfdoc.SaveToFile
                ......
                if callable(getattr(filename, "write",None)):
                        myfile = 0
                        f = filename
                        filename = str(getattr(filename,'name',''))
                else :
                        myfile = 1
                        filename = str(filename)
                        f = open(filename, "wb")
                txt = self.format()
                f.write(txt)
                if myfile:
                        f.close()
                        markfilename(filename) # do platform specific file junk
                if getattr(canvas,'_verbosity',None): print 'saved', filename


seems to work in 1.5.2
-- 
Robin Becker