Patchwork windows: adjust doc string and comments of posixfile()

login
register
mail settings
Submitter Adrian Buehlmann
Date Feb. 6, 2015, 10:45 p.m.
Message ID <c7cda4e729fa5f93c303.1423262747@kork>
Download mbox | patch
Permalink /patch/7725/
State Accepted
Commit c6666395fdd2e72c06d1f4c5fd5966cff339f388
Headers show

Comments

Adrian Buehlmann - Feb. 6, 2015, 10:45 p.m.
# HG changeset patch
# User Adrian Buehlmann <adrian@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)
Matt Mackall - Feb. 6, 2015, 10:57 p.m.
On Fri, 2015-02-06 at 23:45 +0100, Adrian Buehlmann wrote:
> # HG changeset patch
> # User Adrian Buehlmann <adrian@cadifra.com>
> # Date 1423262446 -3600
> # Node ID c7cda4e729fa5f93c303ff9e980e26fc47bbf741
> # Parent  d1fcff9400c984c521a0af89bdf8eb192824ddd8
> windows: adjust doc string and comments of posixfile()

Queued for default, thanks.

Patch

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'''