# 局部底层代码
def request(method, url, **kw):pass
def get(url, params=None, **kw):pass # 获取
def options(url, **kw):pass # 询问url支持的方法
def head(url, **kw):pass # 确定url的有效性
def post(url, data=None, json=None, **kw):pass # 新增
def put(url, data=None, **kw):pass # 整体更新
def patch(url, data=None, **kw):pass # 局部更新
def delete(url, **kw):pass # 删除
def request(method, url, **kwargs):
with sessions.Session() as session:
return session.request(method=method, url=url, **kwargs)
# with 上下文管理器触发的是类Session对应内置方法
def __enter__(self):
return self
def __exit__(self, *args):
self.close()
# 执行顺序为:
# 执行__enter__返回self作为as中的session
# 执行session.request(method=method, url=url, **kwargs)
# 执行__exit__ session.close()
import functools
def show_arg(*arg, **kw):
print(arg, kw)
show_arg(1, 2, 3, a='a', b='b', c='c')
show1 = functools.partial(show_arg, 1, 2, 3)
show1(a='a', b='b', c='c')
show2 = functools.partial(show_arg, a='a', b='b', c='c')
show2(1, 2, 3)
package
|-views # 对外展示接口函数
|-ops # 内部实现逻辑
|-models # 存储模型