def single_POST(environ, start_response):
    '''Response to POST /single'''

    # Handle old CAPTCHA
    form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ)
    code = form.getfirst('confidentcaptcha_code')
    captcha_id = form.getfirst('confidentcaptcha_captcha_id')
    check_status, check_body = captchalib.check_captcha(captcha_id, code)

    if check_body == 'True':
        verify_body = "CAPTCHA solution was correct.  Click above to try another, or go back to the <a href='.'>config check</a>."
    else:
        verify_body = "CAPTCHA solution was incorrect.  Click above to try another, or go back to the <a href='.'>config check</a>."

    # Create next CAPTCHA
    user_ip, user_agent = captchalib.get_user_info(environ)
    captcha_status, captcha_body = captchalib.create_captcha(user_ip, user_agent)

    # Verbose error handling.  In your application, you may want to disable
    #  CAPTCHA instead, or add a fallback CAPTCHA.
    if (captcha_status != 200):
        captcha_body = ("<b>Server returned error %d on create_captcha:</b>" %
            captcha_status) + captcha_body

    html_params = {
        'captcha_body': captcha_body,
        'verify_body': verify_body,
    }
    status = '200 OK'
    headers = [('Content-type', 'text/html; charset=utf-8')]
    html = single_template % html_params

    start_response(status, headers)
    return html.encode('utf-8')
def single_GET(environ, start_response):
    '''Response to GET /single'''

    user_ip, user_agent = captchalib.get_user_info(environ)
    captcha_status, captcha_body = captchalib.create_captcha(user_ip, user_agent)

    # Verbose error handling.  In your application, you may want to disable
    #  CAPTCHA instead, or add a fallback CAPTCHA.
    if (captcha_status != 200):
        captcha_body = ("<b>Server returned error %d on create_captcha:</b>" %
            captcha_status) + captcha_body

    html_params = {
        'captcha_body': captcha_body,
        'verify_body': 'Solve the CAPTCHA above, then click Submit.',
    }

    status = '200 OK'
    headers = [
        ('Content-type', 'text/html; charset=utf-8'),
    ]
    html = single_template % html_params

    start_response(status, headers)
    return html.encode('utf-8')