[Python-checkins] r53142 - in python/trunk/Lib: dumbdbm.py test/test_dumbdbm.py
andrew.kuchling
python-checkins at python.org
Fri Dec 22 16:16:58 CET 2006
Author: andrew.kuchling
Date: Fri Dec 22 16:16:58 2006
New Revision: 53142
Modified:
python/trunk/Lib/dumbdbm.py
python/trunk/Lib/test/test_dumbdbm.py
Log:
[Bug #802128 continued] Modify mode depending on the process umask.
Is there really no other way to read the umask than to set it?
Hope this works on Windows...
Modified: python/trunk/Lib/dumbdbm.py
==============================================================================
--- python/trunk/Lib/dumbdbm.py (original)
+++ python/trunk/Lib/dumbdbm.py Fri Dec 22 16:16:58 2006
@@ -236,4 +236,15 @@
"""
# flag argument is currently ignored
+
+ # Modify mode depending on the umask
+ try:
+ um = _os.umask(0)
+ _os.umask(um)
+ except AttributeError:
+ pass
+ else:
+ # Turn off any bits that are set in the umask
+ mode = mode & (~um)
+
return _Database(file, mode)
Modified: python/trunk/Lib/test/test_dumbdbm.py
==============================================================================
--- python/trunk/Lib/test/test_dumbdbm.py (original)
+++ python/trunk/Lib/test/test_dumbdbm.py Fri Dec 22 16:16:58 2006
@@ -40,17 +40,21 @@
def test_dumbdbm_creation_mode(self):
# On platforms without chmod, don't do anything.
- if not hasattr(os, 'chmod'):
+ if not (hasattr(os, 'chmod') and hasattr(os, 'umask')):
return
- f = dumbdbm.open(_fname, 'c', 0632)
- f.close()
-
+ try:
+ old_umask = os.umask(0002)
+ f = dumbdbm.open(_fname, 'c', 0637)
+ f.close()
+ finally:
+ os.umask(old_umask)
+
import stat
st = os.stat(_fname + '.dat')
- self.assertEqual(stat.S_IMODE(st.st_mode), 0632)
+ self.assertEqual(stat.S_IMODE(st.st_mode), 0635)
st = os.stat(_fname + '.dir')
- self.assertEqual(stat.S_IMODE(st.st_mode), 0632)
+ self.assertEqual(stat.S_IMODE(st.st_mode), 0635)
def test_close_twice(self):
f = dumbdbm.open(_fname)
More information about the Python-checkins
mailing list