Practical considerations for python function support from 3.3 to 2.7 compared to monkeypatching

I'm interested in the new smtplib feature introduced in python3.3: the ability to bind to a specific IP address in a multihomed machine (or a device with multiple IP addresses).

Many building blocks that I would like to use are not ported to 3.3 or have very unstable ports, so the idea of ​​using 3.3 just because of this function is impractical.

To back up this feature, I can install a patch or monkeypatch. I am prone to subclass smtplib.SMTP and monkeypatch on the main socket because it simplifies the deployment, it seems unlikely to affect the base class and is easier than the politically correct backport.

In the world of rubies, monkeypatching is more tolerant, but in most python circles this dangerous but often used method is disapproving.

My question is: have you ever come across such a solution and / or would like to share some tips?

(I am interested in the pros and cons of each approach)

[update]

pps actually, thinking a little more, I always assumed that fixing the monkey meant somehow modifying the existing classes in place so that the new code gets called upon loading from the standard location (I have to admit, now that I think about it, I have I don’t know how you could do this). this is not what I suggest here - this subclass will be a new class in my own module, which is used only by my own code. [andrew cooke]

, , . , SMTP.connect, , , , . , mokeypatching - , , - , . , -, , , .: -)

[]

- SMTP, EHLO, IP-:

s = SMTP('localhost', 8025)
# will use 173.22.213.16 as the outgoing IP address
s.ehlo('example.com 173.22.213.16') 

twisted, 40 SLOC, , 2,7, .

+3
1

, , SMTP SMTP.connect() , , self.sock.connect() _ ( ).

, - ( ruby), , python. , . SMTP, HTTP-lib , HTTP-. , , ( HTTP- , ).

( , , - ? , , - , , , , , , , , . , "" smtplib - - , .)

ps , , .

SMTP, , ; docs; smtplib docs

pps , , , - , ( , , , , ). , - , .

+1

All Articles