Skip to content

Commit a497d8b

Browse files
committed
In newer versions of mxDateTime you cannot compare DateTime objects with strings. This could cause errors in HTTPResponse.setCookie().
1 parent 844829c commit a497d8b

2 files changed

Lines changed: 21 additions & 22 deletions

File tree

WebKit/HTTPResponse.py

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -125,32 +125,30 @@ def setCookie(self, name, value, path='/', expires='ONCLOSE',
125125
126126
"""
127127
cookie = Cookie(name, value)
128-
if expires == 'ONCLOSE' or not expires:
129-
pass # this is already default behavior
130-
elif expires == 'NOW':
131-
cookie.delete()
132-
return
133-
elif expires == 'NEVER':
134-
t = time.gmtime(time.time())
135-
if expires == 'NEVER':
128+
t = expires
129+
if type(t) is StringType:
130+
if t == 'ONCLOSE':
131+
t = None
132+
elif t == 'NOW':
133+
cookie.delete()
134+
return
135+
elif t == 'NEVER':
136+
t = time.gmtime(time.time())
136137
t = (t[0] + 10,) + t[1:]
137-
t = time.strftime("%a, %d-%b-%Y %H:%M:%S GMT", t)
138-
cookie.setExpires(t)
139-
else:
140-
t = expires
141-
if type(t) is StringType and t and t[0] == '+':
142-
interval = timeDecode(t[1:])
143-
t = time.time() + interval
138+
elif t[0] == '+':
139+
t = time.time() + timeDecode(t[1:])
140+
if t:
144141
if type(t) in (IntType, LongType, FloatType):
145142
t = time.gmtime(t)
146143
if type(t) in (TupleType, TimeTupleType):
147144
t = time.strftime("%a, %d-%b-%Y %H:%M:%S GMT", t)
148-
if DateTime and \
149-
(type(t) is DateTime.DateTimeDeltaType
150-
or isinstance(t, DateTime.RelativeDateTime)):
151-
t = DateTime.now() + t
152-
if DateTime and type(t) is DateTime.DateTimeType:
153-
t = (t - t.gmtoffset()).strftime("%a, %d-%b-%Y %H:%M:%S GMT")
145+
if DateTime:
146+
if type(t) is DateTime.DateTimeDeltaType or isinstance(
147+
t, DateTime.RelativeDateTime):
148+
t = DateTime.now() + t
149+
if type(t) is DateTime.DateTimeType:
150+
t -= t.gmtoffset()
151+
t = t.strftime("%a, %d-%b-%Y %H:%M:%S GMT")
154152
cookie.setExpires(t)
155153
if path:
156154
cookie.setPath(path)

WebKit/Testing/SetCookie.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import time
2-
from WebKit.SidebarPage import SidebarPage
32
from MiscUtils import mxDateTime as DateTime
3+
from WebKit.SidebarPage import SidebarPage
4+
45

56
cookieValues = [
67
('onclose', 'ONCLOSE'),

0 commit comments

Comments
 (0)