浏览代码

dramatically simplify error handling with !encrypt/!decrypt irc commands, thanks to previous commit

tags/v0.1^2
Ben Kurtovic 13 年前
父节点
当前提交
848ac58e7a
共有 1 个文件被更改,包括 5 次插入12 次删除
  1. +5
    -12
      irc/commands/crypt.py

+ 5
- 12
irc/commands/crypt.py 查看文件

@@ -63,16 +63,9 @@ class Cryptography(BaseCommand):


try: try:
if data.command == "encrypt": if data.command == "encrypt":
result = blowfish.encrypt(key, text)
self.connection.reply(data, blowfish.encrypt(key, text))
else: else:
result = blowfish.decrypt(key, text)
except blowfish.KeyTooShortError:
self.connection.reply(data, "key is too short.")
except blowfish.KeyTooLongError:
self.connection.reply(data, "key is too long.")
except blowfish.IncorrectKeyError:
self.connection.reply(data, "key is incorrect!")
except blowfish.BadCyphertextError as e:
self.connection.reply(data, "bad cyphertext: {0}.".format(e))
else:
self.connection.reply(data, result)
self.connection.reply(data, blowfish.decrypt(key, text))
except blowfish.BlowfishError as error:
self.connection.reply(data, "{0}: {1}.".format(
error.__class__.__name__, error))

正在加载...
取消
保存