Re: Choosing Source Address to Bind Socket to in IMAP Client
On Wed, Nov 21, 2012 at 8:14 AM, brint...@controlledthinking.com wrote: Hello: 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.) ChrisA -- http://mail.python.org/mailman/listinfo/python-list
RE: Choosing Source Address to Bind Socket to in IMAP Client
brint...@controlledthinking.com wrote: Hello: 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? One assumes by programming. Thanks for any help... You are quite welcome. :) On a less flippant note, maybe some links would help you get started. http://www.doughellmann.com/PyMOTW/imaplib/ http://yuji.wordpress.com/2011/06/22/python-imaplib-imap-example-with-gmail/ http://docs.python.org/2/library/imaplib.html ~Ramit This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -- http://mail.python.org/mailman/listinfo/python-list
Re: Choosing Source Address to Bind Socket to in IMAP Client
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: Hello: 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.) ChrisA Unless I'm reading that wrong, that's specifying the address/host to connect to (the destination address) not the source address... -- http://mail.python.org/mailman/listinfo/python-list
Re: Choosing Source Address to Bind Socket to in IMAP Client
On Tuesday, November 20, 2012 1:59:34 PM UTC-8, Prasad, Ramit wrote: brintoul at controlledthinking.com wrote: Hello: 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? One assumes by programming. Thanks for any help... You are quite welcome. :) On a less flippant note, maybe some links would help you get started. http://www.doughellmann.com/PyMOTW/imaplib/ http://yuji.wordpress.com/2011/06/22/python-imaplib-imap-example-with-gmail/ http://docs.python.org/2/library/imaplib.html ~Ramit This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. While I appreciate your attempt at humor, this is not information which helps me. Perhaps you are not familiar with the basics of socket programming. This is all fine and dandy, and it is good to know what you don't know. If you're interested, look at the third argument to create_connection: http://docs.python.org/2/library/socket.html -- http://mail.python.org/mailman/listinfo/python-list
Re: Choosing Source Address to Bind Socket to in IMAP Client
On Wed, Nov 21, 2012 at 9:00 AM, brint...@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 -- http://mail.python.org/mailman/listinfo/python-list
RE: Choosing Source Address to Bind Socket to in IMAP Client
brint...@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? [snip] While I appreciate your attempt at humor, this is not information which helps me. Perhaps you are not familiar with the basics of socket programming. This is all fine and dandy, and it is good to know what you don't know. If you're interested, look at the third argument to create_connection: http://docs.python.org/2/library/socket.html Apologies, I misread your question. According to the imaplib docs, you can subclass IMAP4 and override `IMAP4.open` to create the socket and bind it to the desired interface. You could also connect using IMAP4 and then close/reopen the socket inside the IMAP4 connection object. I hope that is more help, Ramit This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -- http://mail.python.org/mailman/listinfo/python-list
Re: Choosing Source Address to Bind Socket to in IMAP Client
On Tuesday, November 20, 2012 2:41:58 PM UTC-8, Prasad, Ramit wrote: brintoul at controlledthinking.com wrote: Apologies, I misread your question. According to the imaplib docs, you can subclass IMAP4 and override `IMAP4.open` to create the socket and bind it to the desired interface. You could also connect using IMAP4 and then close/reopen the socket inside the IMAP4 connection object. I hope that is more help, Ramit Thanks, yes, that helps! Just out of curiosity, can you give me a quick link to the docs you are looking at? I'm not seeing anything which gets very specific in the docs for Python 2.7 at docs.python.org ... -- http://mail.python.org/mailman/listinfo/python-list
RE: Choosing Source Address to Bind Socket to in IMAP Client
brint...@controlledthinking.com wrote: On Tuesday, November 20, 2012 2:41:58 PM UTC-8, Prasad, Ramit wrote: brintoul at controlledthinking.com wrote: Apologies, I misread your question. According to the imaplib docs, you can subclass IMAP4 and override `IMAP4.open` to create the socket and bind it to the desired interface. You could also connect using IMAP4 and then close/reopen the socket inside the IMAP4 connection object. I hope that is more help, Ramit Thanks, yes, that helps! Just out of curiosity, can you give me a quick link to the docs you are looking at? I'm not seeing anything which gets very specific in the docs for Python 2.7 at docs.python.org ... It is not very specific or helpful but here is the text in question. ''' IMAP4.open(host, port) Opens socket to port at host. This method is implicitly called by the IMAP4 constructor. The connection objects established by this method will be used in the read, readline, send, and shutdown methods. You may override this method. ''' http://docs.python.org/2.7/library/imaplib.html#imaplib.IMAP4.open ~Ramit This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. -- http://mail.python.org/mailman/listinfo/python-list