[Checkins] SVN: relstorage/trunk/relstorage/adapters/mover.py Simplify buffered download loops with iter(func, sentinel).
Martijn Pieters
mj at zopatista.com
Thu Jun 16 05:39:50 EDT 2011
Log message for revision 121958:
Simplify buffered download loops with iter(func, sentinel).
Changed:
U relstorage/trunk/relstorage/adapters/mover.py
-=-
Modified: relstorage/trunk/relstorage/adapters/mover.py
===================================================================
--- relstorage/trunk/relstorage/adapters/mover.py 2011-06-16 07:11:26 UTC (rev 121957)
+++ relstorage/trunk/relstorage/adapters/mover.py 2011-06-16 09:39:49 UTC (rev 121958)
@@ -1026,13 +1026,10 @@
if f is None:
f = open(filename, 'ab') # Append, chunk 0 was an export
read_chunk_size = self.blob_chunk_size
- while True:
- read_chunk = blob.read(read_chunk_size)
- if read_chunk:
- f.write(read_chunk)
- bytes += len(read_chunk)
- else:
- break
+ reader = iter(lambda: blob.read(read_chunk_size), '')
+ for read_chunk in reader:
+ f.write(read_chunk)
+ bytes += len(read_chunk)
except:
if f is not None:
f.close()
@@ -1116,19 +1113,16 @@
1.0 * self.blob_chunk_size / blob.getchunksize()), 1) *
blob.getchunksize())
offset = 1 # Oracle still uses 1-based indexing.
- while True:
- read_chunk = blob.read(offset, read_chunk_size)
- if read_chunk:
- f.write(read_chunk)
- bytes += len(read_chunk)
- offset += len(read_chunk)
- if offset > maxsize:
- # We have already read the maximum we can store
- # so we can assume we are done. If we do not break
- # off here, cx_Oracle will throw an overflow
- # exception anyway.
- break
- else:
+ reader = iter(lambda: blob.read(offset, read_chunk_size), '')
+ for read_chunk in reader:
+ f.write(read_chunk)
+ bytes += len(read_chunk)
+ offset += len(read_chunk)
+ if offset > maxsize:
+ # We have already read the maximum we can store
+ # so we can assume we are done. If we do not break
+ # off here, cx_Oracle will throw an overflow
+ # exception anyway.
break
except:
if f is not None:
More information about the checkins
mailing list