BJ Swope wrote:
Is the code that calls mktime_tz() your own? If so, maybe you'd be better off fixing that. The error message indicates that the 'data' parameter is None, which is invalid, according to the 2.6 documentation anyway (the parameter to the function is supposed to be a 10-tuple). So it's a bug in the caller, not in that function. Besides, your fix will still raise another exception inside the except class, since if data[9] gives that error, so will data[:8}File "/usr/lib/python2.5/email/_parseaddr.py", line 142, in mktime_tz if data[9] is None: TypeError: 'NoneType' object is unsubscriptableI'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
DaveA -- http://mail.python.org/mailman/listinfo/python-list
