源码:

def setupmethod(f):
"""Wraps a method so that it performs a check in debug mode if the
first request was already handled.
"""
def wrapper_func(self, *args, **kwargs):
if self.debug and self._got_first_request:
raise AssertionError('A setup function was called after the '
'first request was handled. This usually indicates a bug '
'in the application where a module was not imported '
'and decorators or other functionality was called too late.\n'
'To fix this make sure to import all your view modules, '
'database models and everything related at a central place '
'before the application starts serving requests.')
return f(self, *args, **kwargs)
return update_wrapper(wrapper_func, f)
作用: 该对象是一个装饰器。目的是校验Flask实例是否开启了debug模式并且获取第一个请求(从字面理解),如果是这样则报错。
其中调用functools的 update_wrapper ()
WRAPPER_ASSIGNMENTS = ('__module__', '__name__', '__doc__')
WRAPPER_UPDATES = ('__dict__',)
def update_wrapper(wrapper,
wrapped,
assigned = WRAPPER_ASSIGNMENTS,
updated = WRAPPER_UPDATES):
"""Update a wrapper function to look like the wrapped function wrapper is the function to be updated
wrapped is the original function
assigned is a tuple naming the attributes assigned directly
from the wrapped function to the wrapper function (defaults to
functools.WRAPPER_ASSIGNMENTS)
updated is a tuple naming the attributes of the wrapper that
are updated with the corresponding attribute from the wrapped
function (defaults to functools.WRAPPER_UPDATES)
"""
for attr in assigned:
setattr(wrapper, attr, getattr(wrapped, attr))
for attr in updated:
getattr(wrapper, attr).update(getattr(wrapped, attr, {}))
# Return the wrapper so this can be used as a decorator via partial()
return wrapper


对flask.app的所有方法预加载了这个装饰器,

@setupmethod -- flask.setupmethod的更多相关文章

  1. Inside Flask - app.py - 1

    Inside Flask - app.py - 1 除 werkzeug 和 jinja2 等依赖库外,app.py 是在 Flask 的 __init__.py 中导入的第一个 Flask 自身的模 ...

  2. Flask类的属性和方法大全

    Flask Property__class____dict____doc____module__app_ctx_globals_classconfig_classdebugdefault_config ...

  3. Flask源码阅读-第四篇(flask\app.py)

    flask.app该模块2000多行代码,主要完成应用的配置.初始化.蓝图注册.请求装饰器定义.应用的启动和监听,其中以下方法可以重点品读和关注 def setupmethod(f): @setupm ...

  4. FlASK中的endpoint问题

    先贴一点有关的flask代码,时间有限,我慢慢扩充 以下是flask源码中app.py中add_url_rule的代码. 主要是view_func  -- endpoint -- url 之间的对应关 ...

  5. 源码解析flask的路由系统

    源码解析flask的路由系统 当我们新建一个flask项目时,pycharm通常已经为项目定义了一个基本路由 @app.route('/') def hello_world(): return 'He ...

  6. python框架之Flask(2)-路由和视图&Session

    路由和视图 这一波主要是通过看源码加深对 Flask 中路由和视图的了解,可以先回顾一下装饰器的知识:[装饰器函数与进阶] 路由设置的两种方式 # 示例代码 from flask import Fla ...

  7. python框架之Flask(5)-@app.before_request原理

    示例 from flask import Flask app = Flask(__name__) @app.before_request def xx(): pass @app.route('/') ...

  8. Flask 框架

    装饰器知识回顾 http://www.cnblogs.com/0bug/p/7978595.html 普通装饰器格式: def wrapper(func): def inner(*args, **kw ...

  9. flask 未完待续

    Flask - 一个短小精悍.可扩展的一个Web框架很多可用的第三方组件:http://flask.pocoo.org/extensions/blogs:https://www.cnblogs.com ...

随机推荐

  1. P1979 华容道 spfa题解

    题目描述 [问题描述] 小 B 最近迷上了华容道,可是他总是要花很长的时间才能完成一次.于是,他想到用编程来完成华容道:给定一种局面, 华容道是否根本就无法完成,如果能完成, 最少需要多少时间. 小 ...

  2. mybatis通过插件方式实现读写分离

    原理:通过自定义mybatis插件,拦截Executor的update和query方法,检查sql中有select就用读的库,其它的用写的库(如果有调用存储过程就另当别论了) @Intercepts( ...

  3. 进程间通信的两种实现方式(IPC)

    进程间通信的两种实现方式(IPC) IPC: iter processing communicate 进程间通信:IPC(iter process communicate)linux free-m 可 ...

  4. STM32 modbus CRC16校验

    typedef unsigned char uint8_t; typedef unsigned short uint16_t; typedef int int32_t; const uint16_t ...

  5. Synplify FPGA 逻辑综合

    作为 Synopsys FPGA 设计解决方案的一部分,Synplify FPGA 综合软件是实现高性能.高性价比的 FPGA 设计的行业标准. 其独特的行为提取综合技术 (Behavior Extr ...

  6. postgres的强制类型转换与时间函数

    一.类型转换postgres的类型转换:通常::用来做类型转换,timestamp到date用的比较多select  now()::dateselect  now()::varchar 示例1:日期的 ...

  7. vscode setting.json

    setting.json { "sync.gist": "#github的码##", "sync.lastUpload": "20 ...

  8. html自动刷新

    头部<meta http-equiv="refresh" content="10"> 或者js实现 <script language=&quo ...

  9. linux 搜索文本

    find -type f -name '*.php'|xargs grep '127.0.0.1'  搜索所有.php 内容 127.0.0.1 转自:http://www.cnblogs.com/w ...

  10. Openjudge-4115-佐助和鸣人

    这一题是一道广搜的题目,首先我们通过读入字符串读入每一行,然后顺带找到鸣人的位置. 然后我们初始化之后,就进行广搜,还是广搜的格式,但是要压入队列的条件我们可以稍微变一变,我们可以直接判断下一个要走的 ...