comparison mercurial/windows.py @ 24069:c6666395fdd2

windows: adjust doc string and comments of posixfile() The doc string of osutil.posixfile includes (line 611): "On error, this function may raise either a WindowsError or an IOError." which is most likely correct, but does not fit for this function here anymore, as we do fold WindowsError to IOError here specifically. And this function is now a bit more than just an exception-wrapper, as it has been expanded to additionally sanitize the unloved seek/tell behavior of Windows. (Self-disclosure: This patch is entirely untested at the time of its publication, as I'm currently not using this version myself. I send it in hopes that it will reduce potential future confusion. CC-ing Matt Harbison)
author Adrian Buehlmann <adrian@cadifra.com>
date Fri, 06 Feb 2015 23:40:46 +0100
parents 7956d17431bc
children 7a2194473155
comparison
equal deleted inserted replaced
24068:4e02418b4236 24069:c6666395fdd2
26 unlink = win32.unlink 26 unlink = win32.unlink
27 27
28 umask = 0022 28 umask = 0022
29 _SEEK_END = 2 # os.SEEK_END was introduced in Python 2.5 29 _SEEK_END = 2 # os.SEEK_END was introduced in Python 2.5
30 30
31 # wrap osutil.posixfile to provide friendlier exceptions
32 def posixfile(name, mode='r', buffering=-1): 31 def posixfile(name, mode='r', buffering=-1):
33 try: 32 '''Open a file with even more POSIX-like semantics'''
34 fp = osutil.posixfile(name, mode, buffering) 33 try:
34 fp = osutil.posixfile(name, mode, buffering) # may raise WindowsError
35 35
36 # The position when opening in append mode is implementation defined, so 36 # The position when opening in append mode is implementation defined, so
37 # make it consistent with other platforms, which position at EOF. 37 # make it consistent with other platforms, which position at EOF.
38 if 'a' in mode: 38 if 'a' in mode:
39 fp.seek(0, _SEEK_END) 39 fp.seek(0, _SEEK_END)
40 40
41 return fp 41 return fp
42 except WindowsError, err: 42 except WindowsError, err:
43 # convert to a friendlier exception
43 raise IOError(err.errno, '%s: %s' % (name, err.strerror)) 44 raise IOError(err.errno, '%s: %s' % (name, err.strerror))
44 posixfile.__doc__ = osutil.posixfile.__doc__
45 45
46 class winstdout(object): 46 class winstdout(object):
47 '''stdout on windows misbehaves if sent through a pipe''' 47 '''stdout on windows misbehaves if sent through a pipe'''
48 48
49 def __init__(self, fp): 49 def __init__(self, fp):