def logout(_request): body=get_htmltemplate() % ('<p>Logged out</p>') res=Response() c=SimpleCookie() c['authhash']='' res.set_header(*c.output().split(': ')) res.set_body(body) return res
def logout(_request): body = get_htmltemplate() % ("<p>Logged out</p>") res = Response() c = SimpleCookie() c["authhash"] = "" res.set_header(*c.output().split(': ')) res.set_body(body) return res
cgitb.enable() form_body = u""" <form method="post" action="/cgi-bin/rssreader1.py"> RSSのURL: <input type="text" size="40" name="url" value="%s" /> <input type="submit" /> </form>""" rss_parts = u""" <h3><a href="%(link)s">%(title)s</a></h1> <p>%(description)s</p> """ content = u"URLを入力してください" req = Request() if req.form.has_key('url'): try: rss_list = parse_rss(req.form['url'].value) content = '' for d in rss_list: content += rss_parts % d except: pass res = Response() body = form_body % req.form.getvalue('url', '') body += content res.set_body(get_htmltemplate() % body) print res
lang_dic = {} try: if os.path.exists('./favorite_language.dat'): with open('./favorite_language.dat', 'rb') as f: lang_dic = pickle.load(f) except IOError: pass content = "" req = Request() if 'language' in req.form: lang = req.form['language'].value lang_dic[lang] = lang_dic.get(lang, 0) + 1 with open('favorite_language.dat', 'wb') as f: pickle.dump(lang_dic, f) for lang in ['Perl', 'PHP', 'Python', 'Ruby']: num = lang_dic.get(lang, 0) content += radio_parts.format(lang=lang, num=num) res = Response() body = form_body.format(lang=content) res.set_body(get_htmltemplate().format(body)) print(res.make_output())
radio_parts=u""" <input type="radio" name="language" value="%s" />%s <div style="border-left: solid %sem red; ">%s</div> """ lang_dic={} try: f=open('./favorite_langage.dat') lang_dic=pickle.load(f) except IOError: pass content="" req=Request() if req.form.has_key('language'): lang=req.form['language'].value lang_dic[lang]=lang_dic.get(lang, 0)+1 f=open('./favorite_langage.dat', 'w') pickle.dump(lang_dic, f) for lang in ['Perl', 'PHP', 'Python', 'Ruby']: num=lang_dic.get(lang, 0) content+=radio_parts%(lang, lang, num, num) res=Response() body=form_body%content res.set_body(get_htmltemplate()%body) print res
con = sqlite3.connect("./dbfile.dat") cur = con.cursor() try: cur.execute("""CREATE TABLE language_pole( name text, value int);""") except: pass req = Request() if "language" in req.form: incrementvalue(cur, req.form["language"].value) lang_dic = {} cur.execute("""SELECT name, value FROM language_pole;""") for res in cur.fetchall(): lang_dic[res[0]] = res[1] content = "" for lang in ["Perl", "PHP", "Python", "Ruby"]: num = lang_dic.get(lang, 0) content += radio_partu.format(lang, lang, num, num) con.commit() res = Response() body = form_body.format(content) res.set_body(get_htmltemplate("軽量言語アンケート DB版").format(body)) print(res)
def notapplicable(): body = u"該当がありません" res = Response() res.set_body(get_htmltemplate() % body) print res
req = Request() con = MySQLdb.connect(host = 'localhost', db = 'usermanage', user = '******', passwd = 'python', charset = 'utf8') cur = con.cursor(MySQLdb.cursors.DictCursor) str = req.form.getvalue('custname', 'none') radio = req.form.getvalue('cust', 'none') template_path = '/var/www/html/cpy/result.html' if str == "none": body = u"テキストフィールドに検索する文字を入力してください" res = Response() res.set_body(get_htmltemplate() % body) print res elif radio == "custini": cur.execute("""SELECT * FROM main WHERE custini = '%s' FOR UPDATE""" % str) con.commit() temp = cur.fetchall() if temp: item = temp[0] t = SimpleTemplate(file_path = template_path) body = t.render(item) res = Response() res.set_body(body) print res else: notapplicable()
def hello(): """Return a friendly HTTP greeting.""" body = get_htmltemplate() return body.format(title="Simple Stopwatch", script=script, body=timerHtml)