v2ex/babel/ext/captcha.py
def submit (recaptcha_challenge_field,
            recaptcha_response_field,
            private_key,
            remoteip):
    """
    Submits a reCAPTCHA request for verification. Returns RecaptchaResponse
    for the request

    recaptcha_challenge_field -- The value of recaptcha_challenge_field from the form
    recaptcha_response_field -- The value of recaptcha_response_field from the form
    private_key -- your reCAPTCHA private key
    remoteip -- the user's ip address
    """

    if not (recaptcha_response_field and recaptcha_challenge_field and
            len (recaptcha_response_field) and len (recaptcha_challenge_field)):
        return RecaptchaResponse (is_valid = False, error_code = 'incorrect-captcha-sol')
    
    headers = {
               'Content-type':  'application/x-www-form-urlencoded',
               "User-agent"  :  "reCAPTCHA GAE Python"
               }         
    
    params = urllib.urlencode ({
	    'privatekey': private_key,
        'remoteip' : remoteip,
	    'challenge': recaptcha_challenge_field,
	    'response' : recaptcha_response_field,
	    })

    httpresp = urlfetch.fetch(
                   url      = "http://%s/verify" % VERIFY_SERVER,
                   payload  = params,
                   method   = urlfetch.POST,
                   headers  = headers
                    )     
    
    if httpresp.status_code == 200:
        # response was fine
        
        # get the return values
        return_values = httpresp.content.splitlines();
        
        # get the return code (true/false)
        return_code = return_values[0]
        
        if return_code == "true":
            # yep, filled perfectly
            return RecaptchaResponse (is_valid=True)
        else:
            # nope, something went wrong
            return RecaptchaResponse (is_valid=False, error_code = return_values [1])
    else:
        # recaptcha server was not reachable
        return RecaptchaResponse (is_valid=False, error_code = "recaptcha-not-reachable")

    Submits a reCAPTCHA request for verification. Returns RecaptchaResponse
    for the request

    recaptcha_challenge_field -- The value of recaptcha_challenge_field from the form
    recaptcha_response_field -- The value of recaptcha_response_field from the form
    private_key -- your reCAPTCHA private key
    remoteip -- the user's ip address
    
Submits a reCAPTCHA request for verification. Returns RecaptchaResponse
for the request


Submits a reCAPTCHA request for verification . Returns RecaptchaResponse for the request
def submit (recaptcha_challenge_field,
            recaptcha_response_field,
            private_key,
            remoteip):
    if not (recaptcha_response_field and recaptcha_challenge_field and
            len (recaptcha_response_field) and len (recaptcha_challenge_field)):
        return RecaptchaResponse (is_valid = False, error_code = 'incorrect-captcha-sol')
    headers = {
               'Content-type':  'application/x-www-form-urlencoded',
               "User-agent"  :  "reCAPTCHA GAE Python"
               }         
    params = urllib.urlencode ({
	    'privatekey': private_key,
        'remoteip' : remoteip,
	    'challenge': recaptcha_challenge_field,
	    'response' : recaptcha_response_field,
	    })
    httpresp = urlfetch.fetch(
                   url      = "http://%s/verify" % VERIFY_SERVER,
                   payload  = params,
                   method   = urlfetch.POST,
                   headers  = headers
                    )     
    if httpresp.status_code == 200:
        return_values = httpresp.content.splitlines();
        return_code = return_values[0]
        if return_code == "true":
            return RecaptchaResponse (is_valid=True)
        else:
            return RecaptchaResponse (is_valid=False, error_code = return_values [1])
    else:
        return RecaptchaResponse (is_valid=False, error_code = "recaptcha-not-reachable")
def submit ( recaptcha_challenge_field , recaptcha_response_field , private_key , remoteip ) : if not ( recaptcha_response_field and recaptcha_challenge_field and len ( recaptcha_response_field ) and len ( recaptcha_challenge_field ) ) : return RecaptchaResponse ( is_valid = False , error_code = 'incorrect-captcha-sol' ) headers = { 'Content-type' : 'application/x-www-form-urlencoded' , "User-agent" : "reCAPTCHA GAE Python" } params = urllib . urlencode ( { 'privatekey' : private_key , 'remoteip' : remoteip , 'challenge' : recaptcha_challenge_field , 'response' : recaptcha_response_field , } ) httpresp = urlfetch . fetch ( url = "http://%s/verify" % VERIFY_SERVER , payload = params , method = urlfetch . POST , headers = headers ) if httpresp . status_code == 200 : return_values = httpresp . content . splitlines ( ) ; return_code = return_values [ 0 ] if return_code == "true" : return RecaptchaResponse ( is_valid = True ) else : return RecaptchaResponse ( is_valid = False , error_code = return_values [ 1 ] ) else : return RecaptchaResponse ( is_valid = False , error_code = "recaptcha-not-reachable" )
Submits a reCAPTCHA request for verification.
Submits a reCAPTCHA request for verification .
"""
    Submits a reCAPTCHA request for verification. Returns RecaptchaResponse
    for the request

    recaptcha_challenge_field -- The value of recaptcha_challenge_field from the form
    recaptcha_response_field -- The value of recaptcha_response_field from the form
    private_key -- your reCAPTCHA private key
    remoteip -- the user's ip address
    """ # response was fine # get the return values # get the return code (true/false) # yep, filled perfectly # nope, something went wrong # recaptcha server was not reachable
recaptcha_challenge_field
recaptcha_response_field
private_key
remoteip