TypeError Exception in email lib

B

BJ Swope

File "/usr/lib/python2.5/email/_parseaddr.py", line 142, in mktime_tz
if data[9] is None:
TypeError: 'NoneType' object is unsubscriptable

I'm parsing a bunch of spam and using the date field from the spams
for a date-time stamp.

I've fixed the lib on my box to place the call inside a try/except
clause to catch the exception now, but it seems the module has a bug
in it.

How would I go about recommending a change the module?

Original code:
def mktime_tz(data):
"""Turn a 10-tuple as returned by parsedate_tz() into a UTC timestamp."""
if data[9] is None:
# No zone info, so localtime is better assumption than GMT
return time.mktime(data[:8] + (-1,))
else:
t = time.mktime(data[:8] + (0,))
return t - data[9] - time.timezone

Patched code:
def mktime_tz(data):
"""Turn a 10-tuple as returned by parsedate_tz() into a UTC timestamp."""
try:
if data[9] is None:
# No zone info, so localtime is better assumption than GMT
return time.mktime(data[:8] + (-1,))
else:
t = time.mktime(data[:8] + (0,))
return t - data[9] - time.timezone
except TypeError:
return time.mktime(data[:8] + (-1,))


----
Auburn fans are like slinkys... not really good for anything but they
still bring a smile to your face when you push them down a flight of
stairs.

To argue that honorable conduct is only required against an honorable
enemy degrades the Americans who must carry out the orders. -- Charles
Krulak, Former Commandant of the Marine Corps

We are all slave to our own paradigm. -- Joshua Williams

If the letters PhD appear after a person's name, that person will
remain outdoors even after it's started raining. -- Jeff Kay
 

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

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top