Skip to content

Commit

Permalink
Use with open() in more places
Browse files Browse the repository at this point in the history
  • Loading branch information
mgedmin committed Feb 28, 2013
1 parent 08a9305 commit 5bc41c9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 22 deletions.
39 changes: 19 additions & 20 deletions src/ZODB/scripts/fstest.py
Expand Up @@ -76,26 +76,25 @@ def U64(v):
return l

def check(path):
file = open(path, 'rb')

file.seek(0, 2)
file_size = file.tell()
if file_size == 0:
raise FormatError("empty file")
file.seek(0)
if file.read(4) != packed_version:
raise FormatError("invalid file header")

pos = 4
tid = b'\000' * 8 # lowest possible tid to start
i = 0
while pos:
_pos = pos
pos, tid = check_trec(path, file, pos, tid, file_size)
if tid is not None:
chatter("%10d: transaction tid %s #%d \n" %
(_pos, hexify(tid), i))
i = i + 1
with open(path, 'rb') as file:
file.seek(0, 2)
file_size = file.tell()
if file_size == 0:
raise FormatError("empty file")
file.seek(0)
if file.read(4) != packed_version:
raise FormatError("invalid file header")

pos = 4
tid = b'\000' * 8 # lowest possible tid to start
i = 0
while pos:
_pos = pos
pos, tid = check_trec(path, file, pos, tid, file_size)
if tid is not None:
chatter("%10d: transaction tid %s #%d \n" %
(_pos, hexify(tid), i))
i = i + 1


def check_trec(path, file, pos, ltid, file_size):
Expand Down
4 changes: 2 additions & 2 deletions src/ZODB/tests/blob_layout.txt
Expand Up @@ -141,7 +141,7 @@ it will leave a marker with the choosen layout if no marker exists yet:
>>> fsh.layout_name
'bushy'
>>> fsh.create()
>>> open(os.path.join(blobs, LAYOUT_MARKER), 'rb').read()
>>> with open(os.path.join(blobs, LAYOUT_MARKER), 'rb') as fp: fp.read()
'bushy'

If the FSH finds a marker, then it verifies whether its content matches the
Expand Down Expand Up @@ -171,7 +171,7 @@ the marker will be used in the future:
>>> blob_storage = BlobStorage(blobs, base_storage)
>>> blob_storage.fshelper.layout_name
'lawn'
>>> open(os.path.join(blobs, LAYOUT_MARKER), 'rb').read()
>>> with open(os.path.join(blobs, LAYOUT_MARKER), 'rb') as fp: fp.read()
'lawn'
>>> blob_storage = BlobStorage('blobs', base_storage, layout='bushy')
... # doctest: +ELLIPSIS
Expand Down

0 comments on commit 5bc41c9

Please sign in to comment.