From 2fdb2fe36a2f484c06012de1277d73d9082a57d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre=20Mazi=C3=A8re?= Date: Fri, 4 Nov 2011 10:10:23 +0100 Subject: [PATCH] VirtKeyboard: add check_symbols method MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This method allows one to verify, before any decoding attempt, if all the symbols given as arguments can be found in the virtual keyboard. Signed-off-by: Pierre Mazière --- weboob/tools/captcha/virtkeyboard.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/weboob/tools/captcha/virtkeyboard.py b/weboob/tools/captcha/virtkeyboard.py index 85dbbb0d..bcf99a36 100644 --- a/weboob/tools/captcha/virtkeyboard.py +++ b/weboob/tools/captcha/virtkeyboard.py @@ -101,6 +101,16 @@ class VirtKeyboard(object): return i raise VirtKeyboardError('Symbol not found') + def check_symbols(self,symbols,dirname): + # symbols: dictionary : + for s in symbols.keys(): + try: + self.get_symbol_code(symbols[s]) + except VirtKeyboardError: + self.generate_MD5(dirname) + raise VirtKeyboardError("Symbol '%s' not found; all symbol hashes are available in %s"\ + % (s,dirname)) + def generate_MD5(self,dir): for i in self.coords.keys(): width=self.coords[i][2]-self.coords[i][0]+1