use with..as for file reading/writing, as we don't need 2.4 compat anyway right?
This commit is contained in:
		
							parent
							
								
									0938afb882
								
							
						
					
					
						commit
						2095f3c899
					
				|  | @ -24,6 +24,7 @@ Handles HUD configuration files. | ||||||
| ######################################################################## | ######################################################################## | ||||||
| 
 | 
 | ||||||
| #    Standard Library modules | #    Standard Library modules | ||||||
|  | from __future__ import with_statement | ||||||
| import os | import os | ||||||
| import sys | import sys | ||||||
| import inspect | import inspect | ||||||
|  | @ -444,12 +445,11 @@ class Config: | ||||||
| 
 | 
 | ||||||
|     def read_default_conf(self, file): |     def read_default_conf(self, file): | ||||||
|         parms = {} |         parms = {} | ||||||
|         fh = open(file, "r") |         with open(file, "r") as fh: | ||||||
|             for line in fh: |             for line in fh: | ||||||
|                 line = string.strip(line) |                 line = string.strip(line) | ||||||
|                 (key, value) = line.split('=') |                 (key, value) = line.split('=') | ||||||
|                 parms[key] = value |                 parms[key] = value | ||||||
|         fh.close |  | ||||||
|         return parms |         return parms | ||||||
|                  |                  | ||||||
|     def find_example_config(self): |     def find_example_config(self): | ||||||
|  | @ -498,14 +498,12 @@ class Config: | ||||||
| 
 | 
 | ||||||
|     def save(self, file = None): |     def save(self, file = None): | ||||||
|         if file != None: |         if file != None: | ||||||
|             f = open(file, 'w') |             with open(file, 'w') as f: | ||||||
|                 self.doc.writexml(f) |                 self.doc.writexml(f) | ||||||
|             f.close() |  | ||||||
|         else: |         else: | ||||||
|             shutil.move(self.file, self.file+".backup") |             shutil.move(self.file, self.file+".backup") | ||||||
|             f = open(self.file, 'w') |             with open(self.file, 'w'): | ||||||
|                 self.doc.writexml(f) |                 self.doc.writexml(f) | ||||||
|             f.close |  | ||||||
| 
 | 
 | ||||||
|     def edit_layout(self, site_name, max, width = None, height = None, |     def edit_layout(self, site_name, max, width = None, height = None, | ||||||
|                     fav_seat = None, locations = None): |                     fav_seat = None, locations = None): | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user