重载twisted.client.getPage来设置客户端套接字的绑定地址!

发布于 2024-09-12 20:44:27 字数 257 浏览 6 评论 0原文

在过去的 10 个小时里,我一直在努力实现这一目标:

Translation of myblocking httpclient using standard lib... 变成它的扭曲的非阻塞/异步版本。

10 小时后...通过他们的 API 进行评分——似乎没有人需要做这件事。不错的框架,但似乎......将套接字设置到不同的接口有点难以承受。

任何Python专家都可以阐明这一点和/或引导我走向正确的方向吗?或者我可能错过的任何文档?谢谢!

For the past 10 hours I've been trying to accomplish this:

Translation of my blocking httpclient using standard lib...
Into a twisted nonblocking/async version of it.

10 hours later... scoring through their APIs-- it appears no one has EVER needed to do be able to do that. Nice framework, but seems ...a bit overwhelming to just set a socket to a different interface.

Can any python gurus shed some light on this and/or send me in the right direction? or any docs that I could have missed? THANKS!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

反目相谮 2024-09-19 20:44:27

嗯,看起来你并没有错过任何事情。 client.getPage不直接支持设置绑定地址。我只是在这里猜测,但我怀疑这是原始开发人员从未想到有人想要指定绑定地址的情况之一。

尽管没有内置支持这样做,但它应该很容易做到。在twisted 中指定传出连接的绑定地址的方法是将绑定地址传递给reactor.connectXXX() 函数。幸运的是,getPage() 的代码非常简单。我建议三件事:

  1. getPage() 的代码及其关联的辅助函数复制到您的项目中
  2. 修改它们以通过绑定地址
  3. 创建一个补丁来修复此疏忽并将其发送到 Twisted各位:)

Well, it doesn't look like you've missed anything. client.getPage doesn't directly support setting the bind address. I'm just guessing here but I would suspect it's one of those cases where it just never occured to the original developer that someone would want to specify the bind address.

Even though there isn't built-in support for doing this, it should be pretty easy to do. The way you specify binding addresses for outgoing connections in twisted is by passing the bind address to the reactor.connectXXX() functions. Fortunately, the code for getPage() is really simple. I'd suggest three things:

  1. Copy the code for getPage() and it's associated helper function into your project
  2. Modify them to pass through the bind address
  3. Create a patch to fix this oversight and send it to the Twisted folks :)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文