def _format_date(dt):
    """convert a datetime into an RFC 822 formatted date

    Input date must be in GMT.
    """
    return '%s, %02d %s %04d %02d:%02d:%02d GMT' % (['Mon', 'Tue', 'Wed',
        'Thu', 'Fri', 'Sat', 'Sun'][dt.weekday()], dt.day, ['Jan', 'Feb',
        'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov',
        'Dec'][dt.month - 1], dt.year, dt.hour, dt.minute, dt.second)
