#NEWLINE# def _validate_recaptcha( self , response , remote_addr ) : #NEWLINE# #INDENT# 'Performs the actual validation.' #NEWLINE# try : #NEWLINE# #INDENT# private_key = current_app . config [ 'RECAPTCHA_PRIVATE_KEY' ] #NEWLINE# #UNINDENT# except KeyError : #NEWLINE# #INDENT# raise RuntimeError ( 'No RECAPTCHA_PRIVATE_KEY config set' ) #NEWLINE# #UNINDENT# data = url_encode ( { #NEWLINE# #INDENT# 'secret' : private_key , #NEWLINE# 'remoteip' : remote_addr , #NEWLINE# 'response' : response , #NEWLINE# #UNINDENT# } ) #NEWLINE# http_response = http . urlopen ( RECAPTCHA_VERIFY_SERVER , to_bytes ( data ) ) #NEWLINE# if ( http_response . code != 200 ) : #NEWLINE# #INDENT# return False #NEWLINE# #UNINDENT# json_resp = json . loads ( to_unicode ( http_response . read ( ) ) ) #NEWLINE# if json_resp [ 'success' ] : #NEWLINE# #INDENT# return True #NEWLINE# #UNINDENT# for error in json_resp . get ( 'error-codes' , [ ] ) : #NEWLINE# #INDENT# if ( error in RECAPTCHA_ERROR_CODES ) : #NEWLINE# #INDENT# raise ValidationError ( RECAPTCHA_ERROR_CODES [ error ] ) #NEWLINE# #UNINDENT# #UNINDENT# return False