py3: replace "if ispy3" by encoding.strtolocal()
authorYuya Nishihara <yuya@tcha.org>
Sat, 27 Jan 2018 13:09:49 +0900
changeset 35937 4b1c04082cdc
parent 35936 ed3a7300b7b5
child 35938 a2b3b5c5a25a
py3: replace "if ispy3" by encoding.strtolocal()
mercurial/lock.py
mercurial/ui.py
--- a/mercurial/lock.py	Sat Feb 03 00:01:57 2018 -0500
+++ b/mercurial/lock.py	Sat Jan 27 13:09:49 2018 +0900
@@ -30,9 +30,7 @@
     confidence. Typically it's just hostname. On modern linux, we include an
     extra Linux-specific pid namespace identifier.
     """
-    result = socket.gethostname()
-    if pycompat.ispy3:
-        result = result.encode(pycompat.sysstr(encoding.encoding), 'replace')
+    result = encoding.strtolocal(socket.gethostname())
     if pycompat.sysplatform.startswith('linux'):
         try:
             result += '/%x' % os.stat('/proc/self/ns/pid').st_ino
--- a/mercurial/ui.py	Sat Feb 03 00:01:57 2018 -0500
+++ b/mercurial/ui.py	Sat Jan 27 13:09:49 2018 +0900
@@ -1508,11 +1508,7 @@
                                ''.join(exconly))
             else:
                 output = traceback.format_exception(exc[0], exc[1], exc[2])
-                data = r''.join(output)
-                if pycompat.ispy3:
-                    enc = pycompat.sysstr(encoding.encoding)
-                    data = data.encode(enc, errors=r'replace')
-                self.write_err(data)
+                self.write_err(encoding.strtolocal(r''.join(output)))
         return self.tracebackflag or force
 
     def geteditor(self):