Datasette插件,用于配置任意ASGI中间件
项目描述
datasette-configure-asgi
Datasette插件,用于配置任意ASGI中间件
安装
pip install datasette-configure-asgi
用法
此插件仅在您的metadata.json文件中包含相关顶级插件配置时才有效,配置键为"datasette-configure-asgi"。
例如,要将您的Datasette实例包装在配置为将日志写入/tmp/log.db的asgi-log-to-sqlite中间件中,您将使用以下内容
{
    "plugins": {
        "datasette-configure-asgi": [
            {
                "class": "asgi_log_to_sqlite.AsgiLogToSqlite",
                "args": {
                    "file": "/tmp/log.db"
                }
            }
        ]
    }
}
"datasette-configure-asgi"键应是一个JSON对象列表。每个对象应有一个"class"键,指示要使用的类,以及一个可选的"args"键,提供传递给该类构造函数的任何必要参数。
插件结构
此插件可用于将您的Datasette实例包装在任何符合以下结构的ASGI中间件中
class SomeAsgiMiddleware:
    def __init__(self, app, arg1, arg2):
        self.app = app
        self.arg1 = arg1
        self.arg2 = arg2
    async def __call__(self, scope, receive, send):
        start = time.time()
        await self.app(scope, receive, send)
        end = time.time()
        print("Time taken: {}".format(end - start))
因此,中间件是一个具有构造函数的类,该构造函数将包装的应用程序作为第一个参数app,然后是进一步命名的参数以配置中间件。它提供一个async def __call__(self, scope, receive, send)方法来实现中间件的行为。
项目详情
    
       关闭
    
      
        
    
    
  
哈希值 for datasette_configure_asgi-0.1-py3-none-any.whl
| 算法 | 哈希摘要 | |
|---|---|---|
| SHA256 | 2061cf5184f5d9aaa7909f6fef54702c2595fcc731bdd4472518c07ce3fa8cb2 | |
| MD5 | 79b55380adfb541b4c33cf952eb9264e | |
| BLAKE2b-256 | f776c2ae1907ff0c5e8f3366c2041c1d73019b7825d6948ce880eb3ddf60be20 |