wave-ttt/tictactoe.py

24 lines
520 B
Python
Raw Normal View History

2017-09-30 08:43:09 -07:00
from flask import Flask, abort, request
2017-09-30 08:11:17 -07:00
app = Flask(__name__)
@app.route('/')
def hello():
2017-09-30 08:43:09 -07:00
board = _get_board_or_abort()
return board
def _get_board_or_abort():
'''
Get the board from the request, or abort the request with a 400 error.
'''
board = request.args.get('board', None)
is_valid = all(
board is not None, # 'board' var must exist.
len(board) >= 9, # Board should be at least 9 characters long.
)
if not is_valid:
abort(400)
return board