Pyramid1.6的新功能¶
本文解释了 Pyramid 1.6版与其前代版本相比, Pyramid 1.5。它还记录了两个版本之间的向后不兼容以及添加到 Pyramid 1.6,以及软件依赖性更改和显著的文档添加。
向后不兼容¶
IPython和BPython支持已经从核心的pshell中移除。要继续在Pyramid1.6+上使用它们,必须显式安装绑定包。一种方法是添加
pyramid_ipython(或)pyramid_bpython)install_requires包的一部分setup.py文件,然后重新运行setup.py develop::setup( #... install_requires=[ 'pyramid_ipython', # new dependency 'pyramid', #... ], )
request.response当使用render_to_response()应用程序编程接口。现在有必要通过response=参数render_to_response()如果要为渲染器提供自定义响应对象。如果您没有通过一个,那么将使用当前响应工厂创建响应对象。几乎所有渲染器都会改变request.response响应对象(例如,JSON渲染器集request.response.content_type到application/json)但是,当调用render_to_response,不期望返回的响应对象与稍后在请求中使用的响应对象相同。从返回的响应对象render_to_response现在明显不同于request.response. 这不会更改渲染器的API。参见https://github.com/pylons/pyramid/pull/1563为了解决一个共同的问题,它现在是
ConfigurationError注册一个在使用默认视图映射器时实际上是未绑定方法的视图可调用。由于PY3中不存在未绑定的方法,因此通过检查第一个参数是否已命名,可以检测到可能的错误。self. 例如, config.add_view(ViewClass.some_method, ...) 实际上应该是 config.add_view(ViewClass, attr='some_method)' . 在PY2上,这一直是Pyramid中的一个问题,但向后不兼容性在PY3+上,在PY3+上,不能使用名为self. 在这种情况下,它看起来太像一个常见错误,将引发异常。参见https://github.com/pylons/pyramid/pull/1498
功能添加¶
python 3.5和pypy3的兼容性。
pserve --reload不再因语法错误而崩溃。参见https://github.com/pylons/pyramid/pull/2044静态资源的缓存总线已添加,可以通过新的
pyramid.config.Configurator.add_cache_buster()应用程序编程接口。核心API通过查询字符串和资产清单(用于集成到自定义资产管道中)来提供缓存总线。参见https://github.com/pylons/pyramid/pull/1380和https://github.com/pylons/pyramid/pull/1583和https://github.com/pylons/pyramid/pull/2171当使用
override_asset()应用程序编程接口。这使得在仍然能够使用static_url()API和add_static_view(). 以前不可能使用add_static_view()有绝对路径 and 生成内容的URL。此更改将取代呼叫,config.add_static_view('/abs/path', 'static')用config.add_static_view('myapp:static', 'static')和config.override_asset(to_override='myapp:static/', override_with='/abs/path/'). 这个myapp:static资产规格是完全组成的,不需要存在,它用于通过request.static_url('myapp:static/foo.png'). 参见https://github.com/pylons/pyramid/pull/1252补充
set_response_factory()以及response_factory的构造函数的关键字参数Configurator用于定义将返回自定义Response类。参见https://github.com/pylons/pyramid/pull/1499补充
pyramid.config.Configurator.root_package属性和init参数,以帮助包含的包解析与创建配置程序的包相关的资源。这对于需要从设置中加载资产规格的附加组件尤其有用,在这种情况下,开发人员可以自然地定义相对于顶级包的导入或资产。参见https://github.com/pylons/pyramid/pull/1337整体改善
proutes命令。补充--format和--glob命令的参数,引入了method用于显示可用请求方法的列,并改进了view通过显示模块而不是仅显示__repr__. 参见https://github.com/pylons/pyramid/pull/1488pserve现在可以采取-b或--browser在Web浏览器中打开服务器URL的选项。参见https://github.com/pylons/pyramid/pull/1533在python 3的视图中只支持关键字参数和函数注释。参见https://github.com/pylons/pyramid/pull/1556
这个
append_slash的参数add_notfound_view()现在将接受实现IResponse接口,并将其用作响应类,而不是默认的HTTPFound. 参见https://github.com/pylons/pyramid/pull/1610这个
Configurator已经增强了允许操作在提交周期内调用其他操作的能力。这使得更多的逻辑可以放在行动中,例如调用其他行动或将其分组以改进冲突检测的能力。我们还公开并记录了Pyramid使用的配置阶段,以便进一步帮助构建符合要求的附加组件。参见https://github.com/pylons/pyramid/pull/1513允许从呈现器返回迭代器。以前只能返回字节或Unicode。参见https://github.com/pylons/pyramid/pull/1417
提高在
AuthTktCookieHelper以及SignedCookieSessionFactory通过使用stdlib的hmac.compare_digest如果可用(如python 2.7.7+和3.3+)。参见https://github.com/pylons/pyramid/pull/1457提高
pcreateshell脚本输出。参见https://github.com/pylons/pyramid/pull/1453简化定义
notfound和forbidden希望使用默认异常响应视图,但谓词和其他配置选项已更改的视图。这个view参数现在是可选的add_notfound_view()和add_forbidden_view()参见https://github.com/pylons/pyramid/issues/494这个
pshell脚本现在将加载PYTHONSTARTUP文件(如果在启动解释器之前在环境中定义了一个)。参见https://github.com/pylons/pyramid/pull/1448为状态代码添加新的HTTP异常对象
428 Precondition Required,429 Too Many Requests和431 Request Header Fields Too Large在里面pyramid.httpexceptions. 请参阅https://github.com/pylons/pyramid/pull/1372/filespcreate如果不使用scaffold参数运行,现在将打印缺少标志的信息以及可用scaffold的列表。参见https://github.com/pylons/pyramid/pull/1566和https://github.com/pylons/pyramid/issues/1297pcreate如果使用当前环境中已存在或可导入的项目名称的参数调用,现在将要求确认。请参阅https://github.com/pylons/pyramid/issues/1357和https://github.com/pylons/pyramid/pull/1837添加
pyramid.request.apply_request_extensions()可用于测试以应用通过以下方式配置的任何请求扩展的函数config.add_request_method. 以前,只有通过Pyramid的路由器才能测试扩展。参见https://github.com/pylons/pyramid/pull/1581使子类成为可能
pyramid.request.Request并使用pyramid.request.Request.add_request.method. 参见https://github.com/pylons/pyramid/issues/1529附加Shell
pshell现在可以注册为入口点。参见https://github.com/pylons/pyramid/pull/1891和https://github.com/pylons/pyramid/pull/2012注入的变量
pshell现在显示文档字符串而不是默认值str(obj)如果可能的话。参见https://github.com/pylons/pyramid/pull/1929
废弃¶
这个
pserve命令的后台监控功能,以及--monitor-restart,已被弃用。这包括[start,stop,restart,status]子命令以及--daemon,--stop-daemon,--pid-file,--status,--user和--group旗帜。参见https://github.com/pylons/pyramid/pull/2120和https://github.com/pylons/pyramid/pull/2189和https://github.com/pylons/pyramid/pull/1641请在将来使用真正的流程管理器,而不是依赖
pserve去监控自己。存在许多选项,包括操作系统的服务(如systemd或upstart),以及基于python的解决方案(如circus和supervisor)。参见https://github.com/pylons/pyramid/pull/1641和https://github.com/pylons/pyramid/pull/2120
这个
principal参数pyramid.security.remember()重命名为userid. 使用principal因为参数名仍然有效,并且将在接下来的几个版本中继续工作,但是会打印一个拒绝警告。
脚手架增强¶
在脚手架中的日志格式化程序中添加行号以帮助调试。参见https://github.com/pylons/pyramid/pull/1326
更新脚手架生成机械,返回版本 Pyramid 以及用于脚手架的文件。更新的
starter,alchemy和zodb模板具有指向正确版本文档的链接,并反映 Pyramid 用于生成支架。从模板中删除了非ASCII版权符号,因为这导致脚手架无法生成项目。
文档增强功能¶
已从快速教程中删除日志配置
ini文件,除了脚手架和日志相关章节,以避免需要解释得太早。改进和澄清文件 Pyramid 定义为
principal和Auserid在它的安全API中。参见https://github.com/pylons/pyramid/pull/1399将文档移动到
accept在pyramid.config.Configurator.add_view()不再是谓词列表的一部分。请参阅https://github.com/pylons/pyramid/issues/1391,获取一份声明not_失败了accept. 与@mcdonc的讨论得出结论,不应将其作为谓词进行记录。请参阅https://github.com/pylons/pyramid/pull/1487了解此公关。澄清之前暗示的
ISession.invalidateAPI文档。添加命令行程序的文档 (
p*脚本)。参见https://github.com/pylons/pyramid/pull/2191