当前位置: 首页>>代码示例>>Python>>正文


Python default_exceptions.iterkeys函数代码示例

本文整理汇总了Python中werkzeug.exceptions.default_exceptions.iterkeys函数的典型用法代码示例。如果您正苦于以下问题:Python iterkeys函数的具体用法?Python iterkeys怎么用?Python iterkeys使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了iterkeys函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: make_json_app

def make_json_app(import_name):
    """
    Creates a JSON-oriented Flask app.

    All error responses that you don't specifically
    manage yourself will have application/json content
    type, and will contain JSON like this (just an example):

    { "message": "405: Method Not Allowed" }
    """
    def make_json_error(ex):
        message = str(ex)
        status = ''
        code = 500
        if isinstance(ex, HTTPException):
            code = ex.code
        else:
            code = 500

        if code in [401, 403, 405, 415]:
            status = 'fail'
            response = jsonify(status=status, data=None)
        else:
            status = 'error'
            response = jsonify(status=status, data=None,  message=message)
        response.status_code = code
        return response

    app = Flask(import_name)

    for code in default_exceptions.iterkeys():
        app.error_handler_spec[None][code] = make_json_error
    return app
开发者ID:EuresTools,项目名称:eVote-API-old,代码行数:33,代码来源:app.py

示例2: make_json_app

def make_json_app(import_name, **kwargs):
    """
    Creates a JSON-oriented Flask app.

    All error responses that you don't specifically
    manage yourself will have application/json content
    type, and will contain JSON like this (just an example):

    { "message": "405: Method Not Allowed" }
    """
    def make_json_error(ex):
        pprint.pprint(ex)
        pprint.pprint(ex.code)
        #response = jsonify(message=str(ex))
        response = jsonify(ex)
        response.status_code = (ex.code
                                if isinstance(ex, HTTPException)
                                else 500)
        return response

    app = Flask(import_name, **kwargs)
    #app.debug = True
    app.secret_key = id_generator(24)

    for code in default_exceptions.iterkeys():
        app.error_handler_spec[None][code] = make_json_error

    return app
开发者ID:javacruft,项目名称:python-lefthandclient,代码行数:28,代码来源:test_HPLeftHandMockServer_flask.py

示例3: run_daemon

def run_daemon(environment, log_level, config_file):
    create_app(app, log_level, config_file, True)
    app.conf.set("enviro", "run", environment)
    app.logger.info('Environment: %s' % environment)
    
    for code in default_exceptions.iterkeys():
        app.error_handler_spec[None][code] = make_json_error
    
    app.register_blueprint(auth.backend)
    app.register_blueprint(messages.backend)
    
    app.logger.info("Loading applications...")
    applications.get()

    # Load framework blueprints
    app.logger.info("Loading frameworks...")
    register_frameworks(app)

    app.logger.info("Initializing Genesis (if present)...")
    app.register_blueprint(genesis.backend)
    
    tracked_services.initialize()
    app.logger.info("Server is up and ready")
    try:
        app.run(host="0.0.0.0", port=8000)
    except KeyboardInterrupt:
        app.logger.info("Received interrupt")
开发者ID:josejamilena,项目名称:arkos-kraken,代码行数:27,代码来源:application.py

示例4: make_rest_app

def make_rest_app(import_name, **kwargs):
	"""
	Creates a JSON-oriented Flask app.

	All error responses that you don't specifically
	manage yourself will have application/json content
	type, and will contain JSON like this (just an example):

	{ "message": "405: Method Not Allowed" }
	"""
	def make_rest_error(ex):
		# app.logger.info("in make rest error")
		# app.logger.info(str(ex))
		if request_wants_json():
			response = jsonify(message=str(ex))
		else:
			response = Response('<message>{}</message>'.format(str(ex)))
			
		response.status_code = (ex.code
									if isinstance(ex, HTTPException)
									else 500)
		return response
		
	app = Flask(import_name, **kwargs)

	for code in default_exceptions.iterkeys():
		app.error_handler_spec[None][code] = make_rest_error

	return app
开发者ID:sachinsu,项目名称:rssapp,代码行数:29,代码来源:rssapp.py

示例5: make_json_app

def make_json_app(import_name, **kwargs):
    """
    Creates a JSON-oriented Flask app.

    All error responses that you don't specifically
    manage yourself will have application/json content
    type, and will contain JSON like this (just an example):

    { "message": "405: Method Not Allowed" }
    """
    def make_json_error(ex):
        response = flask.jsonify(Message=str(ex))
        response.status_code = (ex.code
                                if isinstance(ex, HTTPException)
                                else 500)
        return response

    app = flask.Flask(import_name, **kwargs)

    for code in default_exceptions.iterkeys():
        app.error_handler_spec[None][code] = make_json_error

    # Add logging
    handler = logging.StreamHandler()
    handler.setLevel(logging.INFO)
    app.logger.addHandler(handler)

    return app
