[weboob] [PATCH 5/7] Add MappedVirtKeyboard class

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


This is useful for virtual keyboard based on the usemap
attribute of an IMG tag

Signed-off-by: Pierre Mazière <pierre.maziere at gmail.com>
---
 weboob/tools/captcha/virtkeyboard.py |   16 ++++++++++++++++
 1 files changed, 16 insertions(+), 0 deletions(-)

diff --git a/weboob/tools/captcha/virtkeyboard.py b/weboob/tools/captcha/virtkeyboard.py
index bcf99a3..72ab98a 100644
--- a/weboob/tools/captcha/virtkeyboard.py
+++ b/weboob/tools/captcha/virtkeyboard.py
@@ -122,3 +122,19 @@ class VirtKeyboard(object):
                     matrix[x,y]=self.pixar[self.coords[i][0]+x,self.coords[i][1]+y]
             img.save(dir+"/"+self.md5[i]+".png")
 
+class MappedVirtKeyboard(VirtKeyboard):
+    def __init__(self,file,document,img_element,color):
+        map_id=img_element.attrib.get("usemap")[1:]
+        map=document.find("//map[@id='"+map_id+"']")
+        if map is None:
+            map=document.find("//map[@name='"+map_id+"']")
+
+        coords={}
+        for area in map.getiterator("area"):
+            code=area.attrib.get("onclick")
+            area_coords=[]
+            for coord in area.attrib.get("coords").split(','):
+                area_coords.append(int(coord))
+            coords[code]=tuple(area_coords)
+
+        VirtKeyboard.__init__(self,file,coords,color)
-- 
1.7.7



More information about the weboob mailing list