Back to index

plone3  3.1.7
Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes | Static Private Attributes
CMFEditions.tests.DummyTools.MemoryStorage Class Reference
Inheritance diagram for CMFEditions.tests.DummyTools.MemoryStorage:
Inheritance graph
[legend]
Collaboration diagram for CMFEditions.tests.DummyTools.MemoryStorage:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def register
def save
def retrieve
def getHistory
def isRegistered
def getModificationDate
def purge
def getId

Static Public Attributes

string id = 'portal_historiesstorage'

Private Member Functions

def _save
def _getHistory
def _getLength

Private Attributes

 _histories

Static Private Attributes

tuple __implements__ = (IStorage, IPurgeSupport)

Detailed Description

Definition at line 440 of file DummyTools.py.


Constructor & Destructor Documentation

Definition at line 446 of file DummyTools.py.

00446 
00447     def __init__(self):
00448         self._histories = {}


Member Function Documentation

def CMFEditions.tests.DummyTools.MemoryStorage._getHistory (   self,
  history_id 
) [private]

Definition at line 562 of file DummyTools.py.

00562 
00563     def _getHistory(self, history_id):
00564         try:
00565             history = self._histories[history_id]
00566         except KeyError:
00567             raise StorageUnregisteredError(
00568                 "Saving or retrieving an unregistered object is not "
00569                 "possible. Register the object with history id '%s' first. "
00570                 % history_id)
00571         return history
00572 #        return HistoryList(history)

Here is the caller graph for this function:

def CMFEditions.tests.DummyTools.MemoryStorage._getLength (   self,
  history_id,
  countPurged = True 
) [private]
Returns the length of the history

Definition at line 573 of file DummyTools.py.

00573 
00574     def _getLength(self, history_id, countPurged=True):
00575         """Returns the length of the history
00576         """
00577         histories = self._histories
00578         history = self._getHistory(history_id)
00579         if countPurged:
00580             return len(history)
00581         
00582         length = 0
00583         for vdata in history:
00584             if not isinstance(vdata.object, Removed):
00585                 length += 1
00586         
00587         return length
00588 

Here is the call graph for this function:

def CMFEditions.tests.DummyTools.MemoryStorage._save (   self,
  history_id,
  object,
  referenced_data = {},
  metadata = None 
) [private]

Definition at line 472 of file DummyTools.py.

00472 
00473     def _save(self, history_id, object, referenced_data={}, metadata=None):
00474         histories = self._histories
00475         cloned_referenced_data = {}
00476 
00477         for key, ref in referenced_data.items():
00478             # a real storage may treat IStreamableReference obj differently
00479             if IStreamableReference.isImplementedBy(ref):
00480                 cloned_referenced_data[key] = deepCopy(ref.getObject())
00481             else:
00482                 cloned_referenced_data[key] = deepCopy(ref)
00483         vdata = StorageVersionData(object=deepCopy(object),
00484                                    referenced_data=cloned_referenced_data,
00485                                    metadata=metadata)
00486         if history_id in histories.keys():
00487             histories[history_id].append(vdata)
00488         else:
00489             histories[history_id] = [vdata]
00490 
00491         return len(histories[history_id]) - 1

Here is the call graph for this function:

Here is the caller graph for this function:

def CMFEditions.tests.DummyTools.MemoryStorage.getHistory (   self,
  history_id,
  preserve = (),
  countPurged = True,
  substitute = True 
)

Definition at line 525 of file DummyTools.py.

00525 
00526                    substitute=True):
00527         history = []
00528         sel = 0
00529         
00530         while True:
00531             try:
00532                 vdata = self.retrieve(history_id, sel, countPurged, substitute)
00533             except StorageRetrieveError:
00534                 break
00535             history.append(vdata)
00536             sel += 1
00537             
00538         return HistoryList(history)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 33 of file DummyTools.py.

00033 
00034     def getId(self):
00035         return self.id

Here is the call graph for this function:

def CMFEditions.tests.DummyTools.MemoryStorage.getModificationDate (   self,
  history_id,
  selector = None,
  countPurged = True,
  substitute = True 
)

Definition at line 543 of file DummyTools.py.

00543 
00544                             countPurged=True, substitute=True):
00545         vdata = self.retrieve(history_id, selector, countPurged, substitute)
00546         return vdata.object.object.modified()

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 539 of file DummyTools.py.

00539 
00540     def isRegistered(self, history_id):
00541         return history_id in self._histories

