Commit 9e1edebc authored by Christian Theune's avatar Christian Theune

- some coding-style updates

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