[Python-bugs-list] [ python-Bugs-499169 ] imaplib.Time2Internaldate is broken

noreply@sourceforge.net noreply@sourceforge.net
Sat, 05 Jan 2002 03:34:42 -0800


Bugs item #499169, was opened at 2002-01-03 15:09
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=499169&group_id=5470

Category: Python Library
Group: Python 2.2
>Status: Closed
>Resolution: Fixed
Priority: 5
Submitted By: Ben Hutchings (wom-work)
Assigned to: Nobody/Anonymous (nobody)
Summary: imaplib.Time2Internaldate is broken

Initial Comment:
The type tests in this function have stopped working
because the return type of time.gmtime() and friends is
now time.struct_time and not tuple.

Secondly, the format string used for the timezone is
'%+02d%02d'.  I believe it should be '%+03d02d' since
the first field width includes the sign character.

A patch that works for me (note that it lets strftime
do its own type-checking):

--- imaplib.py~ Tue Oct 30 00:56:40 2001
+++ imaplib.py  Thu Jan  3 18:42:22 2002
@@ -1070,13 +1070,12 @@
     """

     dttype = type(date_time)
-    if dttype is type(1) or dttype is type(1.1):
+    if dttype is str:
+        return date_time
+    if dttype is int or dttype is float:
         tt = time.localtime(date_time)
-    elif dttype is type(()):
+    else:
         tt = date_time
-    elif dttype is type(""):
-        return date_time        # Assume in correct format
-    else: raise ValueError

     dt = time.strftime("%d-%b-%Y %H:%M:%S", tt)
     if dt[0] == '0':
@@ -1085,7 +1084,7 @@
         zone = -time.altzone
     else:
         zone = -time.timezone
-    return '"' + dt + " %+02d%02d" % divmod(zone/60,
60) + '"'
+    return '"' + dt + " %+03d%02d" % divmod(zone/60,
60) + '"'





----------------------------------------------------------------------

>Comment By: Martin v. Löwis (loewis)
Date: 2002-01-05 03:34

Message:
Logged In: YES 
user_id=21627

Thanks for the report. I took a slightly different approach,
since strftime raises TypeError in case of failure, whereas
this function used to raise ValueError: so I know check for
time.struct_time in addition to tuples. Committed as
imaplib.py 1.40 and 1.39.8.1, test_imaplib.py 1.1. 

----------------------------------------------------------------------

You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=499169&group_id=5470