[odf-devel] bug in addPicture
Søren Roug
soren.roug at eea.europa.eu
Sat Mar 21 04:06:49 EDT 2009
Hello Toon,
Thanks for the bug fix. It was already pointed out a few months ago and a patch
released, that you apparently didn't see.
I like your idea of splitting up the addPicture method and will introduce it
into the product.
B.t.w. a few days ago I silently released version 0.9, that uses the ODF 1.1
standard. You can download it from http://forge.osor.eu/frs/?group_id=33 or
the Python package index.
I intend to post an announcement about it this weekend.
/Søren Roug
Lørdag 21 marts 2009 06:52:43 skrev Toon Verstraelen:
> Hi,
>
> I've been using odfpy-0.8 to generate supporting information for a
> scientific paper. These documents typically contain a lot of pictures
> and data that one does not want to enter by hand. I ran into a bug when
> adding a picture based on a filename:
>
> Traceback (most recent call last):
> File "../../bin/supinf.py", line 59, in <module>
> href = doc.addPicture(fn)
> File "/usr/local//lib/python2.5/site-packages/odf/opendocument.py",
> line 290, in addPicture
> self.Pictures[manifestfn] = (IS_FILENAME, fileobj, mediatype)
> NameError: global name 'fileobj' is not defined
>
> It was easy to fix: fileobj must simply be replaced by filename on line
> 290. However, I do find the addPicture method very confusing and the
> document string talks about file objects that are nowhere in the code. I
> suggest to split the method into two different ones, see below. That
> makes the code at least understandable.
>
> best regards,
>
> Toon
>
>
>
> def addPicture(self, filename, mediatype=None):
> """ Add a picture
> It uses the same convention as OOo, in that it saves the
> picture in
> the zipfile in the subdirectory 'Pictures'.
> If mediatype is not given, it will be guessed from the
> filename
> extension.
> """
> if mediatype is None:
> mediatype, encoding = mimetypes.guess_type(filename)
> if mediatype is None:
> mediatype = ''
> try: ext = filename[filename.rindex('.'):]
> except ValueError: ext=''
> else:
> ext = mimetypes.guess_extension(mediatype)
> manifestfn = "Pictures/%0.0f%s" % ((time.time()*10000000000),
> ext) self.Pictures[manifestfn] = (IS_FILENAME, filename, mediatype) return
> manifestfn
>
> def addPictureString(self, content, mediatype):
> """ Add a picture
> It uses the same convention as OOo, in that it saves the
> picture in
> the zipfile in the subdirectory 'Pictures'. The content
> variable
> is a string that contains the binary image data. The
> mediatype indicates the image format.
> """
> ext = mimetypes.guess_extension(mediatype)
> manifestfn = "Pictures/%0.0f%s" % ((time.time()*10000000000),
> ext) self.Pictures[manifestfn] = (IS_IMAGE, content, mediatype) return
> manifestfn
>
>
>
> _______________________________________________
> odf-devel mailing list
> odf-devel at opendocumentfellowship.com
> http://lists.opendocumentfellowship.com/mailman/listinfo/odf-devel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.opendocumentfellowship.com/pipermail/odf-devel/attachments/20090321/2880ae0c/attachment.htm
More information about the odf-devel
mailing list