mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 05:31:20 +00:00 
			
		
		
		
	[Bug #802128] Make the mode argument of dumbdbm actually work the way it's
described, and add a test for it. 2.5 bugfix candidate, maybe; arguably this patch changes the API of dumbdbm and shouldn't be added in a point-release.
This commit is contained in:
		
							parent
							
								
									b29069d6b6
								
							
						
					
					
						commit
						dc26758ffe
					
				
					 2 changed files with 23 additions and 3 deletions
				
			
		|  | @ -68,7 +68,8 @@ def __init__(self, filebasename, mode): | |||
|         try: | ||||
|             f = _open(self._datfile, 'r') | ||||
|         except IOError: | ||||
|             f = _open(self._datfile, 'w', self._mode) | ||||
|             f = _open(self._datfile, 'w') | ||||
|             self._chmod(self._datfile) | ||||
|         f.close() | ||||
|         self._update() | ||||
| 
 | ||||
|  | @ -106,7 +107,8 @@ def _commit(self): | |||
|         except self._os.error: | ||||
|             pass | ||||
| 
 | ||||
|         f = self._open(self._dirfile, 'w', self._mode) | ||||
|         f = self._open(self._dirfile, 'w') | ||||
|         self._chmod(self._dirfile) | ||||
|         for key, pos_and_siz_pair in self._index.iteritems(): | ||||
|             f.write("%r, %r\n" % (key, pos_and_siz_pair)) | ||||
|         f.close() | ||||
|  | @ -152,7 +154,8 @@ def _setval(self, pos, val): | |||
|     # the in-memory index dict, and append one to the directory file. | ||||
|     def _addkey(self, key, pos_and_siz_pair): | ||||
|         self._index[key] = pos_and_siz_pair | ||||
|         f = _open(self._dirfile, 'a', self._mode) | ||||
|         f = _open(self._dirfile, 'a') | ||||
|         self._chmod(self._dirfile) | ||||
|         f.write("%r, %r\n" % (key, pos_and_siz_pair)) | ||||
|         f.close() | ||||
| 
 | ||||
|  | @ -214,6 +217,9 @@ def close(self): | |||
| 
 | ||||
|     __del__ = close | ||||
| 
 | ||||
|     def _chmod (self, file): | ||||
|         if hasattr(self._os, 'chmod'): | ||||
|             self._os.chmod(file, self._mode) | ||||
| 
 | ||||
| 
 | ||||
| def open(file, flag=None, mode=0666): | ||||
|  |  | |||
|  | @ -38,6 +38,20 @@ def test_dumbdbm_creation(self): | |||
|         self.read_helper(f) | ||||
|         f.close() | ||||
| 
 | ||||
|     def test_dumbdbm_creation_mode(self): | ||||
|         # On platforms without chmod, don't do anything. | ||||
|         if not hasattr(os, 'chmod'): | ||||
|             return | ||||
| 
 | ||||
|         f = dumbdbm.open(_fname, 'c', 0632) | ||||
|         f.close() | ||||
| 
 | ||||
|         import stat | ||||
|         st = os.stat(_fname + '.dat') | ||||
|         self.assertEqual(stat.S_IMODE(st.st_mode), 0632) | ||||
|         st = os.stat(_fname + '.dir') | ||||
|         self.assertEqual(stat.S_IMODE(st.st_mode), 0632) | ||||
|          | ||||
|     def test_close_twice(self): | ||||
|         f = dumbdbm.open(_fname) | ||||
|         f['a'] = 'b' | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Andrew M. Kuchling
						Andrew M. Kuchling