annotate MoinMoin/filter/__init__.py @ 1918:bb2e053067fb

fixing copyright headers: remove umlauts (encoding troubles), make epydoc compatible, reformat
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Tue, 27 Mar 2007 21:07:33 +0200
parents db56bd53fc32
children f048227cabc3
rev   line source
438
8bb545d58e6f lupy: filter plugins for attachment search
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
1 # -*- coding: iso-8859-1 -*-
8bb545d58e6f lupy: filter plugins for attachment search
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
2 """
8bb545d58e6f lupy: filter plugins for attachment search
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
3 MoinMoin - Filter Package
8bb545d58e6f lupy: filter plugins for attachment search
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
4
1918
bb2e053067fb fixing copyright headers: remove umlauts (encoding troubles), make epydoc compatible, reformat
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1133
diff changeset
5 @copyright: 2006 Thomas Waldmann
438
8bb545d58e6f lupy: filter plugins for attachment search
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
6 @license: GNU GPL, see COPYING for details.
8bb545d58e6f lupy: filter plugins for attachment search
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
7 """
8bb545d58e6f lupy: filter plugins for attachment search
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
8
470
957d482215ac lupy: some filters, update mode
Thomas Waldmann <tw@waldmann-edv.de>
parents: 438
diff changeset
9 import os
438
8bb545d58e6f lupy: filter plugins for attachment search
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
10 from MoinMoin.util import pysupport
8bb545d58e6f lupy: filter plugins for attachment search
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
11
1133
db56bd53fc32 cleanup plugin related code / attributes, remove unused stuff
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 999
diff changeset
12 modules = pysupport.getPackageModules(__file__)
438
8bb545d58e6f lupy: filter plugins for attachment search
Thomas Waldmann <tw@waldmann-edv.de>
parents:
diff changeset
13
999
97ce857bdebf whitespace-only cleanup and minor style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 470
diff changeset
14 standard_codings = ['utf-8', 'iso-8859-15', 'iso-8859-1', ]
470
957d482215ac lupy: some filters, update mode
Thomas Waldmann <tw@waldmann-edv.de>
parents: 438
diff changeset
15
957d482215ac lupy: some filters, update mode
Thomas Waldmann <tw@waldmann-edv.de>
parents: 438
diff changeset
16 def execfilter(cmd, filename, codings=standard_codings):
957d482215ac lupy: some filters, update mode
Thomas Waldmann <tw@waldmann-edv.de>
parents: 438
diff changeset
17 """ use cmd to get plaintext content of filename
957d482215ac lupy: some filters, update mode
Thomas Waldmann <tw@waldmann-edv.de>
parents: 438
diff changeset
18 to decode to unicode, we use the first coding of codings list that
957d482215ac lupy: some filters, update mode
Thomas Waldmann <tw@waldmann-edv.de>
parents: 438
diff changeset
19 does not throw an exception or force ascii
957d482215ac lupy: some filters, update mode
Thomas Waldmann <tw@waldmann-edv.de>
parents: 438
diff changeset
20 """
957d482215ac lupy: some filters, update mode
Thomas Waldmann <tw@waldmann-edv.de>
parents: 438
diff changeset
21 f = os.popen(cmd % filename)
957d482215ac lupy: some filters, update mode
Thomas Waldmann <tw@waldmann-edv.de>
parents: 438
diff changeset
22 data = f.read()
957d482215ac lupy: some filters, update mode
Thomas Waldmann <tw@waldmann-edv.de>
parents: 438
diff changeset
23 f.close()
957d482215ac lupy: some filters, update mode
Thomas Waldmann <tw@waldmann-edv.de>
parents: 438
diff changeset
24 for c in codings:
957d482215ac lupy: some filters, update mode
Thomas Waldmann <tw@waldmann-edv.de>
parents: 438
diff changeset
25 try:
957d482215ac lupy: some filters, update mode
Thomas Waldmann <tw@waldmann-edv.de>
parents: 438
diff changeset
26 return data.decode(c)
957d482215ac lupy: some filters, update mode
Thomas Waldmann <tw@waldmann-edv.de>
parents: 438
diff changeset
27 except UnicodeError:
957d482215ac lupy: some filters, update mode
Thomas Waldmann <tw@waldmann-edv.de>
parents: 438
diff changeset
28 pass
957d482215ac lupy: some filters, update mode
Thomas Waldmann <tw@waldmann-edv.de>
parents: 438
diff changeset
29 return data.decode('ascii', 'replace')
957d482215ac lupy: some filters, update mode
Thomas Waldmann <tw@waldmann-edv.de>
parents: 438
diff changeset
30