Formats a timestamp in the format used by HTTP. The argument may be a numeric timestamp as returned by `time.time`, a time tuple as returned by `time.gmtime`, or a `datetime.datetime` object. >>> format_timestamp(1359312200) 'Sun, 27 Jan 2013 18:43:20 GMT'
(
ts: Union[int, float, tuple, time.struct_time, datetime.datetime]
)
| 850 | |
| 851 | |
| 852 | def format_timestamp( |
| 853 | ts: Union[int, float, tuple, time.struct_time, datetime.datetime] |
| 854 | ) -> str: |
| 855 | """Formats a timestamp in the format used by HTTP. |
| 856 | |
| 857 | The argument may be a numeric timestamp as returned by `time.time`, |
| 858 | a time tuple as returned by `time.gmtime`, or a `datetime.datetime` |
| 859 | object. |
| 860 | |
| 861 | >>> format_timestamp(1359312200) |
| 862 | 'Sun, 27 Jan 2013 18:43:20 GMT' |
| 863 | """ |
| 864 | if isinstance(ts, (int, float)): |
| 865 | time_num = ts |
| 866 | elif isinstance(ts, (tuple, time.struct_time)): |
| 867 | time_num = calendar.timegm(ts) |
| 868 | elif isinstance(ts, datetime.datetime): |
| 869 | time_num = calendar.timegm(ts.utctimetuple()) |
| 870 | else: |
| 871 | raise TypeError("unknown timestamp type: %r" % ts) |
| 872 | return email.utils.formatdate(time_num, usegmt=True) |
| 873 | |
| 874 | |
| 875 | RequestStartLine = collections.namedtuple( |
no outgoing calls