使用Twisted中的http.Request实例来访问频道。

2024-05-19 12:03:32 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在做一个使用Twisted web设施的项目,但不使用高级web框架。如何访问创建了某个http.Request实例的HTTPChannel实例(twistedprotocol)?在

我看到http.Request的构造函数将通道作为参数,但没有方法/属性进一步访问它。在

另外,虽然我可以通过factory属性从通道访问HTTPFactory实例,但我可以直接从请求实例访问工厂吗?在


Tags: 项目实例方法框架webhttp参数属性
1条回答
网友
1楼 · 发布于 2024-05-19 12:03:32

频道似乎可以直接在Request上使用。考虑Request.__init__

def __init__(self, channel, queued):
    """                                                                                                                                     
    @param channel: the channel we're connected to.                                                                                         
    @param queued: are we in the request queue, or can we start writing to                                                                  
        the transport?                                                                                                                      
    """
    self.notifications = []
    self.channel = channel
    self.queued = queued
    ...

self.channel = channel似乎正是您要找的。在

相关问题 更多 >

    热门问题