2017年4月8日土曜日

開発環境

Head First Python (Paul Barry (著)、O'Reilly Media)のChapter 10.(Function Decorators: Wrapping Functions) の SHARPEN YOUR PENCIL(No. 7022) を取り組んでみる。

SHARPEN YOUR PENCIL(No. 7022)

コード(Emacs)

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from flask import Flask, session

app = Flask(__name__)

app.secret_key = 'YouWillNeverGuess'


@app.route('/login')
def do_login() -> str:
    session['logged_in'] = True
    return 'You are now logged in'


@app.route('/logout')
def do_logout() -> str:
    if 'logged_in' in session:
        del session['logged_in']
    return 'You are now logged out'


@app.route('/status')
def do_status() -> str:
    if 'logged_in' in session:
        return 'You are currently logged in'
    return 'You are NOT logged in'

if __name__ == '__main__':
    app.run(debug=True)

入出力結果(Terminal, IPython)

$ ./sample2.py
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
 * Restarting with stat
 * Debugger is active!
 * Debugger PIN: 873-014-066
127.0.0.1 - - [08/Apr/2017 18:55:49] "GET /login HTTP/1.1" 200 -
127.0.0.1 - - [08/Apr/2017 18:55:50] "GET /login HTTP/1.1" 200 -
127.0.0.1 - - [08/Apr/2017 18:55:52] "GET /logout HTTP/1.1" 200 -
127.0.0.1 - - [08/Apr/2017 18:55:52] "GET /logout HTTP/1.1" 200 -
127.0.0.1 - - [08/Apr/2017 18:55:56] "GET /search4 HTTP/1.1" 404 -
127.0.0.1 - - [08/Apr/2017 18:55:56] "GET /status HTTP/1.1" 200 -
127.0.0.1 - - [08/Apr/2017 18:55:56] "GET /status HTTP/1.1" 200 -
127.0.0.1 - - [08/Apr/2017 18:55:59] "GET / HTTP/1.1" 404 -
127.0.0.1 - - [08/Apr/2017 18:55:59] "GET /login HTTP/1.1" 200 -
127.0.0.1 - - [08/Apr/2017 18:56:00] "GET /login HTTP/1.1" 200 -
127.0.0.1 - - [08/Apr/2017 18:56:01] "GET /login HTTP/1.1" 200 -
127.0.0.1 - - [08/Apr/2017 18:56:03] "GET /login HTTP/1.1" 200 -
127.0.0.1 - - [08/Apr/2017 18:56:04] "GET /logout HTTP/1.1" 200 -
127.0.0.1 - - [08/Apr/2017 18:56:07] "GET /status HTTP/1.1" 200 -
127.0.0.1 - - [08/Apr/2017 18:56:07] "GET /status HTTP/1.1" 200 -
127.0.0.1 - - [08/Apr/2017 18:56:10] "GET /status HTTP/1.1" 200 -
127.0.0.1 - - [08/Apr/2017 18:56:12] "GET / HTTP/1.1" 404 -
127.0.0.1 - - [08/Apr/2017 18:56:12] "GET /login HTTP/1.1" 200 -
127.0.0.1 - - [08/Apr/2017 18:56:13] "GET /login HTTP/1.1" 200 -
127.0.0.1 - - [08/Apr/2017 18:56:16] "GET /search4 HTTP/1.1" 404 -
127.0.0.1 - - [08/Apr/2017 18:56:17] "GET /status HTTP/1.1" 200 -
127.0.0.1 - - [08/Apr/2017 18:56:17] "GET /status HTTP/1.1" 200 -
127.0.0.1 - - [08/Apr/2017 18:56:19] "GET /status HTTP/1.1" 200 -
127.0.0.1 - - [08/Apr/2017 18:56:21] "GET / HTTP/1.1" 404 -
127.0.0.1 - - [08/Apr/2017 18:56:22] "GET /login HTTP/1.1" 200 -
127.0.0.1 - - [08/Apr/2017 18:56:24] "GET /login HTTP/1.1" 200 -
127.0.0.1 - - [08/Apr/2017 18:56:24] "GET /logout HTTP/1.1" 200 -
127.0.0.1 - - [08/Apr/2017 18:56:24] "GET /logout HTTP/1.1" 200 -
127.0.0.1 - - [08/Apr/2017 18:56:25] "GET /logout HTTP/1.1" 200 -
127.0.0.1 - - [08/Apr/2017 18:56:29] "GET /login HTTP/1.1" 200 -
127.0.0.1 - - [08/Apr/2017 18:56:29] "GET /login HTTP/1.1" 200 -
127.0.0.1 - - [08/Apr/2017 18:56:32] "GET /search4 HTTP/1.1" 404 -
127.0.0.1 - - [08/Apr/2017 18:56:32] "GET /status HTTP/1.1" 200 -
127.0.0.1 - - [08/Apr/2017 18:56:33] "GET /status HTTP/1.1" 200 -
127.0.0.1 - - [08/Apr/2017 18:56:34] "GET /status HTTP/1.1" 200 -
127.0.0.1 - - [08/Apr/2017 18:56:37] "GET /login HTTP/1.1" 200 -
127.0.0.1 - - [08/Apr/2017 18:56:37] "GET /lgout HTTP/1.1" 404 -
127.0.0.1 - - [08/Apr/2017 18:56:40] "GET /login HTTP/1.1" 200 -
127.0.0.1 - - [08/Apr/2017 18:56:40] "GET /logout HTTP/1.1" 200 -
127.0.0.1 - - [08/Apr/2017 18:56:40] "GET /logout HTTP/1.1" 200 -
127.0.0.1 - - [08/Apr/2017 18:56:47] "GET /logout HTTP/1.1" 200 -
127.0.0.1 - - [08/Apr/2017 18:56:47] "GET /logout HTTP/1.1" 200 -
127.0.0.1 - - [08/Apr/2017 18:56:48] "GET /logout HTTP/1.1" 200 -
127.0.0.1 - - [08/Apr/2017 18:56:51] "GET /search4 HTTP/1.1" 404 -
127.0.0.1 - - [08/Apr/2017 18:56:51] "GET /status HTTP/1.1" 200 -
127.0.0.1 - - [08/Apr/2017 18:56:51] "GET /status HTTP/1.1" 200 -
127.0.0.1 - - [08/Apr/2017 18:56:52] "GET /status HTTP/1.1" 200 -
  C-c C-c$

0 コメント:

コメントを投稿

Comments on Google+: