comparison mercurial/pycompat.py @ 31277:86cd1f2cfff5 stable

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.
author Augie Fackler <augie@google.com>
date Tue, 07 Mar 2017 13:24:24 -0500
parents 6a70cf94d1b5
children 295625f1296b
comparison
equal deleted inserted replaced
31139:6b00c3ecd15b 31277:86cd1f2cfff5
67 # 67 #
68 # https://hg.python.org/cpython/file/v3.5.1/Programs/python.c#l55 68 # https://hg.python.org/cpython/file/v3.5.1/Programs/python.c#l55
69 # 69 #
70 # TODO: On Windows, the native argv is wchar_t, so we'll need a different 70 # TODO: On Windows, the native argv is wchar_t, so we'll need a different
71 # workaround to simulate the Python 2 (i.e. ANSI Win32 API) behavior. 71 # workaround to simulate the Python 2 (i.e. ANSI Win32 API) behavior.
72 sysargv = list(map(os.fsencode, sys.argv)) 72 if getattr(sys, 'argv', None) is not None:
73 sysargv = list(map(os.fsencode, sys.argv))
73 74
74 def sysstr(s): 75 def sysstr(s):
75 """Return a keyword str to be passed to Python functions such as 76 """Return a keyword str to be passed to Python functions such as
76 getattr() and str.encode() 77 getattr() and str.encode()
77 78
163 ossep = os.sep 164 ossep = os.sep
164 osaltsep = os.altsep 165 osaltsep = os.altsep
165 stdin = sys.stdin 166 stdin = sys.stdin
166 stdout = sys.stdout 167 stdout = sys.stdout
167 stderr = sys.stderr 168 stderr = sys.stderr
168 sysargv = sys.argv 169 if getattr(sys, 'argv', None) is not None:
170 sysargv = sys.argv
169 sysplatform = sys.platform 171 sysplatform = sys.platform
170 getcwd = os.getcwd 172 getcwd = os.getcwd
171 sysexecutable = sys.executable 173 sysexecutable = sys.executable
172 shlexsplit = shlex.split 174 shlexsplit = shlex.split
173 175