Commit 90a976f5 authored by Chris McDonough's avatar Chris McDonough

Change names of Blob class methods that may be called when the blob object is...

Change names of Blob class methods that may be called when the blob object is ghosted.  We use a convention of _p_blob_whatever.
parent a810d770
...@@ -101,11 +101,17 @@ class Blob(Persistent): ...@@ -101,11 +101,17 @@ class Blob(Persistent):
def _change(self): def _change(self):
self._p_changed = 1 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_readers = 0
self._p_blob_writers = 0 self._p_blob_writers = 0
def _rc_decref(self, mode): def _p_blob_decref(self, mode):
if mode.startswith('r') or mode == 'U': if mode.startswith('r') or mode == 'U':
self._p_blob_readers = max(0, self._p_blob_readers - 1) self._p_blob_readers = max(0, self._p_blob_readers - 1)
elif mode.startswith('w') or mode.startswith('a'): elif mode.startswith('w') or mode.startswith('a'):
...@@ -113,7 +119,7 @@ class Blob(Persistent): ...@@ -113,7 +119,7 @@ class Blob(Persistent):
else: else:
raise AssertionError, 'Unknown mode %s' % mode raise AssertionError, 'Unknown mode %s' % mode
def _get_refcounts(self): def _p_blob_refcounts(self):
# used by unit tests # used by unit tests
return self._p_blob_readers, self._p_blob_writers return self._p_blob_readers, self._p_blob_writers
...@@ -162,14 +168,14 @@ class BlobDataManager: ...@@ -162,14 +168,14 @@ class BlobDataManager:
def commit(self, object, transaction): def commit(self, object, transaction):
if not self.subtransaction: if not self.subtransaction:
self.blob._rc_clear() # clear all blob refcounts self.blob._p_blob_clear() # clear all blob refcounts
filehandle = self.fhref() filehandle = self.fhref()
if filehandle is not None: if filehandle is not None:
filehandle.close() filehandle.close()
def abort(self, object, transaction): def abort(self, object, transaction):
if not self.subtransaction: if not self.subtransaction:
self.blob._rc_clear() self.blob._p_blob_clear()
filehandle = self.fhref() filehandle = self.fhref()
if filehandle is not None: if filehandle is not None:
filehandle.close() filehandle.close()
...@@ -214,7 +220,7 @@ class BlobFile(file): ...@@ -214,7 +220,7 @@ class BlobFile(file):
def close(self): def close(self):
# we don't want to decref twice # we don't want to decref twice
if not self.close_called: if not self.close_called:
self.blob._rc_decref(self.mode) self.blob._p_blob_decref(self.mode)
self.close_called = True self.close_called = True
super(BlobFile, self).close() super(BlobFile, self).close()
......
...@@ -43,14 +43,14 @@ resulting filehandle is accomplished via the filehandle's read method: ...@@ -43,14 +43,14 @@ resulting filehandle is accomplished via the filehandle's read method:
>>> connection2 = database.open() >>> connection2 = database.open()
>>> root = connection2.root() >>> root = connection2.root()
>>> blob2 = root['myblob'] >>> blob2 = root['myblob']
>>> blob2._get_refcounts() >>> blob2._p_blob_refcounts()
(0, 0) (0, 0)
>>> >>>
>>> b1 = blob2.open("r") >>> b1 = blob2.open("r")
>>> b1.read() >>> b1.read()
'abc' 'abc'
>>> # we reach into the implementation here, dont try this at home >>> # we reach into the implementation here, dont try this at home
>>> b1.blob._get_refcounts()[0] >>> b1.blob._p_blob_refcounts()[0]
1 1
Let's make another filehandle for read only to blob2, this should bump Let's make another filehandle for read only to blob2, this should bump
...@@ -58,18 +58,18 @@ up its refcount by one, and each file handle has a reference to the ...@@ -58,18 +58,18 @@ up its refcount by one, and each file handle has a reference to the
(same) underlying blob: (same) underlying blob:
>>> b2 = blob2.open("r") >>> b2 = blob2.open("r")
>>> b2.blob._get_refcounts() >>> b2.blob._p_blob_refcounts()
(2, 0) (2, 0)
>>> b1.blob._get_refcounts() >>> b1.blob._p_blob_refcounts()
(2, 0) (2, 0)
Let's close the first filehandle we got from the blob, this should decrease Let's close the first filehandle we got from the blob, this should decrease
its refcount by one: its refcount by one:
>>> b1.close() >>> b1.close()
>>> b1.blob._get_refcounts() >>> b1.blob._p_blob_refcounts()
(1, 0) (1, 0)
>>> b1.blob._get_refcounts() >>> b1.blob._p_blob_refcounts()
(1, 0) (1, 0)
Let's abort this transaction, and ensure that the filehandles that we Let's abort this transaction, and ensure that the filehandles that we
...@@ -77,9 +77,9 @@ opened are now closed and that the filehandle refcounts on the blob ...@@ -77,9 +77,9 @@ opened are now closed and that the filehandle refcounts on the blob
object are cleared. object are cleared.
>>> transaction.abort() >>> transaction.abort()
>>> b1.blob._get_refcounts() >>> b1.blob._p_blob_refcounts()
(0, 0) (0, 0)
>>> b2.blob._get_refcounts() >>> b2.blob._p_blob_refcounts()
(0, 0) (0, 0)
>>> b2.read() >>> b2.read()
Traceback (most recent call last): Traceback (most recent call last):
...@@ -88,10 +88,10 @@ object are cleared. ...@@ -88,10 +88,10 @@ object are cleared.
If we open a blob for writing, its write refcount should be nonzero: If we open a blob for writing, its write refcount should be nonzero:
>>> blob2._get_refcounts() >>> blob2._p_blob_refcounts()
(0, 0) (0, 0)
>>> b2 = blob2.open('a') >>> b2 = blob2.open('a')
>>> blob2._get_refcounts() >>> blob2._p_blob_refcounts()
(0, 1) (0, 1)
While we are testing this, we don't need the storage directory and databases While we are testing this, we don't need the storage directory and databases
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment