Skip to content
This repository was archived by the owner on Dec 28, 2017. It is now read-only.

Commit 03080e8

Browse files
committed
PEP8 pass.
1 parent c0ec578 commit 03080e8

File tree

5 files changed

+27
-22
lines changed

5 files changed

+27
-22
lines changed

README.rst

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,12 @@ The following settings may be used in your ``settings.py``:
9797
Changes
9898
-------
9999

100+
0.6
101+
^^^
102+
103+
* Removing some no longer used imports.
104+
* PEP8 cleanup.
105+
100106
0.5
101107
^^^
102108

@@ -127,4 +133,4 @@ License
127133

128134
django-dynamodb-sessions is licensed under the `BSD License`_.
129135

130-
.. _BSD License: https://github.com/gtaylor/django-dynamodb-sessions/blob/master/LICENSE
136+
.. _BSD License: https://github.com/gtaylor/django-dynamodb-sessions/blob/master/LICENSE

dynamodb_sessions/backends/cached_dynamodb.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
"""
44

55
from django.conf import settings
6-
from dynamodb_sessions.backends.dynamodb import SessionStore as DynamoDBStore
76
from django.core.cache import cache
87

8+
from dynamodb_sessions.backends.dynamodb import SessionStore as DynamoDBStore
9+
910
KEY_PREFIX = "dynamodb_sessions.backends.cached_dynamodb"
1011

12+
1113
class SessionStore(DynamoDBStore):
1214
"""
1315
Implements cached, database backed sessions.
@@ -49,6 +51,7 @@ def flush(self):
4951
Removes the current session data from the database and regenerates the
5052
key.
5153
"""
54+
5255
self.clear()
5356
self.delete(self.session_key)
5457
self.create()

dynamodb_sessions/backends/dynamodb.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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

dynamodb_sessions/models.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +0,0 @@
1-
'''
2-
Created on Feb 13, 2013
3-
4-
@author: brian
5-
'''

dynamodb_sessions/tests.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
1-
'''
2-
Created on Feb 13, 2013
3-
4-
@author: brian
5-
'''
6-
from django.contrib.sessions.tests import SessionTestsMixin,DatabaseSessionTests
1+
from django.contrib.sessions.tests import SessionTestsMixin
72
from django.test import TestCase
83

94
from .backends.dynamodb import SessionStore as DynamoDBSession
105
from .backends.cached_dynamodb import SessionStore as CachedDynamoDBSession
116

12-
class DynamoDBTestCase(SessionTestsMixin,TestCase):
7+
8+
class DynamoDBTestCase(SessionTestsMixin, TestCase):
139

1410
backend = DynamoDBSession
1511

16-
class CachedDynamoDBTestCase(SessionTestsMixin,TestCase):
12+
13+
class CachedDynamoDBTestCase(SessionTestsMixin, TestCase):
1714

1815
backend = CachedDynamoDBSession
19-

0 commit comments

Comments
 (0)