Parse RFC 822 dates and times, with one minor difference: years may be 4DIGIT or 2DIGIT. http://tools.ietf.org/html/rfc822#section-5
(dt)
| 3481 | ).match |
| 3482 | |
| 3483 | def _parse_date_rfc822(dt): |
| 3484 | """Parse RFC 822 dates and times, with one minor |
| 3485 | difference: years may be 4DIGIT or 2DIGIT. |
| 3486 | http://tools.ietf.org/html/rfc822#section-5""" |
| 3487 | try: |
| 3488 | m = _rfc822_match(dt.lower()).groupdict(0) |
| 3489 | except AttributeError: |
| 3490 | return None |
| 3491 | |
| 3492 | # Calculate a date and timestamp |
| 3493 | for k in ('year', 'day', 'hour', 'minute', 'second'): |
| 3494 | m[k] = int(m[k]) |
| 3495 | m['month'] = _rfc822_months.index(m['month']) + 1 |
| 3496 | # If the year is 2 digits, assume everything in the 90's is the 1990's |
| 3497 | if m['year'] < 100: |
| 3498 | m['year'] += (1900, 2000)[m['year'] < 90] |
| 3499 | stamp = datetime.datetime(*[m[i] for i in |
| 3500 | ('year', 'month', 'day', 'hour', 'minute', 'second')]) |
| 3501 | |
| 3502 | # Use the timezone information to calculate the difference between |
| 3503 | # the given date and timestamp and Universal Coordinated Time |
| 3504 | tzhour = 0 |
| 3505 | tzmin = 0 |
| 3506 | if m['tz'] and m['tz'].startswith('gmt'): |
| 3507 | # Handle GMT and GMT+hh:mm timezone syntax (the trailing |
| 3508 | # timezone info will be handled by the next `if` block) |
| 3509 | m['tz'] = ''.join(m['tz'][3:].split(':')) or 'gmt' |
| 3510 | if not m['tz']: |
| 3511 | pass |
| 3512 | elif m['tz'].startswith('+'): |
| 3513 | tzhour = int(m['tz'][1:3]) |
| 3514 | tzmin = int(m['tz'][3:]) |
| 3515 | elif m['tz'].startswith('-'): |
| 3516 | tzhour = int(m['tz'][1:3]) * -1 |
| 3517 | tzmin = int(m['tz'][3:]) * -1 |
| 3518 | else: |
| 3519 | tzhour = _rfc822_tznames[m['tz']] |
| 3520 | delta = datetime.timedelta(0, 0, 0, 0, tzmin, tzhour) |
| 3521 | |
| 3522 | # Return the date and timestamp in UTC |
| 3523 | return (stamp - delta).utctimetuple() |
| 3524 | registerDateHandler(_parse_date_rfc822) |
| 3525 | |
| 3526 | def _parse_date_asctime(dt): |
no test coverage detected
searching dependent graphs…