Patchwork [stable] pycompat: verify sys.argv exists before forwarding it (issue5493)

login
register
mail settings
Submitter Augie Fackler
Date March 7, 2017, 6:32 p.m.
Message ID <b1e649de4c2761334442.1488911561@augie-macbookair2.roam.corp.google.com>
Download mbox | patch
Permalink /patch/18967/
State Accepted
Headers show

Comments

Augie Fackler - March 7, 2017, 6:32 p.m.
# HG changeset patch
# User Augie Fackler <augie@google.com>
# Date 1488911064 18000
#      Tue Mar 07 13:24:24 2017 -0500
# Branch stable
# Node ID b1e649de4c276133444234f33638cde393cbbfc8
# Parent  6b00c3ecd15b26587de8cca6fab811069cba3b2f
pycompat: verify sys.argv exists before forwarding it (issue5493)

ISAPI_WSGI doesn't set up sys.argv, so we have to look for the
attribute before assuming it exists.
Yuya Nishihara - March 9, 2017, 5:29 a.m.
On Tue, 07 Mar 2017 13:32:41 -0500, Augie Fackler wrote:
> # HG changeset patch
> # User Augie Fackler <augie@google.com>
> # Date 1488911064 18000
> #      Tue Mar 07 13:24:24 2017 -0500
> # Branch stable
> # Node ID b1e649de4c276133444234f33638cde393cbbfc8
> # Parent  6b00c3ecd15b26587de8cca6fab811069cba3b2f
> pycompat: verify sys.argv exists before forwarding it (issue5493)
> 
> ISAPI_WSGI doesn't set up sys.argv, so we have to look for the
> attribute before assuming it exists.

Queued this, thanks.

Patch

diff --git a/mercurial/pycompat.py b/mercurial/pycompat.py
--- a/mercurial/pycompat.py
+++ b/mercurial/pycompat.py
@@ -69,7 +69,8 @@  if ispy3:
     #
     # TODO: On Windows, the native argv is wchar_t, so we'll need a different
     # workaround to simulate the Python 2 (i.e. ANSI Win32 API) behavior.
-    sysargv = list(map(os.fsencode, sys.argv))
+    if getattr(sys, 'argv', None) is not None:
+        sysargv = list(map(os.fsencode, sys.argv))
 
     def sysstr(s):
         """Return a keyword str to be passed to Python functions such as
@@ -165,7 +166,8 @@  else:
     stdin = sys.stdin
     stdout = sys.stdout
     stderr = sys.stderr
-    sysargv = sys.argv
+    if getattr(sys, 'argv', None) is not None:
+        sysargv = sys.argv
     sysplatform = sys.platform
     getcwd = os.getcwd
     sysexecutable = sys.executable