changeset 36566:ed96d1116302

tests: help dummysmtpd work on python 3 Differential Revision: https://phab.mercurial-scm.org/D2542
author Augie Fackler <augie@google.com>
date Thu, 01 Mar 2018 23:59:44 -0500
parents 9805c906aaad
children 19ec5da944d5
files tests/dummysmtpd.py
diffstat 1 files changed, 18 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/tests/dummysmtpd.py	Thu Mar 01 23:58:04 2018 -0500
+++ b/tests/dummysmtpd.py	Thu Mar 01 23:59:44 2018 -0500
@@ -12,6 +12,7 @@
 import traceback
 
 from mercurial import (
+    pycompat,
     server,
     sslutil,
     ui as uimod,
@@ -63,6 +64,19 @@
     except KeyboardInterrupt:
         pass
 
+def _encodestrsonly(v):
+    if isinstance(v, type(u'')):
+        return v.encode('ascii')
+    return v
+
+def bytesvars(obj):
+    unidict = vars(obj)
+    bd = {k.encode('ascii'): _encodestrsonly(v) for k, v in unidict.items()}
+    if bd[b'daemon_postexec'] is not None:
+        bd[b'daemon_postexec'] = [
+            _encodestrsonly(v) for v in bd[b'daemon_postexec']]
+    return bd
+
 def main():
     op = optparse.OptionParser()
     op.add_option('-d', '--daemon', action='store_true')
@@ -85,8 +99,10 @@
             dummysmtpsecureserver(addr, opts.certificate)
         log('listening at %s:%d\n' % addr)
 
-    server.runservice(vars(opts), initfn=init, runfn=run,
-                      runargs=[sys.executable, __file__] + sys.argv[1:])
+    server.runservice(
+        bytesvars(opts), initfn=init, runfn=run,
+        runargs=[pycompat.sysexecutable,
+                 pycompat.fsencode(__file__)] + pycompat.sysargv[1:])
 
 if __name__ == '__main__':
     main()