本文整理汇总了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
示例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
示例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")
示例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
示例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
示例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
示例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
示例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
示例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
示例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
示例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
示例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
示例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
示例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)
示例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