Back to index

moin  1.9.0~rc2
text.py
Go to the documentation of this file.
00001 # -*- coding: iso-8859-1 -*-
00002 """
00003     MoinMoin - text/* file Filter
00004 
00005     We try to support more than ASCII here.
00006 
00007     @copyright: 2006 MoinMoin:ThomasWaldmann
00008     @license: GNU GPL, see COPYING for details.
00009 """
00010 
00011 import codecs
00012 
00013 def execute(indexobj, filename):
00014     for enc in ('utf-8', 'iso-8859-15', ):
00015         try:
00016             f = codecs.open(filename, "r", enc)
00017             data = f.read()
00018             f.close()
00019             return data
00020         except UnicodeError:
00021             pass
00022     f = file(filename, "r")
00023     data = f.read()
00024     f.close()
00025     data = data.decode('ascii', 'replace')
00026     return data
00027