view MoinMoin/filter/__init__.py @ 3027:6dcc9617bab6

Fix for WrongAlignedAttachment (Thanks to Benjamin Weber) (ported from 1.6)
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Sun, 03 Feb 2008 17:57:42 +0100
parents bb2e053067fb
children f048227cabc3
line wrap: on
line source
# -*- coding: iso-8859-1 -*-
"""
    MoinMoin - Filter Package

    @copyright: 2006 Thomas Waldmann
    @license: GNU GPL, see COPYING for details.
"""

import os
from MoinMoin.util import pysupport

modules = pysupport.getPackageModules(__file__)

standard_codings = ['utf-8', 'iso-8859-15', 'iso-8859-1', ]

def execfilter(cmd, filename, codings=standard_codings):
    """ use cmd to get plaintext content of filename
        to decode to unicode, we use the first coding of codings list that
        does not throw an exception or force ascii
    """
    f = os.popen(cmd % filename)
    data = f.read()
    f.close()
    for c in codings:
        try:
            return data.decode(c)
        except UnicodeError:
            pass
    return data.decode('ascii', 'replace')