Unix: make plugin py3k-friendly.

This commit is contained in:
Valentin Lorentz 2012-08-04 22:20:20 +02:00
parent 65eb79b8f2
commit 6537137b3f

View File

@ -109,7 +109,7 @@ class Unix(callbacks.Plugin):
irc.reply(format('%i', os.getpid()), private=True)
pid = wrap(pid, [('checkCapability', 'owner')])
_cryptre = re.compile(r'[./0-9A-Za-z]')
_cryptre = re.compile(b'[./0-9A-Za-z]')
@internationalizeDocstring
def crypt(self, irc, msg, args, password, salt):
"""<password> [<salt>]
@ -120,12 +120,12 @@ class Unix(callbacks.Plugin):
based crypt rather than the standard DES based crypt.
"""
def makeSalt():
s = '\x00'
while self._cryptre.sub('', s) != '':
s = b'\x00'
while self._cryptre.sub(b'', s) != b'':
s = struct.pack('<h', random.randrange(-(2**15), 2**15))
return s
if not salt:
salt = makeSalt()
salt = makeSalt().decode()
irc.reply(crypt.crypt(password, salt))
crypt = wrap(crypt, ['something', additional('something')])
@ -157,15 +157,15 @@ class Unix(callbacks.Plugin):
irc.error(e, Raise=True)
ret = inst.poll()
if ret is not None:
s = inst.stderr.readline()
s = inst.stderr.readline().decode('utf8')
if not s:
s = inst.stdout.readline()
s = inst.stdout.readline().decode('utf8')
s = s.rstrip('\r\n')
s = s.lstrip('Error: ')
irc.error(s, Raise=True)
(out, err) = inst.communicate(word)
(out, err) = inst.communicate(word.encode())
inst.wait()
lines = filter(None, out.splitlines())
lines = [x.decode('utf8') for x in out.splitlines() if x]
lines.pop(0) # Banner
if not lines:
irc.error(_('No results found.'), Raise=True)
@ -251,7 +251,7 @@ class Unix(callbacks.Plugin):
(out, _) = inst.communicate()
inst.wait()
if out:
response = out.splitlines()[0].strip()
response = out.decode('utf8').splitlines()[0].strip()
response = utils.str.normalizeWhitespace(response)
irc.reply(response)
else:
@ -299,9 +299,9 @@ class Unix(callbacks.Plugin):
'not available (%s).' % e, Raise=True)
result = inst.communicate()
if result[1]: # stderr
irc.error(' '.join(result[1].split()))
irc.error(' '.join(result[1].decode('utf8').split()))
else:
response = result[0].split("\n");
response = result[0].decode('utf8').split("\n");
if response[1]:
irc.reply(' '.join(response[1].split()[3:5]).split(':')[0]
+ ': ' + ' '.join(response[-3:]))
@ -333,7 +333,7 @@ class Unix(callbacks.Plugin):
(out, err) = inst.communicate()
inst.wait()
lines = out.splitlines()
lines = map(str.rstrip, lines)
lines = [x.decode('utf8').rstrip() for x in lines]
lines = filter(None, lines)
irc.replies(lines, joiner=' ')
else:
@ -389,9 +389,9 @@ class Unix(callbacks.Plugin):
'not available (%s).' % e, Raise=True)
result = inst.communicate()
if result[1]: # stderr
irc.error(' '.join(result[1].split()))
irc.error(' '.join(result[1].decode('utf8').split()))
if result[0]: # stdout
response = result[0].split("\n");
response = result[0].decode('utf8').split("\n");
response = [l for l in response if l]
irc.replies(response)
call = thread(wrap(call, ["owner", "text"]))