3
3
MoinMoin - Filter Package
5
@copyright: 2006-2009 MoinMoin:ThomasWaldmann
5
@copyright: 2006-2008 MoinMoin:ThomasWaldmann
6
6
@license: GNU GPL, see COPYING for details.
12
11
from MoinMoin import log
13
12
logging = log.getLogger(__name__)
19
18
standard_codings = ['utf-8', 'iso-8859-15', 'iso-8859-1', ]
21
from MoinMoin.util.SubProcess import exec_cmd
24
def quote_filename(filename):
25
""" quote a filename (could contain blanks or other special chars) in a
26
way suitable for the platform we run on.
28
# XXX Use os.name AND/OR sys.platform?
29
if os.name == 'posix':
30
filename = "'%s'" % filename
31
elif sys.platform == 'win32':
32
filename = '"%s"' % filename
34
raise ValueError("MoinMoin.filter.quote_filename: os/platform not supported")
38
20
def execfilter(cmd, filename, codings=standard_codings):
39
21
""" use cmd to get plaintext content of filename
40
22
to decode to unicode, we use the first coding of codings list that
41
23
does not throw an exception or force ascii
43
filter_cmd = cmd % quote_filename(filename)
44
data, errors, rc = exec_cmd(filter_cmd, timeout=300)
45
logging.debug("Command '%s', rc: %d, stdout: %d bytes, stderr: %s" % (filter_cmd, rc, len(data), errors))
25
filter_cmd = cmd % filename
26
child_stdin, child_stdout, child_stderr = os.popen3(filter_cmd)
27
data = child_stdout.read()
28
errors = child_stderr.read()
31
logging.debug("cmd: %s stderr: %s" % (filter_cmd, errors))
48
34
return data.decode(c)