Created
May 2, 2014 07:52
-
-
Save lbolla/bb7af2bfb536aec2f79c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
import string | |
import cherrypy | |
class StringGenerator(object): | |
@cherrypy.expose | |
def index(self): | |
return """<html> | |
<body> | |
<form method="get" action="generate"> | |
<input type="text" value="8" name="length" /> | |
<button type="submit">Give it now!</button> | |
</form> | |
</body> | |
</html>""" | |
@cherrypy.expose | |
def generate(self, length=8): | |
some_string = ''.join(random.sample(string.hexdigits, int(length))) | |
cherrypy.session['mystring'] = some_string | |
return some_string | |
@cherrypy.expose | |
def display(self): | |
return cherrypy.session['mystring'] | |
if __name__ == '__main__': | |
favconfig = { | |
"/favicon.ico": { | |
"tools.staticfile.on": True, | |
"tools.staticfile.filename": "/tmp/favicon.ico", | |
"tools.staticfile.content_types": {"ico": "image/x-icon"}, | |
} | |
} | |
cherrypy.quickstart(StringGenerator(), "/", favconfig) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment