Mercurial > public > mercurial-scm > hg
diff mercurial/pure/osutil.py @ 39644:3b421154d2ca
py3: fix str vs bytes in enough places to run `hg version` on Windows
I don't have Visual Studio 2015 at home, but this now works with a handful of
extensions (blackbox, extdiff, patchbomb, phabricator and rebase, but not
evolve):
$ HGMODULEPOLICY=py py -3 ../hg version
Enabling the evolve extension causes the usual "failed to import ..." line, but
then print this before the usual version output:
('commit', '[b'debugancestor', b'debugapplystreamclonebundle', ...,
b'verify', b'version']')
... where the elided part seems to be every command and alias known.
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Thu, 13 Sep 2018 22:07:00 -0400 |
parents | e7aa113b14f7 |
children | 120ecb17242b |
line wrap: on
line diff
--- a/mercurial/pure/osutil.py Thu Sep 13 20:54:53 2018 -0400 +++ b/mercurial/pure/osutil.py Thu Sep 13 22:07:00 2018 -0400 @@ -14,6 +14,7 @@ import stat as statmod from .. import ( + encoding, pycompat, ) @@ -193,7 +194,8 @@ def _raiseioerror(name): err = ctypes.WinError() - raise IOError(err.errno, '%s: %s' % (name, err.strerror)) + raise IOError(err.errno, r'%s: %s' % (encoding.strfromlocal(name), + err.strerror)) class posixfile(object): '''a file object aiming for POSIX-like semantics @@ -207,14 +209,14 @@ remains but cannot be opened again or be recreated under the same name, until all reading processes have closed the file.''' - def __init__(self, name, mode='r', bufsize=-1): - if 'b' in mode: + def __init__(self, name, mode=b'r', bufsize=-1): + if b'b' in mode: flags = _O_BINARY else: flags = _O_TEXT - m0 = mode[0] - if m0 == 'r' and '+' not in mode: + m0 = mode[0:1] + if m0 == b'r' and b'+' not in mode: flags |= _O_RDONLY access = _GENERIC_READ else: @@ -223,15 +225,15 @@ flags |= _O_RDWR access = _GENERIC_READ | _GENERIC_WRITE - if m0 == 'r': + if m0 == b'r': creation = _OPEN_EXISTING - elif m0 == 'w': + elif m0 == b'w': creation = _CREATE_ALWAYS - elif m0 == 'a': + elif m0 == b'a': creation = _OPEN_ALWAYS flags |= _O_APPEND else: - raise ValueError("invalid mode: %s" % mode) + raise ValueError(r"invalid mode: %s" % pycompat.sysstr(mode)) fh = _kernel32.CreateFileA(name, access, _FILE_SHARE_READ | _FILE_SHARE_WRITE | _FILE_SHARE_DELETE,