Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e16e01f

Browse files
committed
Patch #639112: fixes for None locale and tz.
1 parent e4827eb commit e16e01f

2 files changed

Lines changed: 154 additions & 61 deletions

File tree

Lib/_strptime.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
from re import IGNORECASE
2727
from string import whitespace as whitespace_string
2828

29-
__version__ = (2,1,6)
3029
__author__ = "Brett Cannon"
3130
__email__ = "[email protected]"
3231

@@ -287,13 +286,19 @@ def __calc_timezone(self):
287286
self.__timezone = self.__pad(time.tzname, 0)
288287

289288
def __calc_lang(self):
290-
# Set self.lang by using locale.getlocale() or
291-
# locale.getdefaultlocale().
289+
# Set self.__lang by using locale.getlocale() or
290+
# locale.getdefaultlocale(). If both turn up empty, set the attribute
291+
# to ''. This is to stop calls to this method and to make sure
292+
# strptime() can produce an re object correctly.
292293
current_lang = locale.getlocale(locale.LC_TIME)[0]
293294
if current_lang:
294295
self.__lang = current_lang
295296
else:
296-
self.__lang = locale.getdefaultlocale()[0]
297+
current_lang = locale.getdefaultlocale()[0]
298+
if current_lang:
299+
self.__lang = current_lang
300+
else:
301+
self.__lang = ''
297302

298303

299304
class TimeRE(dict):
@@ -463,7 +468,10 @@ def strptime(data_string, format="%a %b %d %H:%M:%S %Y"):
463468
julian = int(found_dict['j'])
464469
elif group_key == 'Z':
465470
found_zone = found_dict['Z'].lower()
466-
if locale_time.timezone[0].lower() == found_zone:
471+
if locale_time.timezone[0] == locale_time.timezone[1]:
472+
pass #Deals with bad locale setup where timezone info is
473+
# the same; first found on FreeBSD 4.4 -current
474+
elif locale_time.timezone[0].lower() == found_zone:
467475
tz = 0
468476
elif locale_time.timezone[1].lower() == found_zone:
469477
tz = 1

0 commit comments

Comments
 (0)