view MoinMoin/filter/application_vnd_sun_xml.py @ 4965:ae8bf4c7d5a1

catch another exception when a bad zip file is encountered while indexing (ignore it)
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Wed, 26 Aug 2009 13:59:33 +0200
parents 0b220c040be4
children b2e96d4cac1c
line wrap: on
line source
# -*- coding: iso-8859-1 -*-
"""
    MoinMoin - OpenOffice.org *.sx? Filter

    Depends on: nothing (only python with zlib)

    @copyright: 2006 MoinMoin:ThomasWaldmann
    @license: GNU GPL, see COPYING for details.
"""

import re, zipfile

from MoinMoin import log
logging = log.getLogger(__name__)

rx_stripxml = re.compile("<[^>]*?>", re.DOTALL|re.MULTILINE)

def execute(indexobj, filename):
    try:
        zf = zipfile.ZipFile(filename, "r")
        data = zf.read("content.xml")
        zf.close()
        data = " ".join(rx_stripxml.sub(" ", data).split())
    except (zipfile.BadZipfile, RuntimeError), err:
        logging.error("%s [%s]" % (str(err), filename))
        data = ""
    return data.decode('utf-8')