py3: create built in exceptions with str type messages in win32.py
I hit an IOError in unlink() in test-pathconflicts-basic.t, that then crashed as
it was handled:
File "mercurial\dispatch.py", line 359, in _runcatch
return _callcatch(ui, _runcatchfunc)
File "mercurial\dispatch.py", line 367, in _callcatch
return scmutil.callcatch(ui, func)
File "mercurial\scmutil.py", line 252, in callcatch
ui.error(_("abort: %s\n") % encoding.strtolocal(inst.strerror))
File "mercurial\encoding.py", line 205, in unitolocal
return tolocal(u.encode('utf-8'))
AttributeError: 'bytes' object has no attribute 'encode'
--- a/mercurial/win32.py Sat Sep 22 12:11:48 2018 -0400
+++ b/mercurial/win32.py Fri Sep 21 21:44:27 2018 -0400
@@ -307,8 +307,8 @@
if code > 0x7fffffff:
code -= 2**32
err = ctypes.WinError(code=code)
- raise OSError(err.errno, '%s: %s' % (name,
- encoding.strtolocal(err.strerror)))
+ raise OSError(err.errno, r'%s: %s' % (encoding.strfromlocal(name),
+ err.strerror))
def _getfileinfo(name):
fh = _kernel32.CreateFileA(name, 0,
@@ -597,7 +597,8 @@
# use EPERM because it is POSIX prescribed value, even though
# unlink(2) on directories returns EISDIR on Linux
raise IOError(errno.EPERM,
- "Unlinking directory not permitted: '%s'" % f)
+ r"Unlinking directory not permitted: '%s'"
+ % encoding.strfromlocal(f))
# POSIX allows to unlink and rename open files. Windows has serious
# problems with doing that:
@@ -625,7 +626,7 @@
if e.errno != errno.EEXIST:
raise
else:
- raise IOError(errno.EEXIST, "No usable temporary filename found")
+ raise IOError(errno.EEXIST, r"No usable temporary filename found")
try:
os.unlink(temp)