Patchwork [1,of,5] py3: remove use of str() in hgwebdir

login
register
mail settings
Submitter Yuya Nishihara
Date Sept. 27, 2017, 12:34 p.m.
Message ID <b27593faa8b3d4ddcf71.1506515678@mimosa>
Download mbox | patch
Permalink /patch/24180/
State Accepted
Headers show

Comments

Yuya Nishihara - Sept. 27, 2017, 12:34 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1506506672 -32400
#      Wed Sep 27 19:04:32 2017 +0900
# Node ID b27593faa8b3d4ddcf71dcb323ae8189691929df
# Parent  bf17b694881c47015c02f006a788b469c399f3eb
py3: remove use of str() in hgwebdir

'%d' can't be used here since port may be either integer or byte string.

Patch

diff --git a/mercurial/hgweb/hgwebdir_mod.py b/mercurial/hgweb/hgwebdir_mod.py
--- a/mercurial/hgweb/hgwebdir_mod.py
+++ b/mercurial/hgweb/hgwebdir_mod.py
@@ -34,6 +34,7 @@  from .. import (
     error,
     hg,
     profiling,
+    pycompat,
     scmutil,
     templater,
     ui as uimod,
@@ -106,7 +107,7 @@  def geturlcgivars(baseurl, port):
     if not path.startswith('/'):
         path = '/' + path
 
-    return name, str(port), path
+    return name, pycompat.bytestr(port), path
 
 class hgwebdir(object):
     """HTTP server for multiple repositories.
@@ -293,7 +294,7 @@  class hgwebdir(object):
                         msg = encoding.strtolocal(inst.strerror)
                         raise ErrorResponse(HTTP_SERVER_ERROR, msg)
                     except error.RepoError as inst:
-                        raise ErrorResponse(HTTP_SERVER_ERROR, str(inst))
+                        raise ErrorResponse(HTTP_SERVER_ERROR, bytes(inst))
 
             # browse subdirectories
             subdir = virtual + '/'
diff --git a/tests/test-doctest.py b/tests/test-doctest.py
--- a/tests/test-doctest.py
+++ b/tests/test-doctest.py
@@ -53,7 +53,7 @@  testmod('mercurial.dispatch')
 testmod('mercurial.encoding')
 testmod('mercurial.formatter')
 testmod('mercurial.hg')
-testmod('mercurial.hgweb.hgwebdir_mod', py3=False)  # py3: repr(bytes) ?
+testmod('mercurial.hgweb.hgwebdir_mod')
 testmod('mercurial.match')
 testmod('mercurial.mdiff')
 testmod('mercurial.minirst')