]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Added a new fileno() method. ZODB's repozo.py wants this so it can
authorTim Peters <tim.peters@gmail.com>
Tue, 27 Jul 2004 21:02:02 +0000 (21:02 +0000)
committerTim Peters <tim.peters@gmail.com>
Tue, 27 Jul 2004 21:02:02 +0000 (21:02 +0000)
apply os.fsync() to the GzipFile backup files it creates.

Lib/gzip.py
Lib/test/test_gzip.py
Misc/NEWS

index d51b7dbe8dc736e2971128b1c20ee3114cda42ba..9cab9952a2372d8934c4d0b86af1ef53b389a551 100644 (file)
@@ -5,7 +5,7 @@ but random access is not allowed."""
 
 # 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__
 
@@ -334,6 +334,14 @@ class GzipFile:
     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
 
index bb4ed492b6f12fb70c43e3495542c8befa65493f..81a4865b217edc21236eddafdf6af14af65b4e88 100644 (file)
@@ -16,8 +16,16 @@ data2 = """/* zlibmodule.c -- gzip-compatible data compression */
 /* 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)
 
index 289754dfc340496c6469e43dae5ce2be84a4af54..0fb2559228df18ad4f6d2e91ce8d10016469c342 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -46,6 +46,10 @@ Extension modules
 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