BJ Swope wrote:
  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,))

The traceback is saying that 'data' is None, not that it's too short
(that would raise an IndexError).
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to