@@ -64,6 +64,10 @@ def __init__(self):
6464 locks to prevent changing the locale while locale-dependent code is
6565 running. The check here is done in case someone does not think about
6666 doing this.
67+
68+ Only other possible issue is if someone changed the timezone and did
69+ not call tz.tzset . That is an issue for the programmer, though,
70+ since changing the timezone is worthless without that call.
6771
6872 """
6973 self .lang = _getlang ()
@@ -155,6 +159,8 @@ def __calc_date_time(self):
155159
156160 def __calc_timezone (self ):
157161 # Set self.timezone by using time.tzname.
162+ # Do not worry about possibility of time.tzname[0] == timetzname[1]
163+ # and time.daylight; handle that in strptime .
158164 try :
159165 time .tzset ()
160166 except AttributeError :
@@ -237,7 +243,7 @@ def pattern(self, format):
237243 """Return regex pattern for the format string.
238244
239245 Need to make sure that any characters that might be interpreted as
240- regex syntax is escaped.
246+ regex syntax are escaped.
241247
242248 """
243249 processed_format = ''
@@ -263,11 +269,11 @@ def compile(self, format):
263269# DO NOT modify _TimeRE_cache or _regex_cache without acquiring the cache lock
264270# first!
265271_TimeRE_cache = TimeRE ()
266- _CACHE_MAX_SIZE = 5
272+ _CACHE_MAX_SIZE = 5 # Max number of regexes stored in _regex_cache
267273_regex_cache = {}
268274
269275def strptime (data_string , format = "%a %b %d %H:%M:%S %Y" ):
270- """Return a time struct based on the input data and the format string."""
276+ """Return a time struct based on the input string and the format string."""
271277 global _TimeRE_cache
272278 _cache_lock .acquire ()
273279 try :
@@ -355,14 +361,17 @@ def strptime(data_string, format="%a %b %d %H:%M:%S %Y"):
355361 # Since -1 is default value only need to worry about setting tz if
356362 # it can be something other than -1.
357363 found_zone = found_dict ['Z' ].lower ()
358- if locale_time .timezone [0 ] == locale_time .timezone [1 ] and \
359- time .daylight :
360- pass #Deals with bad locale setup where timezone info is
361- # the same; first found on FreeBSD 4.4.
362- else :
363- for value , tz_values in enumerate (locale_time .timezone ):
364- if found_zone in tz_values :
364+ for value , tz_values in enumerate (locale_time .timezone ):
365+ if found_zone in tz_values :
366+ # Deal with bad locale setup where timezone names are the
367+ # same and yet time.daylight is true; too ambiguous to
368+ # be able to tell what timezone has daylight savings
369+ if time .tzname [0 ] == time .tzname [1 ] and \
370+ time .daylight :
371+ break
372+ else :
365373 tz = value
374+ break
366375 # Cannot pre-calculate datetime_date() since can change in Julian
367376 #calculation and thus could have different value for the day of the week
368377 #calculation
0 commit comments