Index: Lib/os.py =================================================================== --- Lib/os.py (revision 64492) +++ Lib/os.py (working copy) @@ -758,3 +758,37 @@ bytes += read(_urandomfd, n - len(bytes)) close(_urandomfd) return bytes + +if not _exists("startfile"): + def startfile(filepath, operation = ""): + """startfile(filepath [, operation]) + +Start a file with its associated application.""" + if sys.platform == 'darwin': + command = ['open',] + def raise_error(code): + # XXX + # need implemented + raise OSError + else: + command = ['xdg-open',] + def raise_error(code): + err = { + 1: errno.EINVAL, + 2: errno.ENOENT, + 3: errno.ENOEXEC, + # XXX + 4: errno.ENOEXEC, + 5: errno.EACCES, + 6: errno.EACCES, + }[code] + raise OSError(err, strerror(err)) + if operation: + command.append(operation) + command.append(filepath) + import subprocess + retcode = subprocess.call(command) + if retcode: + raise_error(retcode) + + __all__.append("startfile")