apply os.fsync() to the GzipFile backup files it creates.
# based on Andrew Kuchling's minigzip.py distributed with the zlib module
-import struct, sys, time
+import os, struct, sys, time
import zlib
import __builtin__
def flush(self):
self.fileobj.flush()
+ def fileno(self):
+ """Invoke the underlying file object's fileno() method.
+
+ This will raise AttributeError if the underlying file object
+ doesn't support fileno().
+ """
+ return self.fileobj.fileno()
+
def isatty(self):
return False
/* See http://www.winimage.com/zLibDll for Windows */
"""
-f = gzip.GzipFile(filename, 'wb') ; f.write(data1 * 50) ; f.close()
+f = gzip.GzipFile(filename, 'wb') ; f.write(data1 * 50)
+# Try flush and fileno.
+f.flush()
+f.fileno()
+if hasattr(os, 'fsync'):
+ os.fsync(f.fileno())
+f.close()
+
+# Try reading.
f = gzip.GzipFile(filename, 'r') ; d = f.read() ; f.close()
verify(d == data1*50)
Library
-------
+- gzip.GzipFile has a new fileno() method, to retrieve the handle of the
+ underlying file object (provided it has a fileno() method). This is
+ needed if you want to use os.fsync() on a GzipFile.
+
- imaplib has two new methods: deleteacl and myrights.
- nntplib has two new methods: description and descriptions. They