[PATCH] windows: adjust doc string and comments of posixfile()

Adrian Buehlmann adrian at cadifra.com
Fri Feb 6 22:45:47 UTC 2015


# HG changeset patch
# User Adrian Buehlmann <adrian at cadifra.com>
# Date 1423262446 -3600
# Node ID c7cda4e729fa5f93c303ff9e980e26fc47bbf741
# Parent  d1fcff9400c984c521a0af89bdf8eb192824ddd8
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)

diff --git a/mercurial/windows.py b/mercurial/windows.py
--- a/mercurial/windows.py
+++ b/mercurial/windows.py
@@ -28,10 +28,10 @@
 umask = 0022
 _SEEK_END = 2 # os.SEEK_END was introduced in Python 2.5
 
-# wrap osutil.posixfile to provide friendlier exceptions
 def posixfile(name, mode='r', buffering=-1):
+    '''Open a file with even more POSIX-like semantics'''
     try:
-        fp = osutil.posixfile(name, mode, buffering)
+        fp = osutil.posixfile(name, mode, buffering) # may raise WindowsError
 
         # The position when opening in append mode is implementation defined, so
         # make it consistent with other platforms, which position at EOF.
@@ -40,8 +40,8 @@
 
         return fp
     except WindowsError, err:
+        # convert to a friendlier exception
         raise IOError(err.errno, '%s: %s' % (name, err.strerror))
-posixfile.__doc__ = osutil.posixfile.__doc__
 
 class winstdout(object):
     '''stdout on windows misbehaves if sent through a pipe'''


More information about the Mercurial-devel mailing list