Back to index

moin  1.9.0~rc2
application_vnd_oasis_opendocument.py
Go to the documentation of this file.
00001 # -*- coding: iso-8859-1 -*-
00002 """
00003     MoinMoin - OpenOffice.org 2.0 *.od? Filter (OpenDocument)
00004 
00005     Depends on: nothing (only python with zlib)
00006 
00007     @copyright: 2006-2009 MoinMoin:ThomasWaldmann
00008     @license: GNU GPL, see COPYING for details.
00009 """
00010 
00011 import re, zipfile
00012 
00013 from MoinMoin import log
00014 logging = log.getLogger(__name__)
00015 
00016 rx_stripxml = re.compile("<[^>]*?>", re.DOTALL|re.MULTILINE)
00017 
00018 def execute(indexobj, filename):
00019     try:
00020         zf = zipfile.ZipFile(filename, "r")
00021         data = zf.read("content.xml")
00022         zf.close()
00023         data = " ".join(rx_stripxml.sub(" ", data).split())
00024     except (zipfile.BadZipfile, RuntimeError), err:
00025         logging.error("%s [%s]" % (str(err), filename))
00026         data = ""
00027     try:
00028         data = data.decode('utf-8')
00029     except UnicodeDecodeError:
00030         # protected with password? no valid OpenDocument file?
00031         data = u''
00032     return data
00033