Beispiel #1
0
def webapp(request):
    app = Flask(__name__)
    app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite://"
    app.config["PROPAGATE_EXCEPTIONS"] = True

    db = SQLAlchemy(app)

    class Object(db.Model):
        id = db.Column(db.Integer, primary_key=True)
        field1 = db.Column(db.Integer)
        field2 = db.Column(db.Integer)

    db.create_all()

    @app.route("/objects")
    @paginated_view
    @sorted_view(allowed_fields=["id", "field1"])
    def view_objects():
        return Object.query

    @app.route("/objects_different_renderer")
    @paginated_view(renderer=lambda obj: {"id_value": obj.id})
    def view_objects_different_renderer():
        return Object.query

    @app.route("/objects_limited_page_size")
    @paginated_view(max_page_size=10, default_page_size=5)
    def view_objects_limited_page_size():
        return Object.query

    @app.route("/objects_no_count")
    @paginated_view(max_page_size=10, default_page_size=5, include_count=False)
    def view_objects_no_count():
        return Object.query


    @app.route("/objects_by_field2")
    @paginated_view
    @sorted_view(default="-field2")
    def view_objects_by_field2():
        return Object.query


    num_objects = 100
    field1_values = list(range(num_objects))
    random.shuffle(field1_values)
    field2_values = list(range(num_objects))
    random.shuffle(field2_values)

    for field1_value, field2_value in zip(field1_values, field2_values):
        db.session.add(Object(field1=field1_value, field2=field2_value))

    db.session.commit()

    returned = App(app)
    returned.num_objects = num_objects
    returned.activate()
    request.addfinalizer(returned.deactivate)

    return returned
Beispiel #2
0
def setup_app(env, debug=False, output_path=None, lang="en"):
    app = Flask("lektor.admin")
    app.lektor_info = LektorInfo(env, output_path, lang)
    app.debug = debug
    app.config["PROPAGATE_EXCEPTIONS"] = True

    register_modules(app)

    return app
Beispiel #3
0
def app_context():
    app = Flask(__name__)
    app.config["SECRET_KEY"] = "deterministic"
    app.config["TESTING"] = True
    app.config["PROPAGATE_EXCEPTIONS"] = True
    app.config["DEBUG"] = True

    @app.route("/")
    def index():
        return u"The index"

    @app.route("/login")
    def login():
        id = int(request.args["id"])
        force = "force" in request.args
        remember = "remember" in request.args
        if login_user(USERS[id], force=force, remember=remember):
            if "permanent" in request.args:
                session.permanent = True
            return u"Logged in"
        else:
            return u"Go away, creeper"

    class Protected(LoginRequiredMixin, MethodView):
        def get(self):
            return u"Welcome, %s" % current_user.name

    app.add_url_rule("/protected", view_func=Protected.as_view("protected"))

    @app.route("/sensitive-action")
    @fresh_login_required
    def sensitive_action():
        return u"Be careful, %s" % current_user.name

    @app.route("/logout")
    @login_required
    def logout():
        logout_user()
        return u"Logged out"

    @app.route("/reauth")
    @login_required
    def reauth():
        confirm_login()
        return u"Login confirmed"

    with app.test_request_context():
        yield app
Beispiel #4
0
def app_context():
    app = Flask(__name__)
    app.config["SECRET_KEY"] = "deterministic"
    app.config["TESTING"] = True
    app.config["PROPAGATE_EXCEPTIONS"] = True
    app.config["DEBUG"] = True
    
    @app.route("/")
    def index():
        return u"The index"
    
    @app.route("/login")
    def login():
        id = int(request.args["id"])
        force = "force" in request.args
        remember = "remember" in request.args
        if login_user(USERS[id], force=force, remember=remember):
            if "permanent" in request.args:
                session.permanent = True
            return u"Logged in"
        else:
            return u"Go away, creeper"
    
    @app.route("/protected")
    @login_required
    def protected():
        return u"Welcome, %s" % current_user.name
    
    @app.route("/logout")
    @login_required
    def logout():
        logout_user()
        return u"Logged out"
    
    @app.route("/reauth")
    @login_required
    def reauth():
        confirm_login()
        return u"Login confirmed"
    
    with app.test_request_context():
        yield app
