[Zodb-checkins]
SVN: ZODB/branches/ctheune-blobsupport/src/ZODB/Blobs/
Change names of Blob class methods that may be called when
the blob object is ghosted. We use a convention of _p_blob_whatever.
Chris McDonough
chrism at plope.com
Fri Mar 25 08:27:29 EST 2005
Log message for revision 29680:
Change names of Blob class methods that may be called when the blob object is ghosted. We use a convention of _p_blob_whatever.
Changed:
U ZODB/branches/ctheune-blobsupport/src/ZODB/Blobs/Blob.py
U ZODB/branches/ctheune-blobsupport/src/ZODB/Blobs/tests/transaction.txt
-=-
Modified: ZODB/branches/ctheune-blobsupport/src/ZODB/Blobs/Blob.py
===================================================================
--- ZODB/branches/ctheune-blobsupport/src/ZODB/Blobs/Blob.py 2005-03-25 06:59:37 UTC (rev 29679)
+++ ZODB/branches/ctheune-blobsupport/src/ZODB/Blobs/Blob.py 2005-03-25 13:27:29 UTC (rev 29680)
@@ -101,11 +101,17 @@
def _change(self):
self._p_changed = 1
- def _rc_clear(self):
+ # utility methods which should not cause the object's state to be
+ # loaded if they are called while the object is a ghost. Thus,
+ # they are named with the _p_ convention and only operate against
+ # other _p_ instance attributes. We conventionally name these methods
+ # and attributes with a _p_blob prefix.
+
+ def _p_blob_clear(self):
self._p_blob_readers = 0
self._p_blob_writers = 0
- def _rc_decref(self, mode):
+ def _p_blob_decref(self, mode):
if mode.startswith('r') or mode == 'U':
self._p_blob_readers = max(0, self._p_blob_readers - 1)
elif mode.startswith('w') or mode.startswith('a'):
@@ -113,7 +119,7 @@
else:
raise AssertionError, 'Unknown mode %s' % mode
- def _get_refcounts(self):
+ def _p_blob_refcounts(self):
# used by unit tests
return self._p_blob_readers, self._p_blob_writers
@@ -162,14 +168,14 @@
def commit(self, object, transaction):
if not self.subtransaction:
- self.blob._rc_clear() # clear all blob refcounts
+ self.blob._p_blob_clear() # clear all blob refcounts
filehandle = self.fhref()
if filehandle is not None:
filehandle.close()
def abort(self, object, transaction):
if not self.subtransaction:
- self.blob._rc_clear()
+ self.blob._p_blob_clear()
filehandle = self.fhref()
if filehandle is not None:
filehandle.close()
@@ -214,7 +220,7 @@
def close(self):
# we don't want to decref twice
if not self.close_called:
- self.blob._rc_decref(self.mode)
+ self.blob._p_blob_decref(self.mode)
self.close_called = True
super(BlobFile, self).close()
Modified: ZODB/branches/ctheune-blobsupport/src/ZODB/Blobs/tests/transaction.txt
===================================================================
--- ZODB/branches/ctheune-blobsupport/src/ZODB/Blobs/tests/transaction.txt 2005-03-25 06:59:37 UTC (rev 29679)
+++ ZODB/branches/ctheune-blobsupport/src/ZODB/Blobs/tests/transaction.txt 2005-03-25 13:27:29 UTC (rev 29680)
@@ -43,14 +43,14 @@
>>> connection2 = database.open()
>>> root = connection2.root()
>>> blob2 = root['myblob']
- >>> blob2._get_refcounts()
+ >>> blob2._p_blob_refcounts()
(0, 0)
>>>
>>> b1 = blob2.open("r")
>>> b1.read()
'abc'
>>> # we reach into the implementation here, dont try this at home
- >>> b1.blob._get_refcounts()[0]
+ >>> b1.blob._p_blob_refcounts()[0]
1
Let's make another filehandle for read only to blob2, this should bump
@@ -58,18 +58,18 @@
(same) underlying blob:
>>> b2 = blob2.open("r")
- >>> b2.blob._get_refcounts()
+ >>> b2.blob._p_blob_refcounts()
(2, 0)
- >>> b1.blob._get_refcounts()
+ >>> b1.blob._p_blob_refcounts()
(2, 0)
Let's close the first filehandle we got from the blob, this should decrease
its refcount by one:
>>> b1.close()
- >>> b1.blob._get_refcounts()
+ >>> b1.blob._p_blob_refcounts()
(1, 0)
- >>> b1.blob._get_refcounts()
+ >>> b1.blob._p_blob_refcounts()
(1, 0)
Let's abort this transaction, and ensure that the filehandles that we
@@ -77,9 +77,9 @@
object are cleared.
>>> transaction.abort()
- >>> b1.blob._get_refcounts()
+ >>> b1.blob._p_blob_refcounts()
(0, 0)
- >>> b2.blob._get_refcounts()
+ >>> b2.blob._p_blob_refcounts()
(0, 0)
>>> b2.read()
Traceback (most recent call last):
@@ -88,10 +88,10 @@
If we open a blob for writing, its write refcount should be nonzero:
- >>> blob2._get_refcounts()
+ >>> blob2._p_blob_refcounts()
(0, 0)
>>> b2 = blob2.open('a')
- >>> blob2._get_refcounts()
+ >>> blob2._p_blob_refcounts()
(0, 1)
While we are testing this, we don't need the storage directory and databases
More information about the Zodb-checkins
mailing list