changeset 4145:5bd2da7053a3

Removed httpDate from request object
author Florian Krupicka <florian.krupicka@googlemail.com>
date Fri, 06 Jun 2008 14:26:55 +0200
parents 0a62a439d81b
children 3b36f0cfc656
files MoinMoin/request/__init__.py MoinMoin/request/_tests/test_request.py MoinMoin/session.py
diffstat 3 files changed, 3 insertions(+), 52 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/request/__init__.py	Tue Jun 03 11:56:29 2008 +0200
+++ b/MoinMoin/request/__init__.py	Fri Jun 06 14:26:55 2008 +0200
@@ -1446,45 +1446,6 @@
         '''
         self.include_id, pids = self._include_stack.pop()
 
-    def httpDate(self, when=None, rfc='1123'):
-        """ Returns http date string, according to rfc2068
-
-        See http://www.cse.ohio-state.edu/cgi-bin/rfc/rfc2068.html#sec-3.3
-
-        A http 1.1 server should use only rfc1123 date, but cookie's
-        "expires" field should use the older obsolete rfc850 date.
-
-        Note: we can not use strftime() because that honors the locale
-        and rfc2822 requires english day and month names.
-
-        We can not use email.Utils.formatdate because it formats the
-        zone as '-0000' instead of 'GMT', and creates only rfc1123
-        dates. This is a modified version of email.Utils.formatdate
-        from Python 2.4.
-
-        @param when: seconds from epoch, as returned by time.time()
-        @param rfc: conform to rfc ('1123' or '850')
-        @rtype: string
-        @return: http date conforming to rfc1123 or rfc850
-        """
-        if when is None:
-            when = time.time()
-        now = time.gmtime(when)
-        month = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul',
-                 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'][now.tm_mon - 1]
-        if rfc == '1123':
-            day = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'][now.tm_wday]
-            date = '%02d %s %04d' % (now.tm_mday, month, now.tm_year)
-        elif rfc == '850':
-            day = ["Monday", "Tuesday", "Wednesday", "Thursday",
-                    "Friday", "Saturday", "Sunday"][now.tm_wday]
-            date = '%02d-%s-%s' % (now.tm_mday, month, str(now.tm_year)[-2:])
-        else:
-            raise ValueError("Invalid rfc value: %s" % rfc)
-
-        return '%s, %s %02d:%02d:%02d GMT' % (day, date, now.tm_hour,
-                                              now.tm_min, now.tm_sec)
-
     def disableHttpCaching(self, level=1):
         """ Prevent caching of pages that should not be cached.
 
--- a/MoinMoin/request/_tests/test_request.py	Tue Jun 03 11:56:29 2008 +0200
+++ b/MoinMoin/request/_tests/test_request.py	Fri Jun 06 14:26:55 2008 +0200
@@ -96,18 +96,6 @@
                 result = self.request.normalizePagename(test)
                 assert result == expected
 
-
-class TestHTTPDate(object):
-
-    def testRFC1123Date(self):
-        """ request: httpDate default rfc1123 """
-        assert self.request.httpDate(0) == 'Thu, 01 Jan 1970 00:00:00 GMT'
-
-    def testRFC850Date(self):
-        """ request: httpDate rfc850 """
-        assert self.request.httpDate(0, rfc='850') == 'Thursday, 01-Jan-70 00:00:00 GMT'
-
-
 class TestHTTPHeaders(object):
     std_headers = ['Status: 200 OK', 'Content-type: text/html; charset=%s' % config.charset]
 
--- a/MoinMoin/session.py	Tue Jun 03 11:56:29 2008 +0200
+++ b/MoinMoin/session.py	Fri Jun 06 14:26:55 2008 +0200
@@ -13,6 +13,8 @@
 
 import Cookie
 
+from werkzeug.utils import cookie_date
+
 from MoinMoin import log
 logging = log.getLogger(__name__)
 
@@ -317,7 +319,7 @@
                 path = '/'
             cookie[cookie_name]['path'] = path
         # Set expires for older clients
-        cookie[cookie_name]['expires'] = request.httpDate(when=expires, rfc='850')
+        cookie[cookie_name]['expires'] = cookie_date(expires)
         return cookie.output()
 
     def _set_cookie(self, request, cookie_string, expires):