Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #33677
| References | <72731eb3-1521-46f0-8601-8a2df58849d8@googlegroups.com> <mailman.102.1353448083.29569.python-list@python.org> <2d0c91ed-b3b0-4c1d-bb10-5ec1357ef9ce@googlegroups.com> |
|---|---|
| Date | 2012-11-21 09:35 +1100 |
| Subject | Re: Choosing Source Address to Bind Socket to in IMAP Client |
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.111.1353450918.29569.python-list@python.org> (permalink) |
On Wed, Nov 21, 2012 at 9:00 AM, <brintoul@controlledthinking.com> wrote:
> On Tuesday, November 20, 2012 1:48:46 PM UTC-8, Chris Angelico wrote:
>> On Wed, Nov 21, 2012 at 8:14 AM, <brintoul at controlledthinking.com> wrote:
>>
>> > I have a multihomed machine that I would like to run the Python imaplib's IMAP4 client on. I would like to be able to specify which interface the underlying socket will bind to as its source address. How could I best do this?
>>
>> You're referring to this function?
>>
>> http://docs.python.org/3.3/library/imaplib.html#imaplib.IMAP4
>>
>> The docs suggest that you can simply pass it a parameter to specify
>> the address to bind to. (Note that you bind to addresses, not
>> interfaces. Figuring out which interface has which address is a
>> separate issue.)
>>
>
> Unless I'm reading that wrong, that's specifying the address/host to connect to (the destination address) not the source address...
Ah, whoops! My bad. For some reason I was thinking that was creating a
server socket. Sorry!
Poking around in the source (imaplib.py) shows that it creates a socket here:
class IMAP4:
def _create_socket(self):
return socket.create_connection((self.host, self.port))
Adding a third parameter to create_connection would do what you want.
(Note that this is currently getting one parameter, not two.)
http://docs.python.org/3.3/library/socket.html#socket.create_connection
My recommendation: Subclass IMAP4 and override this one function.
ChrisA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Choosing Source Address to Bind Socket to in IMAP Client brintoul@controlledthinking.com - 2012-11-20 13:14 -0800
Re: Choosing Source Address to Bind Socket to in IMAP Client Chris Angelico <rosuav@gmail.com> - 2012-11-21 08:47 +1100
Re: Choosing Source Address to Bind Socket to in IMAP Client brintoul@controlledthinking.com - 2012-11-20 14:00 -0800
Re: Choosing Source Address to Bind Socket to in IMAP Client Chris Angelico <rosuav@gmail.com> - 2012-11-21 09:35 +1100
Re: Choosing Source Address to Bind Socket to in IMAP Client brintoul@controlledthinking.com - 2012-11-20 14:00 -0800
RE: Choosing Source Address to Bind Socket to in IMAP Client "Prasad, Ramit" <ramit.prasad@jpmorgan.com> - 2012-11-20 21:58 +0000
Re: Choosing Source Address to Bind Socket to in IMAP Client brintoul@controlledthinking.com - 2012-11-20 14:12 -0800
RE: Choosing Source Address to Bind Socket to in IMAP Client "Prasad, Ramit" <ramit.prasad@jpmorgan.com> - 2012-11-20 22:41 +0000
Re: Choosing Source Address to Bind Socket to in IMAP Client brintoul@controlledthinking.com - 2012-11-20 14:55 -0800
RE: Choosing Source Address to Bind Socket to in IMAP Client "Prasad, Ramit" <ramit.prasad@jpmorgan.com> - 2012-11-20 23:10 +0000
Re: Choosing Source Address to Bind Socket to in IMAP Client brintoul@controlledthinking.com - 2012-11-20 14:55 -0800
Re: Choosing Source Address to Bind Socket to in IMAP Client brintoul@controlledthinking.com - 2012-11-20 14:12 -0800
csiph-web