<s> import os <EOL> from flask import Flask , request , render_template <EOL> from flask . ext . babel import Babel <EOL> from . config import DefaultConfig <EOL> from . user import User , user <EOL> from . settings import settings <EOL> from . frontend import frontend <EOL> from . api import api <EOL> from . admin import admin <EOL> from . extensions import db , mail , cache , login_manager , oid <EOL> from . utils import INSTANCE_FOLDER_PATH <EOL> __all__ = [ '<STR_LIT>' ] <EOL> DEFAULT_BLUEPRINTS = ( <EOL> frontend , <EOL> user , <EOL> settings , <EOL> api , <EOL> admin , <EOL> ) <EOL> def create_app ( config = None , app_name = None , blueprints = None ) : <EOL> """<STR_LIT>""" <EOL> if app_name is None : <EOL> app_name = DefaultConfig . PROJECT <EOL> if blueprints is None : <EOL> blueprints = DEFAULT_BLUEPRINTS <EOL> app = Flask ( app_name , instance_path = INSTANCE_FOLDER_PATH , instance_relative_config = True ) <EOL> configure_app ( app , config ) <EOL> configure_hook ( app ) <EOL> configure_blueprints ( app , blueprints ) <EOL> configure_extensions ( app ) <EOL> configure_logging ( app ) <EOL> configure_template_filters ( app ) <EOL> configure_error_handlers ( app ) <EOL> return app <EOL> def configure_app ( app , config = None ) : <EOL> """<STR_LIT>""" <EOL> app . config . from_object ( DefaultConfig ) <EOL> app . config . from_pyfile ( '<STR_LIT>' , silent = True ) <EOL> if config : <EOL> app . config . from_object ( config ) <EOL> def configure_extensions ( app ) : <EOL> db . init_app ( app ) <EOL> mail . init_app ( app ) <EOL> cache . init_app ( app ) <EOL> babel = Babel ( app ) <EOL> @ babel . localeselector <EOL> def get_locale ( ) : <EOL> accept_languages = app . config . get ( '<STR_LIT>' ) <EOL> return request . accept_languages . best_match ( accept_languages ) <EOL> login_manager . login_view = '<STR_LIT>' <EOL> login_manager . refresh_view = '<STR_LIT>' <EOL> @ login_manager . user_loader <EOL> def load_user ( id ) : <EOL> return User . query . get ( id ) <EOL> login_manager . setup_app ( app ) <EOL> oid . init_app ( app ) <EOL> def configure_blueprints ( app , blueprints ) : <EOL> """<STR_LIT>""" <EOL> for blueprint in blueprints : <EOL> app . register_blueprint ( blueprint ) <EOL> def configure_template_filters ( app ) : <EOL> @ app . template_filter ( ) <EOL> def pretty_date ( value ) : <EOL> return pretty_date ( value ) <EOL> @ app . template_filter ( ) <EOL> def format_date ( value , format = '<STR_LIT>' ) : <EOL> return value . strftime ( format ) <EOL> def configure_logging ( app ) : <EOL> """<STR_LIT>""" <EOL> if app . debug or app . testing : <EOL> return <EOL> import logging <EOL> from logging . handlers import SMTPHandler <EOL> app . logger . setLevel ( logging . INFO ) <EOL> info_log = os . path . join ( app . config [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> info_file_handler = logging . handlers . RotatingFileHandler ( info_log , maxBytes = <NUM_LIT> , backupCount = <NUM_LIT:10> ) <EOL> info_file_handler . setLevel ( logging . INFO ) <EOL> info_file_handler . setFormatter ( logging . Formatter ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> ) <EOL> app . logger . addHandler ( info_file_handler ) <EOL> mail_handler = SMTPHandler ( app . config [ '<STR_LIT>' ] , <EOL> app . config [ '<STR_LIT>' ] , <EOL> app . config [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' % app . config [ '<STR_LIT>' ] , <EOL> ( app . config [ '<STR_LIT>' ] , <EOL> app . config [ '<STR_LIT>' ] ) ) <EOL> mail_handler . setLevel ( logging . ERROR ) <EOL> mail_handler . setFormatter ( logging . Formatter ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> ) <EOL> app . logger . addHandler ( mail_handler ) <EOL> def configure_hook ( app ) : <EOL> @ app . before_request <EOL> def before_request ( ) : <EOL> pass <EOL> def configure_error_handlers ( app ) : <EOL> @ app . errorhandler ( <NUM_LIT> ) <EOL> def forbidden_page ( error ) : <EOL> return render_template ( "<STR_LIT>" ) , <NUM_LIT> <EOL> @ app . errorhandler ( <NUM_LIT> ) <EOL> def page_not_found ( error ) : <EOL> return render_template ( "<STR_LIT>" ) , <NUM_LIT> <EOL> @ app . errorhandler ( <NUM_LIT> ) <EOL> def server_error_page ( error ) : <EOL> return render_template ( "<STR_LIT>" ) , <NUM_LIT> </s>
