__version__ = '0.1.0' __api_version__ = '0.1.0' APP = flask.Flask(__name__) APP.config.from_object('pkgdb2.default_config') if 'PKGDB2_CONFIG' in os.environ: # pragma: no cover APP.config.from_envvar('PKGDB2_CONFIG') if APP.config.get('LOGGER_CONFIG_FILE') \ and os.path.exists(APP.config['LOGGER_CONFIG_FILE']): logging.config.fileConfig(APP.config['LOGGER_CONFIG_FILE']) # Set up FAS extension FAS = FAS(APP) # Initialize the cache. CACHE = dogpile.cache.make_region().configure( APP.config.get('PKGDB2_CACHE_BACKEND', 'dogpile.cache.memory'), **APP.config.get('PKGDB2_CACHE_KWARGS', {})) # Set up the logger ## Send emails for big exception mail_handler = logging.handlers.SMTPHandler( APP.config.get('SMTP_SERVER', '127.0.0.1'), '*****@*****.**', APP.config.get('MAIL_ADMIN', '*****@*****.**'), 'PkgDB2 error') mail_handler.setFormatter( logging.Formatter(''' Message type: %(levelname)s Location: %(pathname)s:%(lineno)d
import logging from logging.handlers import RotatingFileHandler from flask import Flask, request, g, redirect, url_for, flash from flask.ext.fas_openid import FAS from fudcon.database import db from fudcon.ui.frontend.utils import avatar_url from functools import wraps # Instantiate application. app = Flask(__name__) app.config.from_object('config.DevelopmentConfig') # Instantiate database object db.init_app(app) # Set up FAS FAS = FAS(app) def is_safe_url(target): ref_url = urlparse.urlparse(request.host_url) test_url = urlparse.urlparse(urlparse.urljoin(request.host_url, target)) return test_url.scheme in ('http', 'https') and \ ref_url.netloc == test_url.netloc def authenticated(): return hasattr(g, 'fas_user') and g.fas_user def is_admin(app): if not authenticated() \