Skip to content

Commit

Permalink
reverting some test but session.__hash needs work
Browse files Browse the repository at this point in the history
  • Loading branch information
mdipierro committed Oct 16, 2012
1 parent ab95dfa commit 3a1ba53
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Version 2.1.1 (2012-10-15 20:43:47) dev
Version 2.1.1 (2012-10-15 21:49:38) dev
18 changes: 5 additions & 13 deletions gluon/globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -608,8 +608,7 @@ def connect(
rcookies = response.cookies
rcookies[response.session_id_name] = response.session_id
rcookies[response.session_id_name]['path'] = '/'
pickle = cPickle.dumps(self)
self.__hash = hashlib.md5(pickle).digest()
self.__hash = hashlib.md5(str(self)).digest()
if self.flash:
(response.flash, self.flash) = (self.flash, None)

Expand Down Expand Up @@ -654,20 +653,16 @@ def _try_store_in_db(self, request, response):

# don't save if no change to session
__hash = self.__hash
pickle = None
if __hash is not None:
del self.__hash
pickle = cPickle.dumps(self)
if __hash == hashlib.md5(pickle).digest():
if __hash == hashlib.md5(str(self)).digest():
return
else:
pickle = cPickle.dumps(self)

(record_id_name, table, record_id, unique_key) = \
response._dbtable_and_field
dd = dict(locked=False, client_ip=request.client.replace(':','.'),
modified_datetime=request.now,
session_data=pickle,
session_data=cPickle.dumps(dict(self)),
unique_key=unique_key)
if record_id:
table._db(table.id == record_id).update(**dd)
Expand All @@ -685,11 +680,9 @@ def _try_store_on_disk(self, request, response):

# don't save if no change to session
__hash = self.__hash
pickle = None
if __hash is not None:
del self.__hash
pickle = cPickle.dumps(self)
if __hash == hashlib.md5(pickle).digest():
if __hash == hashlib.md5(str(self)).digest():
self._close(response)
return

Expand All @@ -707,8 +700,7 @@ def _try_store_on_disk(self, request, response):
response.session_locked = True

if response.session_file:
if not pickle: pickle = cPickle.dumps(self)
response.session_file.write(pickle)
cPickle.dump(dict(self), response.session_file)
response.session_file.truncate()
self._close(response)

Expand Down

0 comments on commit 3a1ba53

Please sign in to comment.