Mercurial > p > roundup > code
comparison roundup/cgi/client.py @ 4980:13f8f88ad984
Replace rfc822 imports with email package (issue2550870)
The rfc822 package has been deprecated since Python v2.3 in favour of
the email package.
| author | John Kristensen <john@jerrykan.com> |
|---|---|
| date | Fri, 27 Feb 2015 00:48:25 +1100 |
| parents | f1a2bd1dea77 |
| children | 494d255043c9 |
comparison
equal
deleted
inserted
replaced
| 4979:f1a2bd1dea77 | 4980:13f8f88ad984 |
|---|---|
| 1 """WWW request handler (also used in the stand-alone server). | 1 """WWW request handler (also used in the stand-alone server). |
| 2 """ | 2 """ |
| 3 __docformat__ = 'restructuredtext' | 3 __docformat__ = 'restructuredtext' |
| 4 | 4 |
| 5 import base64, binascii, cgi, codecs, mimetypes, os | 5 import base64, binascii, cgi, codecs, mimetypes, os |
| 6 import quopri, random, re, rfc822, stat, sys, time | 6 import quopri, random, re, stat, sys, time |
| 7 import socket, errno | 7 import socket, errno |
| 8 import email.utils | |
| 8 from traceback import format_exc | 9 from traceback import format_exc |
| 9 | 10 |
| 10 try: | 11 try: |
| 11 from OpenSSL.SSL import SysCallError | 12 from OpenSSL.SSL import SysCallError |
| 12 except ImportError: | 13 except ImportError: |
| 493 date = time.time() - 1 | 494 date = time.time() - 1 |
| 494 #if self._error_message or self._ok_message: | 495 #if self._error_message or self._ok_message: |
| 495 # date = time.time() - 1 | 496 # date = time.time() - 1 |
| 496 #else: | 497 #else: |
| 497 # date = time.time() + 5 | 498 # date = time.time() + 5 |
| 498 self.additional_headers['Expires'] = rfc822.formatdate(date) | 499 self.additional_headers['Expires'] = \ |
| 500 email.utils.formatdate(date, usegmt=True) | |
| 499 | 501 |
| 500 # render the content | 502 # render the content |
| 501 self.write_html(self.renderContext()) | 503 self.write_html(self.renderContext()) |
| 502 except SendFile, designator: | 504 except SendFile, designator: |
| 503 # The call to serve_file may result in an Unauthorised | 505 # The call to serve_file may result in an Unauthorised |
| 1072 """ guts of serve_file() and serve_static_file() | 1074 """ guts of serve_file() and serve_static_file() |
| 1073 """ | 1075 """ |
| 1074 | 1076 |
| 1075 # spit out headers | 1077 # spit out headers |
| 1076 self.additional_headers['Content-Type'] = mime_type | 1078 self.additional_headers['Content-Type'] = mime_type |
| 1077 self.additional_headers['Last-Modified'] = rfc822.formatdate(lmt) | 1079 self.additional_headers['Last-Modified'] = email.utils.formatdate(lmt) |
| 1078 | 1080 |
| 1079 ims = None | 1081 ims = None |
| 1080 # see if there's an if-modified-since... | 1082 # see if there's an if-modified-since... |
| 1081 # XXX see which interfaces set this | 1083 # XXX see which interfaces set this |
| 1082 #if hasattr(self.request, 'headers'): | 1084 #if hasattr(self.request, 'headers'): |
| 1083 #ims = self.request.headers.getheader('if-modified-since') | 1085 #ims = self.request.headers.getheader('if-modified-since') |
| 1084 if 'HTTP_IF_MODIFIED_SINCE' in self.env: | 1086 if 'HTTP_IF_MODIFIED_SINCE' in self.env: |
| 1085 # cgi will put the header in the env var | 1087 # cgi will put the header in the env var |
| 1086 ims = self.env['HTTP_IF_MODIFIED_SINCE'] | 1088 ims = self.env['HTTP_IF_MODIFIED_SINCE'] |
| 1087 if ims: | 1089 if ims: |
| 1088 ims = rfc822.parsedate(ims)[:6] | 1090 ims = email.utils.parsedate(ims)[:6] |
| 1089 lmtt = time.gmtime(lmt)[:6] | 1091 lmtt = time.gmtime(lmt)[:6] |
| 1090 if lmtt <= ims: | 1092 if lmtt <= ims: |
| 1091 raise NotModified | 1093 raise NotModified |
| 1092 | 1094 |
| 1093 if filename: | 1095 if filename: |
