(solved) smtplib, capturing output from set_debuglevel ??

T

Tim Williams

----- Original Message -----
From: "Tim Williams said:
----- Original Message -----
From: "Steve Holden" <[email protected]> [snip]
Yeah, I did wonder about changing the code (though it's not my first
choice. I've done it before and caught a crab later), or could I do it
with Subclassing?

I'm still close to Newbie status, so I can't immediately imagine what I
could change the smptblib code to write to, or how to subclass to get
the behaviour I might need.

Doh, still thinking of myself as close to newbie scares me off some things
!!

I decided to bite the bullet and have a look at the code for smtplib,
(after being scared of changing it before), and of course its what I
should have done in the first place.

The debug output in smptlib is generated in the SMTP class with lines
similar to:

if self.debuglevel > 0: print "connect:", msg

so, I added a new variable within the class

debug_out = []

and 2 new functions within the class

def do_debug(self,msgs):
if self.debuglevel > 0: print msgs
self.debug_out.append(msgs)

def debug(self):
return self.debug_out

and changed

if self.debuglevel > 0: print "connect:", msg

to

self.do_debug( ('connect:', msg ) )

Took me about 4 minutes !!

now I can call s.debug() and get a list containing the debug information.
s.debug() can be called at anytime including after s.quit()

As a side benefit, I can use s.do_debug( msg ) at any time to get the
program to add (comment) lines to the debug information. This will be
useful when reading the full retrieved debug information at a later date.

set_debuglevel() works exactly as it did before.

I have to tidy up the formatting/handling of the messages, and I think I'm
going to add an option to retrieve the debug information without the
message data (as its usually superfluous to the debugging process) , but
other than that it does just what I need already.

Is it worth asking for something like this to be added permanently to
smtplib, I can't be the only one that needs to log outgoing smtp
conversations, or debug to a file/log ?

Thanks for everyone's help

Tim
 
S

Steve Holden

Tim said:
----- Original Message -----
From: "Tim Williams said:
----- Original Message -----
From: "Steve Holden" <[email protected]>
[snip]

Yeah, I did wonder about changing the code (though it's not my first
choice. I've done it before and caught a crab later), or could I do it
with Subclassing?
[...Tim fixes smtplib...]

Took me about 4 minutes !!

now I can call s.debug() and get a list containing the debug information.
s.debug() can be called at anytime including after s.quit()

As a side benefit, I can use s.do_debug( msg ) at any time to get the
program to add (comment) lines to the debug information. This will be
useful when reading the full retrieved debug information at a later date.

set_debuglevel() works exactly as it did before.

I have to tidy up the formatting/handling of the messages, and I think I'm
going to add an option to retrieve the debug information without the
message data (as its usually superfluous to the debugging process) , but
other than that it does just what I need already.

Is it worth asking for something like this to be added permanently to
smtplib, I can't be the only one that needs to log outgoing smtp
conversations, or debug to a file/log ?

Thanks for everyone's help
Correct action under these circumstances would be to submit a patch.
This sounds intimidating of you've never done it before, but the process
isn;t that difficult once you've created your SourceForgew account, and
there are meny experienced hands on the list who will help you if you
get stuck.

regards
Steve
 
S

Steve Holden

Tim said:
----- Original Message -----
From: "Tim Williams said:
----- Original Message -----
From: "Steve Holden" <[email protected]>
[snip]

Yeah, I did wonder about changing the code (though it's not my first
choice. I've done it before and caught a crab later), or could I do it
with Subclassing?
[...Tim fixes smtplib...]

Took me about 4 minutes !!

now I can call s.debug() and get a list containing the debug information.
s.debug() can be called at anytime including after s.quit()

As a side benefit, I can use s.do_debug( msg ) at any time to get the
program to add (comment) lines to the debug information. This will be
useful when reading the full retrieved debug information at a later date.

set_debuglevel() works exactly as it did before.

I have to tidy up the formatting/handling of the messages, and I think I'm
going to add an option to retrieve the debug information without the
message data (as its usually superfluous to the debugging process) , but
other than that it does just what I need already.

Is it worth asking for something like this to be added permanently to
smtplib, I can't be the only one that needs to log outgoing smtp
conversations, or debug to a file/log ?

Thanks for everyone's help
Correct action under these circumstances would be to submit a patch.
This sounds intimidating of you've never done it before, but the process
isn;t that difficult once you've created your SourceForgew account, and
there are meny experienced hands on the list who will help you if you
get stuck.

regards
Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,796
Messages
2,569,645
Members
45,369
Latest member
Carmen32T6

Latest Threads

Top