]> granicus.if.org Git - python/commitdiff
Time2Internaldate(): Call isinstance() once for each of the type tests
authorFred Drake <fdrake@acm.org>
Sat, 5 Jan 2002 17:17:09 +0000 (17:17 +0000)
committerFred Drake <fdrake@acm.org>
Sat, 5 Jan 2002 17:17:09 +0000 (17:17 +0000)
instead of possibly twice by using a sequence of types to check for.
Add a message to the ValueError that can be raised.

Lib/imaplib.py

index ed785ed3d42c409002ca416239a15bd0595ba3d2..04d4d87bb92fa73edbc81b3a148792d412d4a68d 100644 (file)
@@ -1069,14 +1069,14 @@ def Time2Internaldate(date_time):
     Return string in form: '"DD-Mmm-YYYY HH:MM:SS +HHMM"'
     """
 
-    if isinstance(date_time, int) or isinstance(date_time, float):
+    if isinstance(date_time, (int, float)):
         tt = time.localtime(date_time)
-    elif isinstance(date_time, tuple) or \
-             isinstance(date_time, time.struct_time):
+    elif isinstance(date_time, (tuple, time.struct_time)):
         tt = date_time
     elif isinstance(date_time, str):
         return date_time        # Assume in correct format
-    else: raise ValueError
+    else:
+        raise ValueError("date_time not of a known type")
 
     dt = time.strftime("%d-%b-%Y %H:%M:%S", tt)
     if dt[0] == '0':