<commit_before>from time import sleep
from flask import Flask, request, render_template, url_for, redirect
from flask_restful import Api
from flask_login import LoginManager, login_user, login_required, current_user, logout_user

from models.users import Users
from config import APP_CONFIG
from webapp2_extras import security
from forms import LoginForm
from forms import RegisterFormExt

from resources.users import UsersResource
from resources.tasks import TasksResource

app = Flask(__name__)
app.config.update(APP_CONFIG)
api = Api(app)
login_manager = LoginManager()
login_manager.init_app(app)
login_manager.login_view = 'login'
login_manager.login_message = 'Please login to access this page.'


@login_manager.user_loader
def user_loader(username):
	return Users.get_by_username(username)


@app.route('/', methods=['GET'])
def default():
	return render_template('index.html')


@app.route('/login', methods=['GET', 'POST'])
def login():
	if current_user.is_authenticated:
		return redirect('dashboard')

	form = LoginForm(csrf_enabled=False)
	if request.method == 'POST' and form.validate_on_submit():
		form.user.is_authenticated = True
		form.user.put()
		login_user(form.user, remember=form.remember_me.data)<commit_msg>flask_restful Api subclass `MyApi` definition for handling application exceptions in restful requests.<commit_after>from time import sleep
from flask import Flask, request, render_template, url_for, redirect
from flask_restful import Api
from flask_login import LoginManager, login_user, login_required, current_user, logout_user
from models.users import Users
from config import APP_CONFIG
from webapp2_extras import security
from forms import LoginForm
from forms import RegisterFormExt
from resources.users import UsersResource
from resources.tasks import TasksResource

app = Flask(__name__)
app.config.update(APP_CONFIG)
login_manager = LoginManager()
login_manager.init_app(app)
login_manager.login_view = 'login'
login_manager.login_message = 'Please login to access this page.'


class MyApi(Api):
	def handle_error(self, e):
		code = getattr(e, 'code', 500)
		if code == 500:
			error_code = e.error_code
			message = 'something went wrong'
			if error_code:
				message = e.message
			else:
				error_code = code
			return self.make_response({'message': message}, error_code)
		return super(MyApi, self).handle_error(e)


api = MyApi(app)


@login_manager.user_loader
def user_loader(username):
	return Users.get_by_username(username)


@app.route('/', methods=['GET'])
def default():
	return render_template('index.html')


@app.route('/login', methods=['GET', 'POST'])
def login():
	if current_user.is_authenticated:
		return redirect('dashboard')

	form = LoginForm(csrf_enabled=False)
	if request.method == 'POST' and form.validate_on_submit():
		form.user.is_authenticated = True
		form.user.put()
		login_user(form.user, remember=form.remember_me.data)
{'fraction_non_alphanumeric': 0.09824198552223372, 'fraction_numerical': 0.002757669769045157, 'mean_word_length': 6.236907730673317, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1014674', 'n_tokens_mistral': 929, 'n_tokens_neox': 875, 'n_words': 244}