[weboob] [PATCH 7/7] LCL: use MappedVirtKeyboard instead of VirtKeyboard

Pierre Mazière pierre.maziere at gmail.com
Thu Nov 3 10:03:00 CET 2011


Signed-off-by: Pierre Mazière <pierre.maziere at gmail.com>
---
 weboob/backends/lcl/pages.py |   75 ++++++++++++++++++++---------------------
 1 files changed, 37 insertions(+), 38 deletions(-)

diff --git a/weboob/backends/lcl/pages.py b/weboob/backends/lcl/pages.py
index 6a2d67b..e0cd1bc 100644
--- a/weboob/backends/lcl/pages.py
+++ b/weboob/backends/lcl/pages.py
@@ -22,10 +22,44 @@ from datetime import date
 from weboob.capabilities.bank import Operation
 from weboob.capabilities.bank import Account
 from weboob.tools.browser import BasePage, BrowserUnavailable
-from weboob.tools.captcha.virtkeyboard import VirtKeyboard, VirtKeyboardError
+from weboob.tools.captcha.virtkeyboard import MappedVirtKeyboard, VirtKeyboardError
 from logging import error
 import tempfile
 
+class LCLVirtKeyboard(MappedVirtKeyboard):
+    symbols={'0':'9da2724133f2221482013151735f033c',
+             '1':'873ab0087447610841ae1332221be37b',
+             '2':'93ce6c330393ff5980949d7b6c800f77',
+             '3':'b2d70c69693784e1bf1f0973d81223c0',
+             '4':'498c8f5d885611938f94f1c746c32978',
+             '5':'359bcd60a9b8565917a7bf34522052c3',
+             '6':'aba912172f21f78cd6da437cfc4cdbd0',
+             '7':'f710190d6b947869879ec02d8e851dfa',
+             '8':'b42cc25e1539a15f767aa7a641f3bfec',
+             '9':'cc60e5894a9d8e12ee0c2c104c1d5490'
+            }
+
+    url="/UWBI/UWBIAccueil?DEST=GENERATION_CLAVIER"
+
+    def __init__(self,browser,document,color):
+        img=document.find("//img[@id='idImageClavier']")
+        MappedVirtKeyboard.__init__(self,browser.openurl(self.url),document,img,color)
+        if browser.responses_dirname is None:
+            browser.responses_dirname = \
+                    tempfile.mkdtemp(prefix='weboob_session_')
+        self.check_symbols(self.symbols,browser.responses_dirname)
+
+    def get_symbol_code(self,md5sum):
+        code=MappedVirtKeyboard.get_symbol_code(self,md5sum)
+        return code[-5:-3]
+
+    def get_string_code(self,string):
+        code=''
+        for c in string:
+            code+=self.get_symbol_code(self.symbols[c])
+        return code
+
+
 class LoginPage(BasePage):
     def myXOR(self,value,seed):
         s=''
@@ -34,49 +68,14 @@ class LoginPage(BasePage):
         return s
 
     def login(self, agency, login, passwd):
-        symbols={'0':'9da2724133f2221482013151735f033c',
-                 '1':'873ab0087447610841ae1332221be37b',
-                 '2':'93ce6c330393ff5980949d7b6c800f77',
-                 '3':'b2d70c69693784e1bf1f0973d81223c0',
-                 '4':'498c8f5d885611938f94f1c746c32978',
-                 '5':'359bcd60a9b8565917a7bf34522052c3',
-                 '6':'aba912172f21f78cd6da437cfc4cdbd0',
-                 '7':'f710190d6b947869879ec02d8e851dfa',
-                 '8':'b42cc25e1539a15f767aa7a641f3bfec',
-                 '9':'cc60e5894a9d8e12ee0c2c104c1d5490'
-                }
-
-        map=self.document.find("//map[@id='claviermap']")
-
-        coords={}
-        for area in map.getiterator("area"):
-            code=area.attrib.get("onclick")[-5:-3]
-            area_coords=[]
-            for coord in area.attrib.get("coords").split(','):
-                area_coords.append(int(coord))
-            coords[code]=tuple(area_coords)
         try:
-            vk=VirtKeyboard(self.browser.openurl("/UWBI/UWBIAccueil?DEST=GENERATION_CLAVIER"),
-                            coords,(255,255,255,255))
+            vk=LCLVirtKeyboard(self.browser,self.document,(255,255,255,255))
         except VirtKeyboardError,err:
             error("Error: %s"%err)
             return False
 
-        for s in symbols.keys():
-            try:
-                vk.get_symbol_code(symbols[s])
-            except VirtKeyboardError:
-                if self.browser.responses_dirname is None:
-                    self.browser.responses_dirname = \
-                            tempfile.mkdtemp(prefix='weboob_session_')
-                vk.generate_MD5(self.browser.responses_dirname)
-                error("Error: Symbol '%s' not found; all symbol hashes are available in %s" \
-                      % (s,self.browser.responses_dirname))
-                return False
+        password=vk.get_string_code(passwd)
 
-        password=''
-        for c in passwd:
-            password+=vk.get_symbol_code(symbols[c])
         seed=-1
         str="var aleatoire = "
         for script in self.document.findall("/head/script"):
-- 
1.7.7



More information about the weboob mailing list