ctypes方法调用libcaptcha生成验证码操作,ctypeslibcaptcha,这是一段关于ctypes


这是一段关于ctypes方法调用libcaptcha生成验证码操作的方法python源码。需要用到ctypes.util方法。

#coding:utf-8__all__=('captcha',)import os, \     ctypes,ctypes.utilLIBCAPTCHA_LIB = os.environ.get("LIBCAPTCHA_LIB",  \                            ctypes.util.find_library("captcha")  \                            )libcaptcha = ctypes.CDLL( LIBCAPTCHA_LIB )gifsize = ctypes.c_int.in_dll(libcaptcha,"gifsize").valueget_res = lambda res:''.join( chr( _ ) for _ in res )#www.iplaypy.comdef captcha():    l = ( ctypes.c_ubyte * 6 )()    im = ( ctypes.c_ubyte * 70 * 200 )()    gif = ( ctypes.c_ubyte * gifsize )()    libcaptcha.captcha(im,l)    libcaptcha.makegif(im,gif)    return dict( gif = get_res(gif),l = get_res(l)[:-1] )

编橙之家文章,

评论关闭