跳转到主要内容

Pyramid Web框架,一个Pylons项目

项目描述

Pyramid

2.0-branch Travis CI Status 2.0-branch Documentation Status IRC Libera.Chat

Pyramid 是一个小巧、快速、接地气、开源的 Python 网络框架。它让现实世界的网络应用开发和部署更加有趣、可预测和高效。尝试使用 Pyramid,浏览其附加组件和文档,并了解概览。[尝试 Pyramid](https://trypyramid.com/)

from wsgiref.simple_server import make_server
from pyramid.config import Configurator
from pyramid.response import Response

def hello_world(request):
    return Response('Hello World!')

if __name__ == '__main__':
    with Configurator() as config:
        config.add_route('hello', '/')
        config.add_view(hello_world, route_name='hello')
        app = config.make_wsgi_app()
    server = make_server('0.0.0.0', 6543, app)
    server.serve_forever()

Pyramid 是 Pylons 项目的一个项目。[Pylons 项目](https://pylonsproject.org)

支持和文档

有关文档、报告错误和获取支持,请参阅[Pyramid 支持和发展](https://docs.pylonsproject.org/projects/pyramid/en/latest/#support-and-development)。

开发和贡献

有关在 Pyramid 中开发或在 Pyramid 中贡献时的测试运行、添加功能、编码风格和更新文档的指南,请参阅[HACKING.txt](https://github.com/Pylons/pyramid/blob/main/HACKING.txt)和[contributing.md](https://github.com/Pylons/pyramid/blob/main/contributing.md)。

许可证

Pyramid 在 BSD 衍生的[Repoze 公共许可证](http://repoze.org/license.html)下提供。

作者

Pyramid 由[Agendaless Consulting](https://agendaless.com)和一支[贡献者团队](https://github.com/Pylons/pyramid/graphs/contributors)提供。

2.0.2 (2023-08-25)

错误修复

  • 在针对 static_view 发起文件请求时,删除了对路径中 null-bytes 的支持。虽然 HTTP 规范允许 null-bytes,但由于处理 null-bytes 可能导致安全漏洞,因此不再支持。

    这修复了由于 Python 3.11.0 到 3.11.4 中的错误而存在的一个安全漏洞,从而允许无意中披露静态视图路径上一个目录的 index.html

    感谢 LAC Co., Ltd 的 Masashi Yamane 报告此问题。

向后不兼容性

  • 不再允许对 static_view 的请求在路径段的任何部分包含 null-byte。

2.0.1 (2023-01-29)

  • 添加对 Python 3.10 和 3.11 的支持。

  • 使用 pyramid.decorator.reify 时,从装饰属性复制 __name__。请参阅[https://github.com/Pylons/pyramid/pull/3660](https://github.com/Pylons/pyramid/pull/3660)

  • 修复了文档中 pyramid.config.Configurator.add_static_viewpyramid.config.Configurator.override_asset 的方法签名。请参阅[https://github.com/Pylons/pyramid/pull/3699](https://github.com/Pylons/pyramid/pull/3699)

  • 删除了在显示配置器冲突错误时在 Python 3.5.0 中使用的过时 stackframe 欺骗。请参阅[https://github.com/Pylons/pyramid/pull/3700](https://github.com/Pylons/pyramid/pull/3700)

  • 修复了由于使用 != 而将某些对象注入 pshell 环境时的错误。请参阅[https://github.com/Pylons/pyramid/pull/3704](https://github.com/Pylons/pyramid/pull/3704)

  • Pyramid 库已停止支持 i18n 模块中的 l*gettext() 方法。这些方法自 Python 3.8 起已被弃用,并在 Python 3.11 中被移除。在 Python 3 中也不应使用它们。有关详细信息,请参阅 https://github.com/Pylons/pyramid/pull/3717

  • 通过更新 threading API 使用 .daemon = True 来避免 setDaemon(True) 弃用警告。

2.0 (2021-02-28)

  • 自 2.0b1 版本以来没有变化。

2.0b1 (2021-02-20)

2.0b0 (2020-12-15)

2.0a0 (2020-11-29)

特性

  • 添加对 Python 3.9 的支持。请参阅 https://github.com/Pylons/pyramid/issues/3622

  • 现在,在展开时,aslist 方法可以处理非字符串对象。请参阅 https://github.com/Pylons/pyramid/pull/3594

  • 现在可以将多个值传递给路由和视图配置中的 header 断言。请参阅 https://github.com/Pylons/pyramid/pull/3576

  • 添加对 Python 3.8 的支持。请参阅 https://github.com/Pylons/pyramid/pull/3547

  • 添加了新的安全 API,以支持对认证和授权系统的彻底改造。请在文档的“Pyramid 2.0 新特性”章节中阅读“升级认证/授权”部分,了解如何使用此新系统。

    • pyramid.config.Configurator.set_security_policy.

    • pyramid.interfaces.ISecurityPolicy

    • pyramid.request.Request.identity.

    • pyramid.request.Request.is_authenticated

    • pyramid.authentication.SessionAuthenticationHelper

    • pyramid.authorization.ACLHelper

    • is_authenticated=True/False 断言用于路由和视图配置

    请参阅 https://github.com/Pylons/pyramid/pull/3465https://github.com/Pylons/pyramid/pull/3598

  • pyramid.session.SignedCookieSessionFactory 上的默认 serializer 改为使用 pyramid.session.JSONSerializer 而不是 pyramid.session.PickleSerializer。请在文档的“Pyramid 2.0 新特性”章节中阅读“升级会话序列化”部分,了解更多关于此更改的信息。请参阅 https://github.com/Pylons/pyramid/pull/3413

  • 现在可以通过使用 config.include(..., route_prefix=...)config.route_prefix_context(...) 将路由前缀与路由模式组合时,控制路由模式是否包含尾随斜杠。可以通过指定空模式并设置新的参数 inherit_slash=True 来完成此操作。例如

    with config.route_prefix_context('/users'):
        config.add_route('users', '', inherit_slash=True)

    在示例中,生成的模式将是 /users。同样,如果路由前缀是 /users/,则最终模式将是 /users/。如果 pattern'/',则最终模式始终是 /users/。此新设置仅在向 add_route 传递的模式是空字符串 ('') 时才可用。请参阅 https://github.com/Pylons/pyramid/pull/3420

  • 不再定义 pyramid.request.Request.json_body,因为 WebOb 已经提供了该功能。这允许现在设置该属性。请参阅 https://github.com/Pylons/pyramid/pull/3447

  • 改进了 pyramid.view.view_config 装饰器的调试信息。请参阅 https://github.com/Pylons/pyramid/pull/3483

  • pyramid.config.Configurator.set_default_csrf_options 以及 pyramid.csrf.check_csrf_origin 添加了一个新参数,allow_no_origin。此选项控制是否拒绝没有 OriginReferer 头部的请求 - 这通常是用户出于隐私原因,即使在同域请求中也不发送 Referer 头部配置浏览器时产生的结果。默认情况下,将拒绝没有已知来源的请求。也可以通过将 Origin: null 头部添加到设置中的 pyramid.csrf_trusted_origins 列表中来允许特殊的 Origin: null 头部。请参阅 https://github.com/Pylons/pyramid/pull/3512https://github.com/Pylons/pyramid/pull/3518

  • pyramid.config.Configurator.set_default_csrf_options 添加了一个新参数,check_origin,该参数完全禁用了来源检查。请参阅 https://github.com/Pylons/pyramid/pull/3518

  • 添加了 pyramid.interfaces.IPredicateInfo,该接口定义了作为第二个参数传递给谓词工厂的对象。请参阅 https://github.com/Pylons/pyramid/pull/3514

  • 通过使用 pyramid.config.Configurator.add_static_viewpyramid.static.static_viewcontent_encodings 参数添加了对服务预压缩静态资源的支持。请参阅 https://github.com/Pylons/pyramid/pull/3537

  • 修复了使用 imp 模块发出的 DeprecationWarning。请参阅 https://github.com/Pylons/pyramid/pull/3553

  • 通过 config.add_request_method(..., property=True)request.set_property 创建的属性曾经是只读的。现在可以通过 request.foo = ... 覆盖它们,直到删除该值,它将返回覆盖的值。这在测试中模拟请求属性时非常有用。请参阅 https://github.com/Pylons/pyramid/pull/3559

  • 完成回调现在作为 pyramid.scripting.preparepyramid.paster.bootstrap 调用的部分 closer 执行。请参阅 https://github.com/Pylons/pyramid/pull/3561

  • 添加了 pyramid.request.RequestLocalCache,它可以用来创建在请求之间共享的简单对象,并可用于存储每个请求的数据。当数据来源在请求本身之外时,这非常有用。通常会在请求上通过 pyramid.config.Configurator.add_request_methodpyramid.decorator.reify 使用具体化的属性,当数据在访问请求属性时按需生成时,这些方法工作得很好。然而,通常数据是在访问其他系统时生成的,然后我们希望缓存数据以供请求期间使用。请参阅 https://github.com/Pylons/pyramid/pull/3561

  • 公开了 pyramid.authorization.ALL_PERMISSIONSpyramid.authorization.DENY_ALL,使得所有与ACL相关的常量现在都可以从 pyramid.authorization 命名空间导入。参见 https://github.com/Pylons/pyramid/pull/3563

  • pserve 现在将详细消息输出到 stderr 而不是 stdout,以规避 stdout 默认存在的缓冲问题。参见 https://github.com/Pylons/pyramid/pull/3593

弃用

  • 弃用了身份验证和授权接口以及基于主体的支持。有关等效API和升级说明,请参阅文档中“Pyramid 2.0新功能”章节中的“升级身份验证/授权”。以下API由于此更改已被弃用:

    • pyramid.config.Configurator.set_authentication_policy

    • pyramid.config.Configurator.set_authorization_policy

    • pyramid.interfaces.IAuthenticationPolicy

    • pyramid.interfaces.IAuthorizationPolicy

    • pyramid.request.Request.effective_principals

    • pyramid.request.Request.unauthenticated_userid

    • pyramid.authentication.AuthTktAuthenticationPolicy

    • pyramid.authentication.RemoteUserAuthenticationPolicy

    • pyramid.authentication.RepozeWho1AuthenticationPolicy

    • pyramid.authentication.SessionAuthenticationPolicy

    • pyramid.authentication.BasicAuthAuthenticationPolicy

    • pyramid.authorization.ACLAuthorizationPolicy

    • 视图和路由谓词中的 effective_principals

    参见 https://github.com/Pylons/pyramid/pull/3465

  • 弃用了 pyramid.security.principals_allowed_by_permission。此方法继续与已弃用的 pyramid.interfaces.IAuthorizationPolicy 接口一起工作,但不会与新 pyramid.interfaces.ISecurityPolicy 一起工作。参见 https://github.com/Pylons/pyramid/pull/3465

  • 弃用了 pyramid.security 中与ACL相关的几个方面。现在应从 pyramid.authorization 命名空间导入等效对象。包括以下内容:

    • pyramid.security.Everyone

    • pyramid.security.Authenticated

    • pyramid.security.ALL_PERMISSIONS

    • pyramid.security.DENY_ALL

    • pyramid.security.ACLAllowed

    • pyramid.security.ACLDenied

    参见 https://github.com/Pylons/pyramid/pull/3563

  • 弃用了 pyramid.session.PickleSerializer。参见 https://github.com/pylons/pyramid/issues/2709,以及 https://github.com/pylons/pyramid/pull/3353https://github.com/pylons/pyramid/pull/3413

向后不兼容性

  • 停止支持Python 2.7、3.4和3.5。参见 https://github.com/Pylons/pyramid/pull/3421https://github.com/Pylons/pyramid/pull/3547https://github.com/Pylons/pyramid/pull/3634

  • 移除了 pyramid.compat 模块。集成者应从现在开始使用 six 模块或它们自己的代码库中使用的供应商shims。参见 https://github.com/Pylons/pyramid/pull/3421

  • pcreate 和内置的脚手架已被移除,以支持使用 cookiecutter 工具和 pyramid-cookiecutter-starter cookiecutter。脚本和脚手架在Pyramid 1.8中被弃用。参见 https://github.com/Pylons/pyramid/pull/3406

  • pyramid.authentication.AuthTktCookieHelper 上的默认 hashalg 更改为 sha512。参见 https://github.com/Pylons/pyramid/pull/3557

  • 已删除 pyramid.interfaces.ITemplateRenderer。该接口自Pyramid 1.5起已弃用,并用于如 pyramid_makopyramid_chameleon 等库,但Pyramid自身并未提供功能。请参阅 https://github.com/Pylons/pyramid/pull/3409

  • 已删除 pyramid.security.has_permissionpyramid.security.authenticated_useridpyramid.security.unauthenticated_useridpyramid.security.effective_principals。这些方法自Pyramid 1.5起已弃用,并在请求上作为属性提供等效功能。例如,request.authenticated_userid。请参阅 https://github.com/Pylons/pyramid/pull/3410

  • 已删除对 pyramid.config.Configurator.add_viewpyramid.config.Configurator.add_routeaccept 谓词提供媒体范围的支持。这些选项自Pyramid 1.10和WebOb 1.8起已弃用,因为它们导致无法控制的匹配,并且不符合RFC规范。请参阅 https://github.com/Pylons/pyramid/pull/3411

  • 已删除 pyramid.session.UnencryptedCookieSessionFactoryConfig。该会话工厂自Pyramid 1.5起被 pyramid.session.SignedCookieSessionFactory 替换,并自那时起已弃用。请参阅 https://github.com/Pylons/pyramid/pull/3412

  • 已删除 pyramid.session.signed_serializepyramid.session.signed_deserialize。这些方法仅用于现在已删除的 pyramid.session.UnencryptedCookieSessionFactoryConfig,并与易受攻击的pickle序列化格式相关联,如果密钥泄露,可能导致远程代码执行。请参阅 https://github.com/Pylons/pyramid/pull/3412

  • pyramid.session.SignedCookieSessionFactory 上的默认 serializer 改为使用 pyramid.session.JSONSerializer 而不是 pyramid.session.PickleSerializer。请在文档的“Pyramid 2.0 新特性”章节中阅读“升级会话序列化”部分,了解更多关于此更改的信息。请参阅 https://github.com/Pylons/pyramid/pull/3413

  • pyramid.request.Request.invoke_exception_view 将不会由默认执行策略调用。请参阅 https://github.com/Pylons/pyramid/pull/3496

  • pyramid.config.Configurator.scan 默认将不再执行除 'pyramid' 类别之外的任何类别注册的Venusian装饰器回调。要找到任何装饰器(无论类别如何),请指定 config.scan(..., categories=None)。请参阅 https://github.com/Pylons/pyramid/pull/3510

  • 谓词工厂的第二个参数已从 config 更改为 info,即 pyramid.interfaces.IPredicateInfo 的实例。这限制了谓词可用的数据,但仍提供了包、注册表、设置和点名称解析器,应涵盖大多数用例,并且与向后兼容性良好。请参阅 https://github.com/Pylons/pyramid/pull/3514

  • 已删除 check_csrf 谓词。相反,请使用 pyramid.config.Configurator.set_default_csrf_optionsrequire_csrf 视图选项来启用自动CSRF检查。请参阅 https://github.com/Pylons/pyramid/pull/3521

  • 更新了 pyramid.authenticationAuthTktAuthenticationPolicypyramid.authentication.AuthTktCookieHelper 的默认行为,以便在没有指定其他域约束条件的情况下仅设置不带域参数的单个cookie。在此更改之前,wild_domain=False(默认值)实际上被当作 wild_domain=True 处理,这样cookie会被定义用于请求的域,以及任何子域。在新行为中,cookie默认仅影响当前域,而不影响子域。请参阅 https://github.com/Pylons/pyramid/pull/3587

文档更改

项目详情


发行历史 发行通知 | RSS订阅

下载文件

下载您平台上的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。

源分发

pyramid-2.0.2.tar.gz (2.6 MB 查看哈希值)

上传时间

构建分发

pyramid-2.0.2-py3-none-any.whl (247.3 kB 查看哈希值)

上传时间 Python 3

支持者