Pyramid1.8的新功能¶
本文解释了 Pyramid 与之前的版本相比,1.8版 Pyramid 1.7。它还记录了两个版本之间的向后不兼容以及添加到 Pyramid 1.8,以及软件依赖性更改和显著的文档添加。
主要功能添加¶
补充
pyramid.config.Configurator.add_exception_view()
以及pyramid.view.exception_view_config()
装饰者。现在可以使用这些方法或通过新的exception_only=True
选择权pyramid.config.Configurator.add_view()
添加只在处理异常时匹配的视图。以前,还为继承自异常类的遍历上下文注册了任何异常视图,这阻止了任何仅限异常的优化。参见https://github.com/pylons/pyramid/pull/2660pserve --reload
现在使用 hupper 用于监视文件更改的库。这带来了许多改进:如果 watchdog 安装包后,将使用inotify而不是CPU和磁盘密集型轮询来完成监视。
监视器现在是一个独立的进程,它不会崩溃并在任何代码之前启动。
在保存文件之前,监视器不会在崩溃后重新启动进程。
显示器在Windows上工作。
现在可以通过以下方式从Pyramid视图或任何其他代码手动触发重新加载:
hupper.get_reloader().trigger_reload()
. 有点整洁。您可以通过发出
SIGHUP
到监视器进程。
参见https://github.com/pylons/pyramid/pull/2805
次要功能添加¶
python 3.6兼容性。https://github.com/pylons/pyramid/issues/2835
这个
_get_credentials
私有方法pyramid.authentication.BasicAuthAuthenticationPolicy
已提取为独立函数pyramid.authentication.extract_http_basic_credentials()
,此函数从request
对象,并将其作为命名元组返回。参见https://github.com/pylons/pyramid/pull/2662Pyramid1.4悄悄地删除了已恢复的配置程序的一个功能。行动鉴别器也有可能在不同的行动指令之间发生冲突。参见https://github.com/pylons/pyramid/pull/2757
pyramid.paster.bootstrap()
和它的同胞pyramid.scripting.prepare()
现在可以用作上下文管理器来自动调用closer
将线程局部变量从堆栈中弹出以防止内存泄漏。参见https://github.com/pylons/pyramid/pull/2760增加了
exception_only
布尔到pyramid.interfaces.IViewDeriverInfo
视图派生器可以使用它来确定是否包装只处理异常的视图。这意味着不再需要对request.exception
要确定视图是否正在处理异常,可以在配置时优化管道。参见https://github.com/pylons/pyramid/pull/2660pcreate
了解到--package-name
允许您在现有文件夹中使用与项目名称不同的包名称创建新项目。参见https://github.com/pylons/pyramid/pull/2783pserve
现在应该和gevent
以及其他需要MonkeyPatch进程的工作人员,假设服务器和/或应用程序在导入Pyramid的其余部分之前尽可能快地这样做。参见https://github.com/pylons/pyramid/pull/2797Pyramid不再复制传递给
pyramid.config.Configurator(settings=)
. 原文dict
保持不变。参见https://github.com/pylons/pyramid/pull/2823CSRF Trusted Origins设置现在可能是一个空格分隔的域列表。以前只允许使用python列表。此外,现在可以使用
PYRAMID_CSRF_TRUSTED_ORIGINS
与其他设置类似的环境变量。参见https://github.com/pylons/pyramid/pull/2823一个新的
[pserve]
配置文件中支持节watch_files
可配置的密钥pserve --reload
监视自定义文件路径。参见https://github.com/pylons/pyramid/pull/2827允许从的子类进行流式响应
pyramid.httpexceptions.HTTPException
. 以前,在测试身体时会展开响应,这使得不可能对响应进行流式处理。参见https://github.com/pylons/pyramid/pull/2863通过使用新的
listen
服务员的指示。参见https://github.com/pylons/pyramid/pull/2853所有P*脚本现在都使用argparse而不是optparse。这提高了他们的
--help
输出并使其选项的文档更加清晰。参见https://github.com/pylons/pyramid/pull/2864增加了一个
override
选择权pyramid.config.Configurator.add_translation_dirs()
允许以后调用将翻译目录置于比以前调用更高的优先级。参见https://github.com/pylons/pyramid/pull/2902增加了一个新的
callback
选择权pyramid.config.Configurator.set_default_csrf_options()
`它可用于确定是否应启用CSRF检查以允许混合身份验证方法。只有基于cookie的方法通常需要CSRF检查。参见https://github.com/pylons/pyramid/pull/2778
向后不兼容¶
在Pyramid降级期间(1.6->1.8)之后,已删除对pserver的守护进程支持。这包括删除守护进程命令(start、stop、restart、status)以及以下参数:
--daemon
,--pid-file
,--log-file
,--monitor-restart
,--status
,--user
,--group
,--stop-daemon
要将服务器作为守护进程运行,应使用进程管理器而不是pserver。
参见https://github.com/pylons/pyramid/pull/2615
更改静态视图以避免设置
Content-Encoding
使用python猜测的编码的响应头mimetypes
模块。这导致客户端在下载gzip文件时对其内容进行解码。客户最终会得到foo.txt.gz
磁盘上已解码的文件,因此foo.txt
. 此外,Content-Encoding
仅当客户端本身广播支持通过Accept-Encoding
请求头。参见https://github.com/pylons/pyramid/pull/2810pcreate
现在默认为交互式。如果已存在具有不同内容的文件,系统将提示您。以前,如果有类似的文件,除非您指定,否则将自动跳过它们。--interactive
或--overwrite
. 参见https://github.com/pylons/pyramid/pull/2775支持
IContextURL
已删除Pyramid1.3中不推荐使用的接口。参见https://github.com/pylons/pyramid/pull/2822设置不再作为设置对象(例如
request.registry.settings.foo
)这在Pyramid1.2中被否决。参见https://github.com/pylons/pyramid/pull/2823删除了未记录的参数
cachebust_match
从pyramid.static.static_view
. 这一论点是在Pyramid1.6中偶然提出的。参见https://github.com/pylons/pyramid/pull/2681
废弃¶
这个
pcreate
脚本和核心脚手架 (starter
,alchemy
和zodb
)已弃用。他们被接受大众的决定所取代 cookiecutter 项目作为最佳项目模板化解决方案。
pcreate
最初是在很少有支持Python3的替代方案时引入的。幸运的是,情况有所改善,主要的IDE正在讨论可能的CookieCutters工具支持,以及jinja2语法的简单性,让我们兴奋地接受这个项目的发展!所有Pyramid的官方脚手架和教程都已移植到cookiecutter:
参见https://github.com/pylons/pyramid/pull/2780
文档增强功能¶
添加 pyramid_nacl_session 对工厂进行会话。参见https://github.com/pylons/pyramid/issues/2791
从从未合并到master的陈旧分支更新hacking.txt。参见https://github.com/pylons/pyramid/pull/2782
更新了Windows安装说明和相关位。参见https://github.com/pylons/pyramid/issues/2661
修复视图谓词和路由谓词之间文档中的不一致,并突出它们的API中的差异。参见https://github.com/pylons/pyramid/pull/2764
澄清可能的误用
headers
Kwarg到pyramid.httpexceptions.HTTPException
其中,来自父类的更合适的禁忌pyramid.response.Response
应该改为使用。参见https://github.com/pylons/pyramid/pull/2750sqlacalchemy+url调度+jinja2 (
wiki2
)和zodb+traversal+chameleon (wiki
)已经更新了教程,以利用新的cookiecutters并放弃对pcreate
脚手架。请参见https://github.com/pylons/pyramid/pull/2881和https://github.com/pylons/pyramid/pull/2883。
文档中的快速浏览、快速教程和大多数文件都已更新为使用cookiecutters而不是pcreate和scaffolds。请参阅https://github.com/pylons/pyramid/pull/2888和https://github.com/pylons/pyramid/pull/2889
更新了
mod_wsgi
使用CookiCutters和Apache2.4+的教程。参见https://github.com/pylons/pyramid/pull/2901