diff --git a/src/saml2/httpbase.py b/src/saml2/httpbase.py index 3b6b630..56d4a7e 100644 --- a/src/saml2/httpbase.py +++ b/src/saml2/httpbase.py @@ -67,11 +67,20 @@ def _since_epoch(cdate): if len(cdate) < 5: return utc_now() - cdate = cdate[5:] + cdate = cdate[5:] # assume short weekday, i.e. do not support obsolete RFC 1036 date format try: - t = time.strptime(cdate, "%d-%b-%Y %H:%M:%S %Z") + t = time.strptime(cdate, "%d-%b-%Y %H:%M:%S %Z") # e.g. 18-Apr-2014 12:30:51 GMT except ValueError: - t = time.strptime(cdate, "%d-%b-%y %H:%M:%S %Z") + try: + t = time.strptime(cdate, "%d-%b-%y %H:%M:%S %Z") # e.g. 18-Apr-14 12:30:51 GMT + except ValueError: + try: + t = time.strptime(cdate, "%d %b %Y %H:%M:%S %Z") # e.g. 18 Apr 2014 12:30:51 GMT + except ValueError: + raise Exception, 'ValueError: Date "{0}" does not match any of '.format(cdate) + \ + '"%d-%b-%Y %H:%M:%S %Z", ' + \ + '"%d-%b-%y %H:%M:%S %Z", ' + \ + '"%d %b %Y %H:%M:%S %Z".' #return int(time.mktime(t)) return calendar.timegm(t)