view MoinMoin/filter/text.py @ 454:e099072bba24

changed filters to use mimetypes imported from: moin--main--1.5--patch-458
author Thomas Waldmann <tw@waldmann-edv.de>
date Sat, 25 Feb 2006 08:11:57 +0000
parents
children 930c9f03aa13
line wrap: on
line source
# -*- coding: iso-8859-1 -*-
"""
    MoinMoin - text/* file Filter

    We try to support more than ASCII here.

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

import codecs

def execute(indexobj, filename):
    for enc in ('utf-8', 'iso-8859-15', 'iso-8859-1', ):
        try:
            f = codecs.open(filename, "r", enc)
            data = f.read()
            f.close()
            return data
        except UnicodeError, err:
            pass
    f = file(filename, "r")
    data = f.read()
    f.close()
    data = data.decode('ascii', 'replace')
    return data