mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-27 05:09:23 +01:00
Added some much tighter error-checking to the spell command; also used select to make sure the file handle is readable before trying to read from it.
This commit is contained in:
parent
54aec8d3b2
commit
b4a56057f1
@ -41,10 +41,11 @@ import pwd
|
||||
import sys
|
||||
import crypt
|
||||
import errno
|
||||
import popen2
|
||||
import random
|
||||
import select
|
||||
import string
|
||||
import struct
|
||||
import popen2
|
||||
|
||||
|
||||
import privmsgs
|
||||
@ -169,11 +170,18 @@ class Unix(callbacks.Privmsg):
|
||||
"""
|
||||
# We are only checking the first word
|
||||
word = privmsgs.getArgs(args)
|
||||
if word and word[0] in '*&@+-~#!%^':
|
||||
irc.error(msg, 'Initial spell metacharacters aren\'t allowed.')
|
||||
return
|
||||
if ' ' in word:
|
||||
irc.error(msg, 'Aspell/ispell can\'t handle spaces in words.')
|
||||
irc.error(msg, 'Spaces aren\'t allowed in the word.')
|
||||
return
|
||||
self._spellWrite.write(word)
|
||||
self._spellWrite.write('\n')
|
||||
(r, _, _) = select.select([self._spellRead], [], [], 0.1)
|
||||
if not r:
|
||||
irc.error(msg, 'The spell command did not respond to %r' % word)
|
||||
return
|
||||
line = self._spellRead.readline()
|
||||
# aspell puts extra whitespace, ignore it
|
||||
while line == '\n':
|
||||
|
@ -42,6 +42,7 @@ if os.name == 'posix':
|
||||
'not find')
|
||||
self.assertNotError('spell Strizzike')
|
||||
self.assertError('spell foo bar baz')
|
||||
self.assertError('spell -')
|
||||
|
||||
def testErrno(self):
|
||||
self.assertRegexp('errno 12', '^ENOMEM')
|
||||
|
Loading…
Reference in New Issue
Block a user