未提供项目描述
项目描述
描述
exgurd提供了一种装饰器,用于防止函数或方法抛出异常。这在执行不受信任的代码时非常有用,例如在框架中执行第三方模块时。
与Python 3中的suppress上下文管理器相比,exguard提供了更多控制异常处理的方法
根据模块和命名空间过滤,以定义要捕获哪些异常,并保持其他代码中的异常不受影响
捕获异常后执行回调函数
在finally块中执行回调函数
例如,一个在Web应用程序中调用第三方模块代码的API方法可以通过这种方式防止这些模块中的异常,同时框架本身的异常将原样抛出
from exguard import guard, traceback_str def throw_to_client(exception, module): tb = traceback_str(exception) # Do something to pass a traceback to the browser, disable the plugin,… pass # All third-party modules are under one namespace @guard(modules=["myframework.plugins"], submodules=True, fullstack=True, cb_except=throw_to_client) def call_plugin_api(): # An exception inside this will be caught myframework.plugins.evil.crash() # This will still raise an exception like normal x = 17 / 0
许可和版权
exguard - Guard code against exceptions, e.g. for running untrusted module code in a framework Copyright (C) 2017 Eike Tim Jesinghaus <eike@naturalnet.de> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
变更日志
0.2.1
防止对 <string> 或其他非模块帧进行保护。
0.2
添加实用函数以获取完整的堆栈跟踪作为字符串。
重新许可为MIT。
较小的文档更新。
0.1
首次发布。
项目详情
下载文件
下载适合您平台的文件。如果您不确定选择哪个,请了解更多关于安装软件包的信息。
源代码分发
exguard-0.2.1.tar.gz (4.1 kB 查看哈希值)
构建发行版
exguard-0.2.1-py3-none-any.whl (7.0 kB 查看哈希值)
关闭
exguard-0.2.1.tar.gz 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | e4b06870a9791fb4a8d7f84af2aef54eb3383251d1ef79e0a019ebe277d2c015 |
|
MD5 | c18aec2442931e4f2cf660dfde1dc8f2 |
|
BLAKE2b-256 | 457f777821ee51265f83e157f9f0aca4792024c645811ee70142b48f47435e43 |
关闭
exguard-0.2.1-py3-none-any.whl 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | b955add660111f120ceb0e7b113539d82e5a9823d28b657929efc98a668971b5 |
|
MD5 | a6cabf17679ed8542d4bcdf2ffd67738 |
|
BLAKE2b-256 | f10a11208767200ebe041a41770b76d0b0d929717c88349552cb72d868096113 |