def rfc2822_format(val):
 if isinstance(val, six.string_types):
  return val
 elif isinstance(val, (datetime.datetime, datetime.date)):
  val = time.mktime(val.timetuple())
 if isinstance(val, numbers.Number):
  return email.utils.formatdate(val)
 else:
  return val

def rfc2822_format ( val ) : if isinstance ( val , six . string_types ) : return val elif isinstance ( val , ( datetime . datetime , datetime . date ) ) : val = time . mktime ( val . timetuple ( ) ) if isinstance ( val , numbers . Number ) : return email . utils . formatdate ( val ) else : return val
takes either a date .