#!/usr/bin/env python # Web application that outputs permutations of a given unicode word # Author: hendry@iki.fi # License: GPL import web, config, view from view import render from web import form urls = ( '/', 'index', ) myform = form.Form( form.Textbox("anagram", form.notnull, form.regexp('(?u)\w+', 'Must be a word'), # notice the unicode form.Validator('Must be more than 1 and less than 6 characters', lambda x:len(unicode(x, 'utf-8'))>1 and len(unicode(x, 'utf-8'))<6))) class index: def GET(self): form = myform() if not form.validates(): print render.base(render.input(form)) else: anagram = unicode(form.d.anagram, 'utf-8') # massage into unicode import permute permutation = [(''.join(i)) for i in permute.permu2(list(anagram))] print render.base(render.output(anagram, len(anagram), permutation)) web.webapi.internalerror = web.debugerror if __name__ == "__main__": web.run(urls, globals(), *config.middleware)