使用asyncore/asynchat的http/https客户端库
async_http的Python项目详细描述
原点
这个包最初是作为一种概念证明github的要点编写的 2011年12月25日,约西亚·卡尔森。此更新包是版权所有的 2012年,并在gnu lgpl v2.1许可下发布。
说明
这个包提供了通过异步连接到http服务器的能力。 和Asynchhat模块,以尝试下载文件或以其他方式集成 从异步派生服务中连接到其他服务。
下载文件
- 包含的异步http.get模块,可在命令行上使用:
- $python-m async_http.get<;url列表>;
…将并行获取提供的URL。如果你查一下 py模块,您可以看到如何重写http_body(),http_done(), 和http_close()方法来(例如)远程获取内容 将它重定向到其他地方。
通过从下载文件中正确地进行子类化,您可以为远程文件提供类似的服务 对于此处请求的功能: http://code.google.com/p/pyftpdlib/issues/detail?id=197
发出OAuth请求
- 包含的async_http.oauth模块,可在命令行上使用:
- $python-m async_http.oauth ckey,csecret[tkey,tsecret]<;url>;
…将对提供的具有给定URL的OAuth 1.0A请求执行 客户端密钥和机密,带有可选的令牌密钥和机密(您的url将 确定是否需要某种访问或请求令牌)。
功能
- http/https
- 重定向支持
- 分块传输编码
- 超时
- 透明gzip处理 (源自http://effbot.org/zone/consumer-gzip.htm)
- OAuth 1.0A客户端支持(不需要其他第三方库)
API
如果要为事件编写自己的处理程序,请从 _ http.asynchttprequest,并重写以下一个或多个方法:
def http_setup(self): ''' Called just before the connection is set up. You can manipulate headers, request body, etc. ''' def http_response(self): ''' Called after the response is read. You can handle redirects, perform additional logging, start a reply in a proxy, etc. ''' def http_body(self): ''' Called at the end of every chunk with chunked transfer encoding, and any time data is read for the body otherwise. ''' def http_chunk(self): ''' Called after every chunk with the chunked transfer encoding, immediately after the body callback. ''' def http_done(self): ''' Called when the body has finshed being transferred. This will not be called when there is an error. ''' def http_close(self): ''' Called when the connection has been closed. '''