Mercurial > public > mercurial-scm > hg
comparison mercurial/util_win32.py @ 5840:c67dfc4ecba6
posixfile_nt: set closed early
Exceptions in __init__ may leave us with close undefined in __del__
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Fri, 11 Jan 2008 14:06:05 -0600 |
parents | 55d3e845736a |
children | e90a7a3c28a4 |
comparison
equal
deleted
inserted
replaced
5839:59fba5caa94b | 5840:c67dfc4ecba6 |
---|---|
225 | 225 |
226 # tried to use win32file._open_osfhandle to pass fd to os.fdopen, | 226 # tried to use win32file._open_osfhandle to pass fd to os.fdopen, |
227 # but does not work at all. wrap win32 file api instead. | 227 # but does not work at all. wrap win32 file api instead. |
228 | 228 |
229 def __init__(self, name, mode='rb'): | 229 def __init__(self, name, mode='rb'): |
230 self.closed = False | |
231 self.name = name | |
232 self.mode = mode | |
230 access = 0 | 233 access = 0 |
231 if 'r' in mode or '+' in mode: | 234 if 'r' in mode or '+' in mode: |
232 access |= win32file.GENERIC_READ | 235 access |= win32file.GENERIC_READ |
233 if 'w' in mode or 'a' in mode or '+' in mode: | 236 if 'w' in mode or 'a' in mode or '+' in mode: |
234 access |= win32file.GENERIC_WRITE | 237 access |= win32file.GENERIC_WRITE |
248 creation, | 251 creation, |
249 win32file.FILE_ATTRIBUTE_NORMAL, | 252 win32file.FILE_ATTRIBUTE_NORMAL, |
250 0) | 253 0) |
251 except pywintypes.error, err: | 254 except pywintypes.error, err: |
252 raise WinIOError(err, name) | 255 raise WinIOError(err, name) |
253 self.closed = False | |
254 self.name = name | |
255 self.mode = mode | |
256 | 256 |
257 def __iter__(self): | 257 def __iter__(self): |
258 for line in self.read().splitlines(True): | 258 for line in self.read().splitlines(True): |
259 yield line | 259 yield line |
260 | 260 |