@@ -45,6 +45,7 @@ def dynamodb_connection_factory():
4545 boto.dynamodb.layer2.Layer2 objects are state-less (aside from security
4646 tokens), we're not too concerned about thread safety issues.
4747 """
48+
4849 global _DYNAMODB_CONN
4950 if not _DYNAMODB_CONN :
5051 logger .debug ("Creating a DynamoDB connection." )
@@ -60,11 +61,11 @@ class SessionStore(SessionBase):
6061 """
6162 Implements DynamoDB session store.
6263 """
64+
6365 def __init__ (self , session_key = None ):
6466 super (SessionStore , self ).__init__ (session_key )
6567 self .table = dynamodb_connection_factory ().get_table (TABLE_NAME )
6668
67-
6869 def load (self ):
6970 """
7071 Loads session data from DynamoDB, runs it through the session
@@ -75,9 +76,9 @@ def load(self):
7576 """
7677
7778 try :
78- item = self .table .get_item (self . session_key ,
79- consistent_read = ALWAYS_CONSISTENT )
80- except (DynamoDBKeyNotFoundError ,SuspiciousOperation ):
79+ item = self .table .get_item (
80+ self . session_key , consistent_read = ALWAYS_CONSISTENT )
81+ except (DynamoDBKeyNotFoundError , SuspiciousOperation ):
8182 self .create ()
8283 return {}
8384
@@ -92,6 +93,7 @@ def exists(self, session_key):
9293 :returns: ``True`` if a session with the given key exists in the DB,
9394 ``False`` if not.
9495 """
96+
9597 key_already_exists = self .table .has_item (
9698 session_key ,
9799 consistent_read = ALWAYS_CONSISTENT ,
@@ -106,6 +108,7 @@ def create(self):
106108 Creates a new entry in DynamoDB. This may or may not actually
107109 have anything in it.
108110 """
111+
109112 while True :
110113 try :
111114 # Save immediately to ensure we have a unique entry in the
@@ -127,6 +130,7 @@ def save(self, must_create=False):
127130 :raises: ``CreateError`` if ``must_create`` is ``True`` and a session
128131 with the current session key already exists.
129132 """
133+
130134 # If the save method is called with must_create equal to True, I'm
131135 # setting self._session_key equal to None and when
132136 # self.get_or_create_session_key is called the new
@@ -138,11 +142,11 @@ def save(self, must_create=False):
138142 item = self .table .new_item (self .session_key )
139143 # Queue up a PUT operation for UpdateItem, which preserves the
140144 # existing 'created' attribute.
141- item .put_attribute ('data' ,self .encode (self ._get_session (no_load = must_create )))
145+ item .put_attribute ('data' , self .encode (self ._get_session (no_load = must_create )))
142146
143147 if must_create :
144148
145- item .put_attribute ('created' ,int (time .time ()))
149+ item .put_attribute ('created' , int (time .time ()))
146150 # We expect the data value to be False because we are creating a
147151 # new session
148152 item .put (expected_value = {'data' : False })
@@ -158,6 +162,7 @@ def delete(self, session_key=None):
158162 :keyword str session_key: Optionally, override the session key
159163 to delete.
160164 """
165+
161166 if session_key is None :
162167 if self .session_key is None :
163168 return
0 commit comments