def test_new_delayed_construction_with_default(self):
        app = Flask(__name__)

        ext = KVSessionExtension(self.store)
        ext.init_app(app)

        self.assertIs(self.store, app.kvsession_store)
def create_app(store):
    app = Flask(__name__)

    app.kvsession = KVSessionExtension(store, app)

    @app.route('/')
    def index():
        return 'nothing to see here, move along'

    @app.route('/store-in-session/<key>/<value>/')
    def store(key, value):
        session[key] = value
        return 'stored %r at %r' % (value, key)

    @app.route('/store-datetime/')
    def store_datetime():
        t = datetime(2011, 8, 10, 15, 46, 00)
        session['datetime_key'] = t
        return 'ok'

    @app.route('/delete-from-session/<key>/')
    def delete(key):
        del session[key]
        return 'deleted %r' % key

    @app.route('/destroy-session/')
    def destroy():
        session.destroy()
        return 'session destroyed'

    @app.route('/make-session-permanent/')
    def make_permanent():
        session.permanent = True
        return 'made session permanent'

    @app.route('/dump-session/')
    def dump():
        return json.dumps(dict(session))

    @app.route('/dump-datetime/')
    def dump_datetime():
        return str(session['datetime_key'])

    @app.route('/regenerate-session/')
    def regenerate():
        session.regenerate()
        return 'session regenerated'

    @app.route('/is-kvsession/')
    def is_kvsession():
        return str(isinstance(session._get_current_object(), KVSession))

    @app.route('/is-new-session/')
    def is_new_session():
        return str(session.new)

    return app
Exemple #3
0
def setup_application_extensions(app, login_view='/login'):
    mc = memcache.Client([config.get('app', 'mc')],
                         debug=int(config.get('app', 'mc_debug')))
    store = MemcacheStore(mc)

    KVSessionExtension(store, app)
    login_manager.login_view = login_view
    login_manager.init_app(app)
    return login_manager
    def test_first_request(self):
        store = DictStore()

        app = Flask(__name__)
        app.config['SECRET_KEY'] = 'topsecret'

        KVSessionExtension(store, app)

        @app.route('/')
        def index():
            session.regenerate()
            return 'OK'

        client = app.test_client()
        client.get('/')
    def test_new_delayed_construction(self):
        app = Flask(__name__)

        ext = KVSessionExtension()

        with self.assertRaises(ValueError):
            ext.init_app(app)

        ext.init_app(app, self.store)

        self.assertIs(self.store, app.kvsession_store)
Exemple #6
0
def main():
    parser = argparse.ArgumentParser(description='Dahu web frontend')
    parser.add_argument('config',
                        help='Dahu configuration file (default: config.py)')
    args = parser.parse_args()

    # App related initialization
    app = Flask(__name__)
    app.config.from_pyfile(os.path.join(os.getcwd(), args.config))
    app.register_blueprint(frontend, url_prefix=app.config['FRONTEND_PREFIX'])

    # Session KVSession
    session_store = DictStore()
    KVSessionExtension(session_store, app)

    app.debug = True
    app.run(host=app.config['FRONTEND_HOST'], port=app.config['FRONTEND_PORT'])
Exemple #7
0
import httplib2

from worker import conn
from models import db, User, Music, Video
from admin import AdminModelView
from youtube_utils import process_video_request, youtube_service, VideoMeta
from utils import detect_default_email, auth_required
from forms import EmailForm, flash_errors

rand = SystemRandom()
app = Flask(__name__)
app.config.from_pyfile("settings.py")
db.init_app(app)

store = DictStore()
KVSessionExtension(store, app)

worker_queue = Queue(connection=conn)

if os.environ.get("HEROKU") is not None:
    import logging
    stream_handler = logging.StreamHandler()
    app.logger.addHandler(stream_handler)
    app.logger.setLevel(logging.INFO)
    app.logger.info("starting app")

if os.environ.get("DEBUG", False):
    app.config["DEBUG"] = True

flow = OAuth2WebServerFlow(client_id=app.config["GOOGLE_CLIENT_ID"],
                           client_secret=app.config["GOOGLE_CLIENT_SECRET"],
Exemple #8
0
from flask import Flask, redirect, url_for, render_template, request, session
from werkzeug import secure_filename
from simplekv.fs import FilesystemStore
from flaskext.kvsession import KVSessionExtension
import re
import os.path
import sqlite3
import logging

import err
import const

app = Flask(__name__)

store = FilesystemStore('data')
sess_ext = KVSessionExtension(store, app)


#TODO test this
@app.route('/')
def index():
    if not is_logged_in():
        return redirect(url_for('login'))
    else:
        return redirect(url_for('upload'))


#TODO test this
@app.route('/register', methods=['POST', 'GET'])
def register():
    '''On form submit attempt to create the user if the provided credentials
Exemple #9
0
from flaskext.kvsession import KVSessionExtension
from simplekv.db.sql import SQLAlchemyStore
import pytz


logging_conf = '/etc/narwhal/logging.conf'
if os.path.exists(logging_conf):
    logging.config.fileConfig(logging_conf, disable_existing_loggers=False)

logger = logging.getLogger(__name__)

app = Flask(__name__)
app.config.from_pyfile('config.py')
db = SQLAlchemy(app)
kv_store = SQLAlchemyStore(db.engine, db.metadata, 'kvstore')
KVSessionExtension(kv_store, app)


class GoogleAccount(db.Model):
    __tablename__ = 'GoogleAccount'
    id = db.Column(db.String(80), primary_key=True)
    credentials = db.Column(db.PickleType)
    email = db.Column(db.String(256))
    reddit_accounts = db.relationship('RedditAccount', backref='google_account',
                                      cascade="all, delete, delete-orphan")
    settings = db.relationship('AccountSettings', uselist=False,
                               cascade="all, delete, delete-orphan")
    sent_posts = db.relationship('SentPost', lazy='dynamic',
                                 cascade="all, delete, delete-orphan")
    sent_pms = db.relationship('SentPrivateMessage', lazy='dynamic',
                               cascade="all, delete, delete-orphan")
Exemple #10
0
from oauth2client.appengine import StorageByKeyName
from oauth2client.appengine import CredentialsModel

from simplekv.memory import DictStore
from flaskext.kvsession import KVSessionExtension

from google.appengine.ext import ndb
from models import CronCards, UserProperties

glassdailycard = Flask('glass-daily-card')
glassdailycard.secret_key = ''.join(
    random.choice(string.ascii_uppercase + string.digits) for x in xrange(32))

# Handles our sessions
store = DictStore()
KVSessionExtension(store, glassdailycard)


def _oauth_flow():
    """Prepare an OAuth flow."""
    required_scopes = ('https://www.googleapis.com/auth/glass.location',
                       'https://www.googleapis.com/auth/glass.timeline',
                       'https://www.googleapis.com/auth/plus.login')
    oauthflow = flow_from_clientsecrets('client_secrets.json',
                                        scope=required_scopes,
                                        redirect_uri='postmessage')
    oauthflow.params['access_type'] = 'offline'
    return oauthflow


def _authorized_http(credentials):