()
Presents a demo of this captcha module.
    
    If you run this file as a CGI in your web server, you'll see the demo
    in action
Presents a demo of this captcha module.
    
    If you run this file as a CGI in your web server, you'll see the demo
    in action
Presents a demo of this captcha module . If you run this file as a CGI in your web server you ll see the demo in action
def _demo():
    """
    Presents a demo of this captcha module.
    
    If you run this file as a CGI in your web server, you'll see the demo
    in action
    """
    import cgi
    fields = cgi.FieldStorage()
    cmd = fields.getvalue("cmd", "")
    
    if not cmd:
        # first view
        key = getChallenge()
        print """Content-Type: text/html

<html>
 <head>
  <title>ezcaptcha demo</title>
 <head>
 <body>
  <h1>ezcaptcha demo</h1>
  <form method="POST">
   <input type="hidden" name="cmd" value="answerCaptcha">
   <input type="hidden" name="captchaKey" value="%s">
   <img src="?cmd=showCaptchaImg&captchaKey=%s">
   <br>
   Please type in the word you see in the image above:<br>
   <input type="text" name="captchaAnswer"><br>
   <input type="submit" value="Submit">
  </form>
 </body>
</html>
""" % (key, key)

    elif cmd == 'showCaptchaImg':
        # answer browser request for the CAPTCHA challenge image
        key = fields.getvalue("captchaKey")
        bindata = getImageData(key)
        print "Content-Type: image/jpeg"
        print
        print bindata

    elif cmd == 'answerCaptcha':
        # user has posted in an answer
        key = fields.getvalue("captchaKey")
        guess = fields.getvalue("captchaAnswer")
        
        # test user's answer
        if testSolution(key, guess) == True:
            # successful
            print """Content-Type: text/html

<html>
 <head>
  <title>ezcaptcha demo</title>
 </head>
 <body>
  <h1>ezcaptcha demo</h1>
  Successful!<br>
  <br>
  <a href="">Click here</a> for another demo
 </body>
</html>
"""

        else:
            # failed
            print """Content-Type: text/html

<html>
 <head>
  <title>ezcaptcha demo</title>
 <head>
 <body>
  <h1>ezcaptcha demo</h1>
  Sorry - that was wrong!
  <form method="POST">
   <input type="hidden" name="cmd" value="answerCaptcha">
   <input type="hidden" name="captchaKey" value="%s">
   <img src="?cmd=showCaptchaImg&captchaKey=%s">
   <br>
   Please type in the word you see in the image above:<br>
   <input type="text" name="captchaAnswer"><br>
   <input type="submit" value="Submit">
  </form>
 </body>
</html>
""" % (key, key)
def _demo ( ) : import cgi fields = cgi . FieldStorage ( ) cmd = fields . getvalue ( "cmd" , "" ) if not cmd : # first view key = getChallenge ( ) print """Content-Type: text/html

<html>
 <head>
  <title>ezcaptcha demo</title>
 <head>
 <body>
  <h1>ezcaptcha demo</h1>
  <form method="POST">
   <input type="hidden" name="cmd" value="answerCaptcha">
   <input type="hidden" name="captchaKey" value="%s">
   <img src="?cmd=showCaptchaImg&captchaKey=%s">
   <br>
   Please type in the word you see in the image above:<br>
   <input type="text" name="captchaAnswer"><br>
   <input type="submit" value="Submit">
  </form>
 </body>
</html>
""" % ( key , key ) elif cmd == 'showCaptchaImg' : # answer browser request for the CAPTCHA challenge image key = fields . getvalue ( "captchaKey" ) bindata = getImageData ( key ) print "Content-Type: image/jpeg" print print bindata elif cmd == 'answerCaptcha' : # user has posted in an answer key = fields . getvalue ( "captchaKey" ) guess = fields . getvalue ( "captchaAnswer" ) # test user's answer if testSolution ( key , guess ) == True : # successful print """Content-Type: text/html

<html>
 <head>
  <title>ezcaptcha demo</title>
 </head>
 <body>
  <h1>ezcaptcha demo</h1>
  Successful!<br>
  <br>
  <a href="">Click here</a> for another demo
 </body>
</html>
""" else : # failed print """Content-Type: text/html

<html>
 <head>
  <title>ezcaptcha demo</title>
 <head>
 <body>
  <h1>ezcaptcha demo</h1>
  Sorry - that was wrong!
  <form method="POST">
   <input type="hidden" name="cmd" value="answerCaptcha">
   <input type="hidden" name="captchaKey" value="%s">
   <img src="?cmd=showCaptchaImg&captchaKey=%s">
   <br>
   Please type in the word you see in the image above:<br>
   <input type="text" name="captchaAnswer"><br>
   <input type="submit" value="Submit">
  </form>
 </body>
</html>
""" % ( key , key )