summaryrefslogtreecommitdiffstats
path: root/appengine_django/sessions/backends
diff options
context:
space:
mode:
authorbryan newbold <bnewbold@snark.mit.edu>2009-06-14 19:51:50 -0400
committerbryan newbold <bnewbold@snark.mit.edu>2009-06-14 19:51:50 -0400
commitae078728c8bc1c7d4412c4cb19b6802e9b7e8f74 (patch)
tree978ab726bbad7575ffb66d5e2ceee6b69a1096f1 /appengine_django/sessions/backends
parent0c17a5bb3d6b637f0197418f792045509b7e2d7b (diff)
downloadequator-ae078728c8bc1c7d4412c4cb19b6802e9b7e8f74.tar.gz
equator-ae078728c8bc1c7d4412c4cb19b6802e9b7e8f74.zip
initial appengine setup; BROKEN
Diffstat (limited to 'appengine_django/sessions/backends')
-rw-r--r--appengine_django/sessions/backends/__init__.py0
-rw-r--r--appengine_django/sessions/backends/__init__.pycbin0 -> 165 bytes
-rw-r--r--appengine_django/sessions/backends/db.py82
-rw-r--r--appengine_django/sessions/backends/db.pycbin0 -> 2820 bytes
4 files changed, 82 insertions, 0 deletions
diff --git a/appengine_django/sessions/backends/__init__.py b/appengine_django/sessions/backends/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/appengine_django/sessions/backends/__init__.py
diff --git a/appengine_django/sessions/backends/__init__.pyc b/appengine_django/sessions/backends/__init__.pyc
new file mode 100644
index 0000000..4242888
--- /dev/null
+++ b/appengine_django/sessions/backends/__init__.pyc
Binary files differ
diff --git a/appengine_django/sessions/backends/db.py b/appengine_django/sessions/backends/db.py
new file mode 100644
index 0000000..e2e3aa4
--- /dev/null
+++ b/appengine_django/sessions/backends/db.py
@@ -0,0 +1,82 @@
+#!/usr/bin/python2.4
+#
+# Copyright 2008 Google Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+from datetime import datetime
+
+from django.contrib.sessions.backends import base
+from django.core.exceptions import SuspiciousOperation
+
+from appengine_django.sessions.models import Session
+
+
+class SessionStore(base.SessionBase):
+ """A key-based session store for Google App Engine."""
+
+ def load(self):
+ session = self._get_session(self.session_key)
+ if session:
+ try:
+ return self.decode(session.session_data)
+ except SuspiciousOperation:
+ # Create a new session_key for extra security.
+ pass
+ self.session_key = self._get_new_session_key()
+ self._session_cache = {}
+ self.save()
+ # Ensure the user is notified via a new cookie.
+ self.modified = True
+ return {}
+
+ def save(self, must_create=False):
+ if must_create and self.exists(self.session_key):
+ raise base.CreateError
+ session = Session(
+ key_name='k:' + self.session_key,
+ session_data = self.encode(self._session),
+ expire_date = self.get_expiry_date())
+ session.put()
+
+ def exists(self, session_key):
+ return Session.get_by_key_name('k:' + session_key) is not None
+
+ def delete(self, session_key=None):
+ if session_key is None:
+ session_key = self._session_key
+ session = self._get_session(session_key=session_key)
+ if session:
+ session.delete()
+
+ def _get_session(self, session_key):
+ session = Session.get_by_key_name('k:' + session_key)
+ if session:
+ if session.expire_date > datetime.now():
+ return session
+ session.delete()
+ return None
+
+ def create(self):
+ while True:
+ self.session_key = self._get_new_session_key()
+ try:
+ # Save immediately to ensure we have a unique entry in the
+ # database.
+ self.save(must_create=True)
+ except base.CreateError:
+ # Key wasn't unique. Try again.
+ continue
+ self.modified = True
+ self._session_cache = {}
+ return
diff --git a/appengine_django/sessions/backends/db.pyc b/appengine_django/sessions/backends/db.pyc
new file mode 100644
index 0000000..934b2f7
--- /dev/null
+++ b/appengine_django/sessions/backends/db.pyc
Binary files differ