mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-23 19:19:32 +01:00
Hopefully fixed bugs in Unix.spell once and for all.
This commit is contained in:
parent
4711e227f4
commit
5fb5533e49
@ -97,6 +97,17 @@ def progstats():
|
|||||||
sys.version.translate(string.ascii, '\r\n'))
|
sys.version.translate(string.ascii, '\r\n'))
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
class TimeoutError(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def pipeReadline(fd, timeout=0.5):
|
||||||
|
(r, _, _) = select.select([fd], [], [], timeout)
|
||||||
|
if r:
|
||||||
|
return r[0].readline()
|
||||||
|
else:
|
||||||
|
raise TimeoutError
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Unix(callbacks.Privmsg):
|
class Unix(callbacks.Privmsg):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@ -170,22 +181,22 @@ class Unix(callbacks.Privmsg):
|
|||||||
"""
|
"""
|
||||||
# We are only checking the first word
|
# We are only checking the first word
|
||||||
word = privmsgs.getArgs(args)
|
word = privmsgs.getArgs(args)
|
||||||
if word and word[0] in '.?*&@+-~#!%^':
|
if word and not word[0].isalpha():
|
||||||
irc.error(msg, 'Initial spell metacharacters aren\'t allowed.')
|
irc.error(msg, '<word> must begin with an alphabet character.')
|
||||||
return
|
return
|
||||||
if ' ' in word:
|
if ' ' in word:
|
||||||
irc.error(msg, 'Spaces aren\'t allowed in the word.')
|
irc.error(msg, 'Spaces aren\'t allowed in the word.')
|
||||||
return
|
return
|
||||||
self._spellWrite.write(word)
|
self._spellWrite.write(word)
|
||||||
self._spellWrite.write('\n')
|
self._spellWrite.write('\n')
|
||||||
(r, _, _) = select.select([self._spellRead], [], [], 0.1)
|
try:
|
||||||
if not r:
|
line = pipeReadline(self._spellRead)
|
||||||
irc.error(msg, 'The spell command did not respond to %r' % word)
|
|
||||||
return
|
|
||||||
line = self._spellRead.readline()
|
|
||||||
# aspell puts extra whitespace, ignore it
|
# aspell puts extra whitespace, ignore it
|
||||||
while line == '\n':
|
while line == '\n':
|
||||||
line = self._spellRead.readline()
|
line = pipeReadline(self._spellRead)
|
||||||
|
except TimeoutError:
|
||||||
|
irc.error(msg, 'The spell command didn\'t return usefully.')
|
||||||
|
return
|
||||||
# parse the output
|
# parse the output
|
||||||
if line[0] in '*+':
|
if line[0] in '*+':
|
||||||
resp = '"%s" may be spelled correctly.' % word
|
resp = '"%s" may be spelled correctly.' % word
|
||||||
|
@ -43,6 +43,8 @@ if os.name == 'posix':
|
|||||||
self.assertNotError('spell Strizzike')
|
self.assertNotError('spell Strizzike')
|
||||||
self.assertError('spell foo bar baz')
|
self.assertError('spell foo bar baz')
|
||||||
self.assertError('spell -')
|
self.assertError('spell -')
|
||||||
|
self.assertError('spell .')
|
||||||
|
self.assertError('spell ?')
|
||||||
|
|
||||||
def testErrno(self):
|
def testErrno(self):
|
||||||
self.assertRegexp('errno 12', '^ENOMEM')
|
self.assertRegexp('errno 12', '^ENOMEM')
|
||||||
|
Loading…
Reference in New Issue
Block a user