--- _strptime.py.orig 2015-09-01 17:35:04.171122571 -0400 +++ _strptime.py 2015-09-01 17:58:41.847085410 -0400 @@ -191,12 +191,12 @@ base = super() base.__init__({ # The " \d" part of the regex is to make %c from ANSI C work - 'd': r"(?P3[0-1]|[1-2]\d|0[1-9]|[1-9]| [1-9])", + 'd': r"(?P\d{1,2})", 'f': r"(?P[0-9]{1,6})", 'H': r"(?P2[0-3]|[0-1]\d|\d)", 'I': r"(?P1[0-2]|0[1-9]|[1-9])", 'j': r"(?P36[0-6]|3[0-5]\d|[1-2]\d\d|0[1-9]\d|00[1-9]|[1-9]\d|0[1-9]|[1-9])", - 'm': r"(?P1[0-2]|0[1-9]|[1-9])", + 'm': r"(?P\d{1,2})", 'M': r"(?P[0-5]\d|\d)", 'S': r"(?P6[0-1]|[0-5]\d|\d)", 'U': r"(?P5[0-3]|[0-4]\d|\d)", ------------------------------------------------------------------------------- ====== BEFORE ====== >>> from _strptime import TimeRE >>> TimeRE().pattern('%m') '(?P1[0-2]|0[1-9]|[1-9])' >>> TimeRE().pattern('%d') '(?P3[0-1]|[1-2]\\d|0[1-9]|[1-9]| [1-9])' >>> import datetime >>> datetime.datetime.strptime('36', '%m') Traceback (most recent call last): File "", line 1, in File "/usr/lib/python3.4/_strptime.py", line 500, in _strptime_datetime tt, fraction = _strptime(data_string, format) File "/usr/lib/python3.4/_strptime.py", line 340, in _strptime data_string[found.end():]) ValueError: unconverted data remains: 6 >>> datetime.datetime.strptime('36', '%d') Traceback (most recent call last): File "", line 1, in File "/usr/lib/python3.4/_strptime.py", line 500, in _strptime_datetime tt, fraction = _strptime(data_string, format) File "/usr/lib/python3.4/_strptime.py", line 340, in _strptime data_string[found.end():]) ValueError: unconverted data remains: 6 >>> import time >>> time.strptime('36', '%m') Traceback (most recent call last): File "", line 1, in File "/usr/lib/python3.4/_strptime.py", line 494, in _strptime_time tt = _strptime(data_string, format)[0] File "/usr/lib/python3.4/_strptime.py", line 340, in _strptime data_string[found.end():]) ValueError: unconverted data remains: 6 >>> time.strptime('36', '%d') Traceback (most recent call last): File "", line 1, in File "/usr/lib/python3.4/_strptime.py", line 494, in _strptime_time tt = _strptime(data_string, format)[0] File "/usr/lib/python3.4/_strptime.py", line 340, in _strptime data_string[found.end():]) ValueError: unconverted data remains: 6 ===== AFTER ===== >>> from _strptime import TimeRE >>> TimeRE().pattern('%m') '(?P\\d{1,2})' >>> TimeRE().pattern('%d') '(?P\\d{1,2})' >>> import datetime >>> datetime.datetime.strptime('2001-55-01', '%Y-%m-%d') Traceback (most recent call last): File "", line 1, in File "/usr/lib/python3.4/_strptime.py", line 500, in _strptime_datetime tt, fraction = _strptime(data_string, format) File "/usr/lib/python3.4/_strptime.py", line 465, in _strptime datetime_date(year, 1, 1).toordinal() + 1 ValueError: month must be in 1..12 >>> datetime.datetime.strptime('2001-01-55', '%Y-%m-%d') Traceback (most recent call last): File "", line 1, in File "/usr/lib/python3.4/_strptime.py", line 500, in _strptime_datetime tt, fraction = _strptime(data_string, format) File "/usr/lib/python3.4/_strptime.py", line 465, in _strptime datetime_date(year, 1, 1).toordinal() + 1 ValueError: day is out of range for month >>> import time >>> time.strptime('2001-55-01', '%Y-%m-%d') Traceback (most recent call last): File "", line 1, in File "/usr/lib/python3.4/_strptime.py", line 494, in _strptime_time tt = _strptime(data_string, format)[0] File "/usr/lib/python3.4/_strptime.py", line 465, in _strptime datetime_date(year, 1, 1).toordinal() + 1 ValueError: month must be in 1..12 >>> time.strptime('2001-01-55', '%Y-%m-%d') Traceback (most recent call last): File "", line 1, in File "/usr/lib/python3.4/_strptime.py", line 494, in _strptime_time tt = _strptime(data_string, format)[0] File "/usr/lib/python3.4/_strptime.py", line 465, in _strptime datetime_date(year, 1, 1).toordinal() + 1 ValueError: day is out of range for month