def generate_app(): app = Flask(__name__, template_folder=gru.utils.fs.relative_to( __file__, 'gru/templates'), static_folder=gru.utils.fs.relative_to(__file__, 'gru/static')) app.debug = settings.get('flask.debug') app.permanent_session_lifetime = settings.get('flask.session_seconds') # Client-side sessions with signed cookies app.secret_key = settings.get('flask.secret_key') app.session_interface = ItsdangerousSessionInterface() # Setup logging gru.utils.logs.setup_logging(app, settings) # CSRF protection SeaSurf(app) # Load sub-applications app.register_blueprint(auth_views, url_prefix='/auth') app.register_blueprint(inventory_views, url_prefix='/inventory') # Append plugin paths to sys.path for directory in settings.get('plugins.directories'): sys.path.append(os.path.abspath(os.path.expanduser(directory))) # Register plugins root_path = os.path.realpath(__file__) app.plugins = PluginRegistry(app, settings) for plugin_path in settings.get('plugins.modules'): app.plugins.register(plugin_path) # Also add authentication backend and inventory provider app.plugins.register(settings.get('authentication.backend')) app.plugins.register(settings.get('inventory.provider')) gru.utils.templates.setup(app) gru.utils.web.setup_base_views(app, settings) app.wsgi_app = gru.utils.web.method_rewrite_middleware(app.wsgi_app) return app
""" exercises = db_session.query(Exercise).all() accept = request.headers.get('ACCEPT') resp = None if accept == "application/json": resp = "[" i = 0 for exercise in exercises: resp += jsonify(exercise.serialize).get_data() if i < len(exercises) - 1: resp += (",") i += 1 resp += ("]") resp = Response(resp, mimetype='application/json') else: resp = "<exercises>" for exercise in exercises: resp += "\n" resp += xmlify(exercise.serialize, wrap="exercise", indent=" ") resp += ("\n</exercises>") resp = Response(resp, mimetype='application/xml') return resp if __name__ == '__main__': app.debug = True app.secret_key = 'S6T4o9ramSyTWCa6r!msy9D^uDE' csrf = SeaSurf(app) app.run(host='0.0.0.0', port=80) #app.run(host='0.0.0.0')
from datetime import date, timedelta from types import FunctionType, ModuleType from flask import Flask, redirect, request, session, url_for from flask.ext.funnel import Funnel from flask.ext.markdown import Markdown from flask.ext.seasurf import SeaSurf from standup.apps.status.helpers import get_weeks from standup.apps.status.models import Project from standup.apps.users.models import Team, User from standup.database import get_session from standup.errors import register_error_handlers from standup.filters import register_filters from standup.mdext import nixheaders csrf = SeaSurf() def _get_apps_full_names(apps): names = [] for app in apps: parts = [] if not __name__ == '__main__': parts = __name__.split('.') parts.pop() parts.append('apps') parts.append(app) names.append('.'.join(parts)) return names
from flask import Flask, render_template, request, redirect, url_for, flash from flask import jsonify, session as login_session, make_response from flask.ext.seasurf import SeaSurf from dicttoxml import dicttoxml from sqlalchemy import create_engine, asc from sqlalchemy.orm import sessionmaker from database_setup import Base, Author, Book, User from oauth2client.client import flow_from_clientsecrets, FlowExchangeError from oauth2client import client, crypt from functools import wraps import json, random, string, httplib2, requests # Flask Setup app = Flask(__name__) csrf = SeaSurf() csrf.init_app(app) # Client ID for Google Oauth CLIENT_ID = json.loads( open('client_secrets.json', 'r').read())['web']['client_id'] APPLICATION_NAME = "Catalog" # SQL setup engine = create_engine('sqlite:///catalog.db') Base.metadata.bind = engine DBSession = sessionmaker(bind=engine) session = DBSession() # Generate anti-request-forgery state token, render login page
import random import string from daos import UserDAO, RestaurantDAO, MenuItemDAO from flask import (Flask, render_template, request, redirect, url_for, flash, session as login_session, make_response) from flask.ext.seasurf import SeaSurf from werkzeug import SharedDataMiddleware, secure_filename from project_api_endpoints import api_json, api_atom from project_oauth import oauth # App constants ALLOWED_FILES = set(["png", "jpg", "jpeg", "gif"]) # Initialize app app = Flask(__name__) csrf = SeaSurf(app) # Extension to prevent cross-site request forgery (CSRF) app.debug = True # if True Flash will reload the code on every change app.secret_key = "super_insecure_key" app.config["UPLOAD_FOLDER"] = os.path.join('/tmp') # Not permanent at Heroku!! app.config["MAX_CONTENT_LENGTH"] = 1024 * 1024 # = 1 Megabyte app.add_url_rule("/uploads/<filename>", "uploaded_file", build_only=True) # This lets us use the route /uploads although it does not phisically exist app.wsgi_app = SharedDataMiddleware(app.wsgi_app, {"/uploads": app.config["UPLOAD_FOLDER"]}) # Register blueprints from project_api_endpoint.py and project_oauth.py app.register_blueprint(api_json) app.register_blueprint(api_atom) app.register_blueprint(oauth) # Instantiate our Data Access Objects
""" Module which results with a ready to use wsgi application. """ import logging.config import os from flask import Flask, render_template from flask.ext.mongoengine import MongoEngine, MongoEngineSessionInterface from flask.ext.seasurf import SeaSurf # Set up the application app = Flask('victims_web') # CSRF protection csrf = SeaSurf(app) # configuration app.config.from_object('victims_web.config') # logging logging.basicConfig( filename=os.path.join(app.config.get('LOG_FOLDER'), 'server.log'), format='%(asctime)s - %(levelname)s: %(message)s', datefmt='%a %b %d %Y %H:%M:%S %Z', level=app.config['LOG_LEVEL'], ) app._logger = app.config.get('LOGGER') # debug enhancements if app.debug and not app.testing:
def init_seasurf(app): app.csrf = SeaSurf(app)