diff options
author | Neal Norwitz <nnorwitz@gmail.com> | 2002-12-30 22:23:12 (GMT) |
---|---|---|
committer | Neal Norwitz <nnorwitz@gmail.com> | 2002-12-30 22:23:12 (GMT) |
commit | 5efc50d8afd31dc4cb0ef1b58899943eb0e4cb67 (patch) | |
tree | 0471cb69de9b81bd860ee9b633fea13eb4193f3d | |
parent | 0940c6267af3d4ba2ecf10096b2df5dd4b715650 (diff) | |
download | cpython-5efc50d8afd31dc4cb0ef1b58899943eb0e4cb67.zip cpython-5efc50d8afd31dc4cb0ef1b58899943eb0e4cb67.tar.gz cpython-5efc50d8afd31dc4cb0ef1b58899943eb0e4cb67.tar.bz2 |
Fix SF #658820, regex fixes for _strptime (Brett Cannon)
Disallow zero for days and months
-rw-r--r-- | Lib/_strptime.py | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/Lib/_strptime.py b/Lib/_strptime.py index b7f7577..97cb551 100644 --- a/Lib/_strptime.py +++ b/Lib/_strptime.py @@ -306,22 +306,23 @@ class TimeRE(dict): def __init__(self, locale_time=LocaleTime()): """Init inst with non-locale regexes and store LocaleTime object.""" - # XXX: should 0 be valid for: - # day (d), julian day (j), month (m), and hour12 (I)? - super(TimeRE,self).__init__({ + #XXX: Does 'Y' need to worry about having less or more than 4 digits? + base = super(TimeRE, self) + base.__init__({ # The " \d" option is to make %c from ANSI C work - 'd': r"(?P<d>3[0-1]|[0-2]\d|\d| \d)", + 'd': r"(?P<d>3[0-1]|[1-2]\d|0[1-9]|[1-9]| [1-9])", 'H': r"(?P<H>2[0-3]|[0-1]\d|\d)", - 'I': r"(?P<I>0\d|1[0-2]|\d)", - 'j': r"(?P<j>(?:3[0-5]\d|36[0-6])|[0-2]\d\d|\d\d|\d)", - 'm': r"(?P<m>0\d|1[0-2]|\d)", + 'I': r"(?P<I>1[0-2]|0[1-9]|[1-9])", + 'j': r"(?P<j>36[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"(?P<m>1[0-2]|0[1-9]|[1-9])", 'M': r"(?P<M>[0-5]\d|\d)", 'S': r"(?P<S>6[0-1]|[0-5]\d|\d)", 'U': r"(?P<U>5[0-3]|[0-4]\d|\d)", 'w': r"(?P<w>[0-6])", - 'W': r"(?P<W>5[0-3]|[0-4]\d|\d)", # Same as U + # W is set below by using 'U' 'y': r"(?P<y>\d\d)", 'Y': r"(?P<Y>\d\d\d\d)"}) + base.__setitem__('W', base.__getitem__('U')) self.locale_time = locale_time def __getitem__(self, fetch): |