woob.tools.captcha.virtkeyboard

exception VirtKeyboardError[source]

Bases: Exception

class VirtKeyboard(file=None, coords=None, color=None, convert=None)[source]

Bases: object

Handle a virtual keyboard.

codesep = ''

Output separator between code strings.

See get_string_code().

margin = None

Margin used by get_symbol_coords() to reduce size of each “key” of the virtual keyboard. This attribute is always converted to a 4-tuple, and has the same semantic as the CSS margin property (top, right, bottom, right), in pixels.

load_image(file, color, convert=None)[source]
load_symbols(coords)[source]
check_color(pixel)[source]
get_symbol_coords(coords)[source]

Return narrow coordinates around symbol.

checksum(coords)[source]
get_symbol_code(all_known_md5_for_symbol)[source]
get_string_code(string)[source]
check_symbols(symbols, dirname)[source]
generate_MD5(dir)[source]
class MappedVirtKeyboard(file, document, img_element, color, map_attr='onclick', convert=None)[source]

Bases: VirtKeyboard

class GridVirtKeyboard(symbols, cols, rows, image, color, convert=None)[source]

Bases: VirtKeyboard

Make a virtual keyboard where “keys” are distributed on a grid. Example here: https://www.e-sgbl.com/portalserver/sgbl-web/login

Parameters:
  • symbols (iterable) – Sequence of symbols, ordered in the grid from left to right and up to down

  • cols (int) – Column count of the grid

  • rows (int) – Row count of the grid

  • image (file) – File-like object to be used as data source

  • color (3-tuple) – Color of the meaningful pixels

  • convert – Mode to which convert color of pixels, see (default: None) Image.Image.convert() for more information

symbols = {}

Assocation table between symbols and md5s

class SplitKeyboard(code_to_filedata)[source]

Bases: object

Virtual keyboard for when the chars are in individual images, not a single grid

char_to_hash = None

dict mapping password characters to image hashes

codesep = ''

Output separator between symbols

checksum(buffer)[source]
dump(files, path)[source]
get_string_code(password)[source]
convert(buffer)[source]
classmethod create_from_url(browser, code_to_url)[source]
class Tile(matching_symbol, coords, image=None, md5=None)[source]

Bases: object

Tile of a image grid for SimpleVirtualKeyboard

class SimpleVirtualKeyboard(file, cols, rows, matching_symbols=None, matching_symbols_coords=None, browser=None)[source]

Bases: object

Handle a virtual keyboard where “keys” are distributed on a simple grid.

Parameters:
  • cols (int) – Column count of the grid

  • rows (int) – Row count of the grid

  • file (IO) – File-like object to be used as data source

  • convert – Mode to which convert color of pixels, see Image.Image.convert() for more information

  • matching_symbols (list[str] | None) – symbol that match all case of image grid from left to right and top (default: None) to down, European reading way.

  • matching_symbols_coords (dict[str, tuple[int, int, int, int]] | None) – dict mapping matching website symbols to their image coords (default: None) (x0, y0, x1, y1) on grid image from left to right and top to down, European reading way. It’s not symbols in the image.

  • browser (Browser | None) – Browser of woob session. (default: None) Allow to dump tiles files in same directory than session folder

codesep: ClassVar[str] = ''

Output separator between matching symbols

margin: ClassVar[tuple[int, int, int, int] | tuple[int, int] | int | None] = None

4-tuple(int), same as HTML margin: (top, right, bottom, left). or 2-tuple(int), (top = bottom, right = left), or int, top = right = bottom = left

tile_margin: ClassVar[tuple[int, int, int, int] | tuple[int, int] | int | None] = None

4-tuple(int), same as HTML margin: (top, right, bottom, left). or 2-tuple(int), (top = bottom, right = left), or int, top = right = bottom = left

symbols: ClassVar[dict[str, str | tuple[str, Ellipsis]]] = None

Association table between image symbols and md5s

convert: ClassVar[str | None] = None

Mode to which convert color of pixels, see Image.Image.convert() for more information

tile_klass

alias of Tile

build_path(browser=None)[source]
load_image(file, margin=None, convert=None)[source]
alter_image()[source]
cut_margin(image, margin)[source]
get_tiles(matching_symbols=None, matching_symbols_coords=None)[source]
get_tile_coords_in_grid(case_index)[source]
cut_tiles(tile_margin=None)[source]
hash_md5_tiles()[source]
dump_tiles(path)[source]
get_string_code(password)[source]