--- a/plugins/aspell_plugin.py Wed May 02 20:17:49 2007 +0200
+++ b/plugins/aspell_plugin.py Wed May 02 20:39:20 2007 +0200
@@ -1,36 +1,38 @@
#$ neutron_plugin 01
# 2007-05 Mikael Berthe <mikael@lilotux.net>
-import popen2
+import subprocess
+import locale
import re
-ASPELL = "/usr/bin/aspell -a"
-
def handler_aspell(type, source, parameters):
parameters = parameters.lstrip().rstrip()
splitdata = parameters.split()
- aspell = ASPELL
+ cmd = ['/usr/bin/aspell', '-a']
reply = ""
+ LC, encoding = locale.getdefaultlocale()
+
# Check if the language is specified (two-letter code)
if len(splitdata) > 1:
lang = parameters.lower()
if re.match(r"\w\w ", lang):
parameters = parameters[3:].lstrip()
- aspell += " --lang=" + lang
+ cmd.append("--lang=" + lang)
# Spawn an aspell process
- stdout, stdin = popen2.popen2(aspell)
+ aspell = subprocess.Popen(cmd, stdin=subprocess.PIPE,
+ stdout=subprocess.PIPE)
- stdin.write(parameters.encode('iso-8859-15'))
- stdin.close()
+ aspell.stdin.write(parameters.encode(encoding))
+ aspell.stdin.close()
# Skip the first line (banner)
- r = stdout.readline()
+ aspell.stdout.readline()
# Process all result lines
- for r in stdout.readlines():
- r = r.decode('iso-8859-15')
+ for r in aspell.stdout.readlines():
+ r = r.decode(encoding)
if r == "*\n":
reply += "* Word correctly spelled.\n"
elif r.startswith("& "):
@@ -41,6 +43,8 @@
# I don't know if it can happen
reply += r
+ aspell.stdout.close()
+
if not reply:
reply = "Unknown error (no reply)"