Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

55 lines (49 sloc) 2.171 kb
from import BaseStorage
from import CookieStorage
from import SessionStorage
class FallbackStorage(BaseStorage):
Tries to store all messages in the first backend, storing any unstored
messages in each subsequent backend backend.
storage_classes = (CookieStorage, SessionStorage)
def __init__(self, *args, **kwargs):
super(FallbackStorage, self).__init__(*args, **kwargs)
self.storages = [storage_class(*args, **kwargs)
for storage_class in self.storage_classes]
self._used_storages = set()
def _get(self, *args, **kwargs):
Gets a single list of messages from all storage backends.
all_messages = []
for storage in self.storages:
messages, all_retrieved = storage._get()
# If the backend hasn't been used, no more retrieval is necessary.
if messages is None:
if messages:
# If this storage class contained all the messages, no further
# retrieval is necessary
if all_retrieved:
return all_messages, all_retrieved
def _store(self, messages, response, *args, **kwargs):
Stores the messages, returning any unstored messages after trying all
For each storage backend, any messages not stored are passed on to the
next backend.
for storage in self.storages:
if messages:
messages = storage._store(messages, response,
# Even if there are no more messages, continue iterating to ensure
# storages which contained messages are flushed.
elif storage in self._used_storages:
storage._store([], response)
return messages
Jump to Line
Something went wrong with that request. Please try again.