Commit 5112cb90 authored by Christian Theune's avatar Christian Theune

- some coding-style updates

parent 95147b06
...@@ -38,12 +38,14 @@ BLOB_SUFFIX = ".blob" ...@@ -38,12 +38,14 @@ BLOB_SUFFIX = ".blob"
class Blob(Persistent): class Blob(Persistent):
"""A BLOB supports efficient handling of large data within ZODB."""
zope.interface.implements(IBlob) zope.interface.implements(IBlob)
# Binding this to an attribute allows overriding it in the unit tests # Binding this to an attribute allows overriding it in the unit tests
if sys.platform == 'win32': if sys.platform == 'win32':
_os_link = lambda self, src, dst: win32file.CreateHardLink(dst, src, None) _os_link = lambda self, src, dst: win32file.CreateHardLink(dst, src,
None)
else: else:
_os_link = os.link _os_link = os.link
...@@ -92,7 +94,8 @@ class Blob(Persistent): ...@@ -92,7 +94,8 @@ class Blob(Persistent):
if self._p_blob_uncommitted is None: if self._p_blob_uncommitted is None:
# Create a new working copy # Create a new working copy
uncommitted = BlobFile(self._create_uncommitted_file(), mode, self) uncommitted = BlobFile(self._create_uncommitted_file(),
mode, self)
# NOTE: _p_blob data appears by virtue of Connection._setstate # NOTE: _p_blob data appears by virtue of Connection._setstate
utils.cp(file(self._p_blob_data), uncommitted) utils.cp(file(self._p_blob_data), uncommitted)
uncommitted.seek(0) uncommitted.seek(0)
...@@ -153,8 +156,8 @@ class Blob(Persistent): ...@@ -153,8 +156,8 @@ class Blob(Persistent):
if os.path.exists(target): if os.path.exists(target):
os.unlink(target) os.unlink(target)
# If there was a file moved aside, bring it back including the pointer to # If there was a file moved aside, bring it back including the
# the uncommitted file. # pointer to the uncommitted file.
if previous_uncommitted: if previous_uncommitted:
os.rename(target_aside, target) os.rename(target_aside, target)
self._p_blob_uncommitted = target self._p_blob_uncommitted = target
...@@ -179,7 +182,8 @@ class Blob(Persistent): ...@@ -179,7 +182,8 @@ class Blob(Persistent):
return self._p_blob_uncommitted or self._p_blob_data return self._p_blob_uncommitted or self._p_blob_data
def _create_uncommitted_file(self): def _create_uncommitted_file(self):
assert self._p_blob_uncommitted is None, "Uncommitted file already exists." assert self._p_blob_uncommitted is None, (
"Uncommitted file already exists.")
tempdir = os.environ.get('ZODB_BLOB_TEMPDIR', tempfile.gettempdir()) tempdir = os.environ.get('ZODB_BLOB_TEMPDIR', tempfile.gettempdir())
self._p_blob_uncommitted = utils.mktemp(dir=tempdir) self._p_blob_uncommitted = utils.mktemp(dir=tempdir)
return self._p_blob_uncommitted return self._p_blob_uncommitted
...@@ -276,8 +280,8 @@ class BlobDataManager: ...@@ -276,8 +280,8 @@ class BlobDataManager:
def _remove_uncommitted_data(self): def _remove_uncommitted_data(self):
self.blob._p_blob_clear() self.blob._p_blob_clear()
self.fhrefs.map(lambda fhref: fhref.close()) self.fhrefs.map(lambda fhref: fhref.close())
if self.blob._p_blob_uncommitted is not None and \ if (self.blob._p_blob_uncommitted is not None and
os.path.exists(self.blob._p_blob_uncommitted): os.path.exists(self.blob._p_blob_uncommitted)):
os.unlink(self.blob._p_blob_uncommitted) os.unlink(self.blob._p_blob_uncommitted)
self.blob._p_blob_uncommitted = None self.blob._p_blob_uncommitted = None
......
# python package """The ZODB Blob package."""
...@@ -863,8 +863,8 @@ class Connection(ExportImport, object): ...@@ -863,8 +863,8 @@ class Connection(ExportImport, object):
providedBy = getattr(obj, '__providedBy__', None) providedBy = getattr(obj, '__providedBy__', None)
if providedBy is not None and IBlob in providedBy: if providedBy is not None and IBlob in providedBy:
obj._p_blob_uncommitted = None obj._p_blob_uncommitted = None
obj._p_blob_data = \ obj._p_blob_data = self._storage.loadBlob(
self._storage.loadBlob(obj._p_oid, serial, self._version) obj._p_oid, serial, self._version)
def _load_before_or_conflict(self, obj): def _load_before_or_conflict(self, obj):
"""Load non-current state for obj or raise ReadConflictError.""" """Load non-current state for obj or raise ReadConflictError."""
......
...@@ -14,8 +14,8 @@ ...@@ -14,8 +14,8 @@
import struct import struct
from ZODB.FileStorage import FileIterator from ZODB.FileStorage import FileIterator
from ZODB.FileStorage.format \ from ZODB.FileStorage.format import TRANS_HDR, TRANS_HDR_LEN, DATA_HDR, DATA_HDR_LEN
import TRANS_HDR, TRANS_HDR_LEN, DATA_HDR, DATA_HDR_LEN from ZODB.FileStorage.format import DATA_HDR_LEN
from ZODB.TimeStamp import TimeStamp from ZODB.TimeStamp import TimeStamp
from ZODB.utils import u64, get_pickle_metadata from ZODB.utils import u64, get_pickle_metadata
from ZODB.tests.StorageTestBase import zodb_unpickle from ZODB.tests.StorageTestBase import zodb_unpickle
...@@ -24,13 +24,13 @@ def fsdump(path, file=None, with_offset=1): ...@@ -24,13 +24,13 @@ def fsdump(path, file=None, with_offset=1):
iter = FileIterator(path) iter = FileIterator(path)
for i, trans in enumerate(iter): for i, trans in enumerate(iter):
if with_offset: if with_offset:
print >> file, "Trans #%05d tid=%016x time=%s offset=%d" % \ print >> file, ("Trans #%05d tid=%016x time=%s offset=%d" %
(i, u64(trans.tid), TimeStamp(trans.tid), trans._pos) (i, u64(trans.tid), TimeStamp(trans.tid), trans._pos))
else: else:
print >> file, "Trans #%05d tid=%016x time=%s" % \ print >> file, ("Trans #%05d tid=%016x time=%s" %
(i, u64(trans.tid), TimeStamp(trans.tid)) (i, u64(trans.tid), TimeStamp(trans.tid)))
print >> file, " status=%r user=%r description=%r" % \ print >> file, (" status=%r user=%r description=%r" %
(trans.status, trans.user, trans.description) (trans.status, trans.user, trans.description))
for j, rec in enumerate(trans): for j, rec in enumerate(trans):
if rec.data is None: if rec.data is None:
...@@ -53,8 +53,8 @@ def fsdump(path, file=None, with_offset=1): ...@@ -53,8 +53,8 @@ def fsdump(path, file=None, with_offset=1):
else: else:
bp = "" bp = ""
print >> file, " data #%05d oid=%016x%s%s class=%s%s" % \ print >> file, (" data #%05d oid=%016x%s%s class=%s%s" %
(j, u64(rec.oid), version, size, fullclass, bp) (j, u64(rec.oid), version, size, fullclass, bp))
iter.close() iter.close()
def fmt(p64): def fmt(p64):
...@@ -123,8 +123,8 @@ class Dumper: ...@@ -123,8 +123,8 @@ class Dumper:
version = self.file.read(vlen) version = self.file.read(vlen)
print >> self.dest, "version: %r" % version print >> self.dest, "version: %r" % version
print >> self.dest, "non-version data offset: %d" % u64(pnv) print >> self.dest, "non-version data offset: %d" % u64(pnv)
print >> self.dest, \ print >> self.dest, ("previous version data offset: %d" %
"previous version data offset: %d" % u64(sprevdata) u64(sprevdata))
print >> self.dest, "len(data): %d" % dlen print >> self.dest, "len(data): %d" % dlen
self.file.read(dlen) self.file.read(dlen)
if not dlen: if not dlen:
......
...@@ -281,11 +281,11 @@ class PersistentBroken(Broken, persistent.Persistent): ...@@ -281,11 +281,11 @@ class PersistentBroken(Broken, persistent.Persistent):
and persistent broken objects aren't directly picklable: and persistent broken objects aren't directly picklable:
>>> a.__reduce__() >>> a.__reduce__() # doctest: +NORMALIZE_WHITESPACE
Traceback (most recent call last): Traceback (most recent call last):
... ...
BrokenModified: """ \ BrokenModified:
r"""<persistent broken not.there.Atall instance '\x00\x00\x00\x00****'> <persistent broken not.there.Atall instance '\x00\x00\x00\x00****'>
but you can get their state: but you can get their state:
......
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