开发者ID:Nithyavasudevan,项目名称:ckanext-glasgow,代码行数:28,代码来源:mock_ec.py

示例6: make_json_app

def make_json_app(import_name, **kwargs):
    """
    Creates a JSON-oriented Flask app.

    All error responses that you don't specifically
    manage yourself will have application/json content
    type, and will contain JSON like this (just an example):

    { "message": "405: Method Not Allowed" }

    http://flask.pocoo.org/snippets/83/
    """
    def make_json_error(ex):
        response = jsonify(message=str(ex))
        response.status_code = (ex.code
                                if isinstance(ex, HTTPException)
                                else 500)
        return response

    app = Flask(import_name, **kwargs)

    for code in default_exceptions.iterkeys():
        app.error_handler_spec[None][code] = make_json_error

    return app
开发者ID:erbriones,项目名称:appliance-workflow-backend,代码行数:25,代码来源:webservice.py

示例7: register_error_handlers

    def register_error_handlers(self):
        def prepare_error(message, description, code = None):

            if not code:
                code = 500

            response = jsonify(
                code = code,
                message = message,
                description = description
            )

            response.status_code = code

            return response

        @self.errorhandler(HTTPException)
        def http_error(ex):
            return prepare_error(ex.message, re.sub('<[^<]+?>', '', ex.description), ex.code)

        @self.errorhandler(CollectorException)
        def application_error(ex):
            self.logger.warn("%s: %s [%s]", ex.__class__.__name__, ex.message, ex.description)
            return prepare_error(ex.message, ex.description, ex.code)

        @self.errorhandler(Exception)
        def error(ex):
            return prepare_error(ex.message, None)

        for code in default_exceptions.iterkeys():
            self.error_handler_spec[None][code] = http_error
开发者ID:goldmann,项目名称:collector,代码行数:31,代码来源:collector.py

示例8: make_json_app

def make_json_app(import_name, **kwargs):
    """Creates a JSON-oriented Flask app.

    All error responses that you don't specifically manage yourself will have
    application/json content type, and will contain JSON that follows the
    libnetwork remote driver protocol.


    { "Err": "405: Method Not Allowed" }


    See:
      - https://github.com/docker/libnetwork/blob/3c8e06bc0580a2a1b2440fe0792fbfcd43a9feca/docs/remote.md#errors  # noqa
    """
    app = Flask(import_name, **kwargs)

    @app.errorhandler(NeutronClientException)
    def make_json_error(ex):
        response = jsonify({"Err": str(ex)})
        response.status_code = (ex.code if isinstance(ex, HTTPException)
                                else ex.status_code
                                if isinstance(ex, NeutronClientException)
                                else 500)
        content_type = 'application/vnd.docker.plugins.v1+json; charset=utf-8'
        response.headers['Content-Type'] = content_type
        return response

    for code in default_exceptions.iterkeys():
        app.error_handler_spec[None][code] = make_json_error

    return app
开发者ID:CingHu,项目名称:kuryr,代码行数:31,代码来源:utils.py

示例9: create_app

def create_app():
    app = Flask(__name__)
    app.config.from_object(bark.config)

    for code in default_exceptions.iterkeys():
        app.error_handler_spec[None][code] = make_json_error

    # Component imports. Must be here to fix cyclical problems
    from auth import bp_auth
    app.register_blueprint(bp_auth)

    from swipes import bp_swipes
    app.register_blueprint(bp_swipes, url_prefix='/swipes')

    from events import bp_events
    app.register_blueprint(bp_events, url_prefix='/events')

    from devices import bp_devices
    app.register_blueprint(bp_devices, url_prefix='/devices')

    from persons import bp_persons
    app.register_blueprint(bp_persons, url_prefix='/persons')

    from groups import bp_groups
    app.register_blueprint(bp_groups, url_prefix='/groups')

    @app.route('/') 
    def hello():
        return "Hello World"
    
    db.init_app(app)

    return app
开发者ID:csesoc,项目名称:bark-core,代码行数:33,代码来源:__init__.py

示例10: create_app

def create_app(environment=None):
    '''
    Create an app instance
    '''
    app = Flask('backend')
    app.url_map.converters['ObjectId'] = BSONObjectIdConverter

    # Config app for environment
    if not environment:
        environment = os.environ.get('BACKEND_ENVIRONMENT', 'Local')

    app.config.from_object('backend.backend.settings.%s' % environment)

    # convert exceptions to JSON
    def make_json_error(ex):
        response = jsonify(message=str(ex))
        response.status_code = (ex.code
                if isinstance(ex, HTTPException)
                else 500)
        return response
    for code in default_exceptions.iterkeys():
        app.error_handler_spec[None][code] = make_json_error


    from backend.backend.views.api import api
    app.register_module(api)

    # initialize modules
    admin.init_app(app)
    db.init_app(app)
    login_manager.setup_app(app)
    mail.init_app(app)

    return app
开发者ID:brab,项目名称:flask-api,代码行数:34,代码来源:__init__.py

示例11: json_flask_app

def json_flask_app(import_name, **kwargs):
    def make_json_error(ex):
        response = jsonify(message=str(ex), code=ex.code if isinstance(ex, HTTPException) else 500)
        return response
    app = Flask(import_name, **kwargs)
    for code in default_exceptions.iterkeys():
        app.error_handler_spec[None][code] = make_json_error
    return app
开发者ID:domenicosolazzo,项目名称:customerio-restapi,代码行数:8,代码来源:app.py

示例12: __init__

    def __init__(self, name):
        Flask.__init__(self, name)

        status_view = CephStatusView.as_view('status')
        self.add_url_rule('/', view_func=status_view)

        # add custom error handler
        for code in default_exceptions.iterkeys():
            self.error_handler_spec[None][code] = self.make_json_error
开发者ID:hufman,项目名称:ceph-dash,代码行数:9,代码来源:ceph-dash.py

示例13: create_app

def create_app(option):
    app = Flask(__name__)
    config = config_factory.get(option)
    app.config.from_object(config)
    from common import create_jinja_filters, random_pwd

    create_jinja_filters(app)
    from webapp.api import api
    from webapp.client import client
    from webapp.media import media

    app.register_blueprint(client)
    app.register_blueprint(api, url_prefix=Constants.API_V1_URL_PREFIX)
    app.register_blueprint(media, url_prefix=Constants.MEDIA_URL_PREFIX)

    csrf.init_app(app)
    compress.init_app(app)
    gravatar.init_app(app)
    db.init_app(app)
    migrate.init_app(app, db)
    admin.init_app(app)
    mail.init_app(app)
    from models import User, Role
    from webapp.forms import ExtendedRegisterForm

    user_datastore = SQLAlchemyUserDatastore(db, User, Role)
    security.init_app(app, user_datastore, register_form=ExtendedRegisterForm)
    with app.app_context():
        api_manager.init_app(app, flask_sqlalchemy_db=db)

        @app.before_request
        def before_request():
            g.constants = Constants
            g.config = app.config
            g.mode = app.config.get('MODE')

        @app.after_request
        def redirect_if_next(response_class):
            payload = request.args if request.method == 'GET' else request.form
            if 'api_next' in payload:
                if not response_class.status_code == 200:
                    flash(response_class.data)
                    return redirect(request.referrer)
                return redirect(payload.get('api_next'))
            return response_class

    patch_request_class(app, Constants.MAX_FILE_SIZE)

    from webapp.common import make_json_error

    for code in default_exceptions.iterkeys():
        app.error_handler_spec[None][code] = make_json_error

    configure_uploads(app, (user_images, ))

    return app
开发者ID:danieltcv,项目名称:startupbook,代码行数:56,代码来源:__init__.py

示例14: __init__

    def __init__(self, name):
        Flask.__init__(self, name)

        dhc_view = StateView.as_view('status')
        self.add_url_rule('/', defaults={'env': None}, view_func=dhc_view)
        self.add_url_rule('/<env>', view_func=dhc_view)

        # add custom error handler
        for code in default_exceptions.iterkeys():
            self.register_error_handler(code, self.make_json_error)
开发者ID:Crapworks,项目名称:terrastate,代码行数:10,代码来源:app.py

示例15: make_json_app

def make_json_app():
    def make_json_error(ex):
        response = jsonify(message=str(ex))
        response.status_code = (ex.code
                                if isinstance(ex, HTTPException)
                                else 500)
        return response

    for code in default_exceptions.iterkeys():
        app.error_handler_spec[None][code] = make_json_error
开发者ID:mrphishxxx,项目名称:twilio_server-1,代码行数:10,代码来源:util.py


注:本文中的werkzeug.exceptions.default_exceptions.iterkeys函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。