This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vinay.sajip
Recipients giampaolo.rodola, r.david.murray, vinay.sajip
Date 2011-04-30.15:24:06
SpamBayes Score 4.4991194e-10
Marked as misclassified No
Message-id <1304177047.14.0.270149852599.issue11959@psf.upfronthosting.co.za>
In-reply-to
Content
I don't want to use two different maps - I just want to use a single map which is not the global "socket_map" in asyncore.

asyncore.dispatcher and asynchat.async_chat allow for a map to be passed in so that the default global is not used, but smtpd does not allow this. Note that asyncore.loop() also allows a map to be passed in, so I'm sure this functionality is by design.

I mentioned two places where the map is to be used - passed to SMTPServer constructor (and saved in SMPTServer instance) and the *same* map used to initialise the SMTPChannel from SMTPServer.handle_accepted().

Since asyncore and asynchat support using a passed-in map to avoid using a global, it's not unreasonable to expect smtpd to support it too. After all, using it relies on asyncore.loop(), and passing an explicit map is allowed here.

I initially came across this because I got some warnings from regrtest.py about changed state, when I was trying to implement a TestSMTPServer class (derived from smtpd.SMTPServer) to test the SMTPHandler in logging.

I've taken out the functionality from test_logging for now, but I have a test script here:

https://gist.github.com/949744

This successfully uses a non-global map ("my_map"), but notice how much I had to resort to copypasta.

If I've missed some neat solution which avoids this hackery, please let me know! This is my first use of the smtpd module :-)

As I say, what I'm trying to do is to avoid changing global state in the unit test suite.
History
Date User Action Args
2011-04-30 15:24:07vinay.sajipsetrecipients: + vinay.sajip, giampaolo.rodola, r.david.murray
2011-04-30 15:24:07vinay.sajipsetmessageid: <1304177047.14.0.270149852599.issue11959@psf.upfronthosting.co.za>
2011-04-30 15:24:06vinay.sajiplinkissue11959 messages
2011-04-30 15:24:06vinay.sajipcreate