# HG changeset patch # User Steve Dower # Date 1441479012 25200 # Sat Sep 05 11:50:12 2015 -0700 # Branch 3.5 # Node ID e69442b850c1cb86464e6183fe6867e737884c1e # Parent 4e329892817c1eed81aafd14e82b8ef23b45a6e6 Issue #25005: Adds arguments to os.startfile and fixes webbrowser. diff --git a/Lib/webbrowser.py b/Lib/webbrowser.py --- a/Lib/webbrowser.py +++ b/Lib/webbrowser.py @@ -499,19 +499,26 @@ class WindowsDefault(BaseBrowser): # Windows Default opening arguments. - cmd = "start" + cmd = "" newwindow = "" newtab = "" def open(self, url, new=0, autoraise=True): # Format the command for optional arguments and add the url. - if new == 1: - self.cmd += " " + self.newwindow - elif new == 2: - self.cmd += " " + self.newtab - self.cmd += " " + url + if self.cmd: + cmd = self.cmd + if new == 1: + args = self.newwindow + " " + url + elif new == 2: + args = self.newtab + " " + url + else: + args = url + else: + cmd = url + args = None + try: - subprocess.call(self.cmd, shell=True) + os.startfile(cmd, "open", args) except OSError: # [Error 22] No application is associated with the specified # file for this operation: '' @@ -525,7 +532,7 @@ class InternetExplorer(WindowsDefault): """Launcher class for Internet Explorer browser""" - cmd = "start iexplore.exe" + cmd = "iexplore.exe" newwindow = "" newtab = "" @@ -533,7 +540,7 @@ class WinChrome(WindowsDefault): """Launcher class for windows specific Google Chrome browser""" - cmd = "start chrome.exe" + cmd = "chrome.exe" newwindow = "-new-window" newtab = "-new-tab" @@ -541,7 +548,7 @@ class WinFirefox(WindowsDefault): """Launcher class for windows specific Firefox browser""" - cmd = "start firefox.exe" + cmd = "firefox.exe" newwindow = "-new-window" newtab = "-new-tab" @@ -549,7 +556,7 @@ class WinOpera(WindowsDefault): """Launcher class for windows specific Opera browser""" - cmd = "start opera" + cmd = "opera" newwindow = "" newtab = "" @@ -557,7 +564,7 @@ class WinSeaMonkey(WindowsDefault): """Launcher class for windows specific SeaMonkey browser""" - cmd = "start seamonkey" + cmd = "seamonkey" newwinow = "" newtab = "" diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -10523,7 +10523,7 @@ #ifdef MS_WINDOWS /* AC 3.5: change to path_t? but that might change exceptions */ PyDoc_STRVAR(win32_startfile__doc__, -"startfile(filepath [, operation])\n\ +"startfile(filepath [, operation [, arguments]])\n\ \n\ Start a file with its associated application.\n\ \n\ @@ -10579,10 +10579,11 @@ PyObject *ofilepath; char *filepath; char *operation = NULL; - wchar_t *wpath, *woperation; + char *arguments = NULL; + wchar_t *wpath, *woperation, *warguments; HINSTANCE rc; - PyObject *unipath, *uoperation = NULL; + PyObject *unipath, *uoperation = NULL, *uarguments = NULL; if(!check_ShellExecute()) { /* If the OS doesn't have ShellExecute, return a @@ -10591,8 +10592,8 @@ "startfile not available on this platform"); } - if (!PyArg_ParseTuple(args, "U|s:startfile", - &unipath, &operation)) { + if (!PyArg_ParseTuple(args, "U|sz:startfile", + &unipath, &operation, &arguments)) { PyErr_Clear(); goto normal; } @@ -10607,6 +10608,16 @@ } } + if (arguments) { + uarguments = PyUnicode_DecodeASCII(arguments, + strlen(arguments), NULL); + if (!uarguments) { + PyErr_Clear(); + arguments = NULL; + goto normal; + } + } + wpath = PyUnicode_AsUnicode(unipath); if (wpath == NULL) goto normal; @@ -10617,13 +10628,21 @@ } else woperation = NULL; + if (uarguments) { + warguments = PyUnicode_AsUnicode(uarguments); + if (warguments == NULL) + goto normal; + } + else + warguments = NULL; Py_BEGIN_ALLOW_THREADS rc = Py_ShellExecuteW((HWND)0, woperation, wpath, - NULL, NULL, SW_SHOWNORMAL); + warguments, NULL, SW_SHOWNORMAL); Py_END_ALLOW_THREADS Py_XDECREF(uoperation); + Py_XDECREF(uarguments); if (rc <= (HINSTANCE)32) { win32_error_object("startfile", unipath); return NULL;