Beispiel #5
0
    def create_application():
        """Create a test Flask application.
        """
        ret_val = Flask(__name__)
        ret_val.testing = True
        ret_val.config["EXCEPTIONAL_API_KEY"] = "key"
        ret_val.config["EXCEPTIONAL_DEBUG_URL"] = environ.get(
            "EXCEPTIONAL_DEBUG_URL", "http://posttestserver.com/post.php")
        ret_val.config["PROPAGATE_EXCEPTIONS"] = False

        @ret_val.route("/error")
        def error():
            """Do something that raises an exception.
            """
            1 / 0

        @ret_val.route("/http/<int:code>")
        def http(code):
            """Raises an HTTP exception.
            """
            abort(code)

        return ret_val
Beispiel #6
0
__author__ = 'dhtik_000'
from flask import Flask, url_for, request, redirect, render_template, make_response, jsonify
from database import *
import courses as C


app = Flask(__name__)
app.config["DEBUG"] = True
app.config["PROPAGATE_EXCEPTIONS"] = True

@app.route("/")
def main():
    user = request.cookies.get("last_user", "none")
    token = request.cookies.get("token", "none")
    token = authenticate(user, token)

    if token[:2] == "_$":
        response = make_response(redirect(url_for("dashboard")))
        response.set_cookie("last_user", user)
        response.set_cookie("token", token)
        C.load_courses(user)
        return response
    else:
        if token == "Timeout":
            return redirect(url_for("logout"))
    return redirect(url_for("login"))

@app.route("/login", methods=["GET", "POST"])
def login():
    if request.method == "POST":
        user = request.form['username']
Beispiel #7
0
from flask_babel import gettext as _
from sqlalchemy import create_engine

import backend
import loghelper

from config import config, LANGUAGES
from decorators import crossdomain
from metrics import StatsdClient

# set up flask
app = Flask(__name__)
app.config.from_object(__name__)
app.config["STATIC_URL"] = 'static'
app.config["STATIC_ROOT"] = 'static'
app.config["PROPAGATE_EXCEPTIONS"] = False
babel = Babel(app)

# flask-assets
assets = Environment(app)
assets.cache = "/tmp/"
assets.init_app(app)

# logger
logger = logging.getLogger('kilink.kilink')

# metrics
metrics = StatsdClient("linkode")


def nocache(f):
from flask import Flask, render_template, request
from uwsgidecorators import *
from xkcd_colors import xkcd_names_to_hex
import webcolors
import time
from random import randint

import socket
from ola.ClientWrapper import ClientWrapper
import array
import sys

wrapper = None

public = Flask(__name__)
public.config["PROPAGATE_EXCEPTIONS"] = True

# Include "no-cache" header in all POST responses
@public.after_request
def add_no_cache(response):
    if request.method == "POST":
        response.cache_control.no_cache = True
    return response


### Home page ###
@public.route("/")
@public.route("/index.html")
def default_page():
    return render_template("/index.html")
Beispiel #9
0
import sys

from flask import Flask

from httpobs.conf import DEVELOPMENT_MODE, API_PORT, API_PROPAGATE_EXCEPTIONS
from httpobs.website import add_response_headers
from httpobs.website.api import api
from httpobs.website.monitoring import monitoring_api


def __exit_with(msg: str) -> None:
    print(msg)
    sys.exit(1)


# Register the application with flask
app = Flask("http-observatory")
app.config["PROPAGATE_EXCEPTIONS"] = API_PROPAGATE_EXCEPTIONS
app.register_blueprint(api)
app.register_blueprint(monitoring_api)


@app.route("/")
@add_response_headers()
def main() -> str:
    return "Welcome to the HTTP Observatory!"


if __name__ == "__main__":
    app.run(debug=DEVELOPMENT_MODE, port=API_PORT)