Here is the call graph for this function:

Here is the caller graph for this function:

def CMFEditions.tests.DummyTools.MemoryStorage.purge (   self,
  history_id,
  selector,
  metadata = {},
  countPurged = True 
)
See ``IPurgeSupport``

Definition at line 547 of file DummyTools.py.

00547 
00548     def purge(self, history_id, selector, metadata={}, countPurged=True):
00549         """See ``IPurgeSupport``
00550         """
00551         histories = self._histories
00552         history = histories[history_id]
00553         vdata = self.retrieve(history_id, selector, countPurged, 
00554                               substitute=False)
00555         selector = history.index(vdata)
00556         if not isinstance(vdata.object, Removed):
00557             # prepare replacement for the deleted object and metadata
00558             removedInfo = Removed("purged", metadata)
00559             
00560             # digging into ZVC internals: remove the stored object
00561             history[selector] = StorageVersionData(removedInfo, None, metadata)

Here is the call graph for this function:

def CMFEditions.tests.DummyTools.MemoryStorage.register (   self,
  history_id,
  object,
  referenced_data = {},
  metadata = None 
)

Definition at line 449 of file DummyTools.py.

00449 
00450     def register(self, history_id, object, referenced_data={}, metadata=None):
00451         histories = self._histories
00452         if history_id not in histories.keys():
00453            return self._save(history_id, object, referenced_data, metadata)

Here is the call graph for this function:

Here is the caller graph for this function:

def CMFEditions.tests.DummyTools.MemoryStorage.retrieve (   self,
  history_id,
  selector = None,
  countPurged = True,
  substitute = True 
)

Definition at line 493 of file DummyTools.py.

00493 
00494                  countPurged=True, substitute=True):
00495         if selector is None:
00496             selector = len(self._getHistory(history_id)) - 1
00497             
00498         if countPurged:
00499             try:
00500                 vdata = self._getHistory(history_id)[selector]
00501             except IndexError:
00502                 raise StorageRetrieveError("Retrieving non existing version %s" 
00503                                            % selector)
00504             
00505             vdata.referenced_data = deepcopy(vdata.referenced_data)
00506             if substitute and isinstance(vdata.object, Removed):
00507                 # delegate retrieving to purge policy if one is available
00508                 # if none is available just return "the removed object"
00509                 policy = getToolByName(self, 'portal_purgepolicy', None)
00510                 if policy is not None:
00511                     vdata = policy.retrieveSubstitute(history_id, selector, vdata)
00512             return vdata
00513         else:
00514             valid = 0
00515             history = self._getHistory(history_id)
00516             for vdata in history:
00517                 if isinstance(vdata.object, Removed):
00518                     continue
00519                 if valid == selector:
00520                     return vdata
00521                 valid += 1
00522             raise StorageRetrieveError("Retrieving non existing version %s" 
00523                                        % selector)

Here is the call graph for this function:

Here is the caller graph for this function:

def CMFEditions.tests.DummyTools.MemoryStorage.save (   self,
  history_id,
  object,
  referenced_data = {},
  metadata = None 
)

Definition at line 454 of file DummyTools.py.

00454 
00455     def save(self, history_id, object, referenced_data={}, metadata=None):
00456         # delegate the decission what to purge to the purge policy tool
00457         # if it exists. If the call returns ``True`` do not save the current
00458         # version.
00459         policy = getToolByName(self, 'portal_purgepolicy', None)
00460         if policy is not None:
00461             if not policy.beforeSaveHook(history_id, metadata):
00462                 return len(self._histories[history_id]) - 1
00463         
00464         if not self._histories.has_key(history_id):
00465             raise StorageUnregisteredError(
00466                 "Saving or retrieving an unregistered object is not "
00467                 "possible. Register the object with history id '%s' first. "
00468                 % history_id)
00469 
00470         return self._save(history_id, object, referenced_data, metadata)
00471 

Here is the call graph for this function:


Member Data Documentation

tuple CMFEditions.tests.DummyTools.MemoryStorage.__implements__ = (IStorage, IPurgeSupport) [static, private]

Definition at line 442 of file DummyTools.py.

Definition at line 447 of file DummyTools.py.

string CMFEditions.tests.DummyTools.MemoryStorage.id = 'portal_historiesstorage' [static]

Definition at line 443 of file DummyTools.py.


The documentation for this class was generated from the following file: