/
usr
/
lib64
/
python3.6
/
/usr/lib64/python3.6
mkdir
upload
Name
Size
Mode
Actions
asyncio/
-
0755
rm
collections/
-
0755
rm
concurrent/
-
0755
rm
config-3.6m-x86_64-linux-gnu/
-
0755
rm
ctypes/
-
0755
rm
curses/
-
0755
rm
dbm/
-
0755
rm
distutils/
-
0755
rm
email/
-
0755
rm
encodings/
-
0755
rm
ensurepip/
-
0755
rm
html/
-
0755
rm
http/
-
0755
rm
importlib/
-
0755
rm
json/
-
0755
rm
lib-dynload/
-
0755
rm
lib2to3/
-
0755
rm
logging/
-
0755
rm
multiprocessing/
-
0755
rm
pydoc_data/
-
0755
rm
site-packages/
-
0755
rm
sqlite3/
-
0755
rm
test/
-
0755
rm
unittest/
-
0755
rm
urllib/
-
0755
rm
venv/
-
0755
rm
wsgiref/
-
0755
rm
xml/
-
0755
rm
xmlrpc/
-
0755
rm
__pycache__/
-
0755
rm
abc.py
8727
0644
edit
dl
rm
aifc.py
32454
0644
edit
dl
rm
antigravity.py
477
0644
edit
dl
rm
argparse.py
90372
0644
edit
dl
rm
ast.py
12166
0644
edit
dl
rm
asynchat.py
11328
0644
edit
dl
rm
asyncore.py
20159
0644
edit
dl
rm
base64.py
20388
0755
edit
dl
rm
bdb.py
23556
0644
edit
dl
rm
binhex.py
13954
0644
edit
dl
rm
bisect.py
2595
0644
edit
dl
rm
bz2.py
12478
0644
edit
dl
rm
calendar.py
23213
0644
edit
dl
rm
cgi.py
37219
0755
edit
dl
rm
cgitb.py
12018
0644
edit
dl
rm
chunk.py
5425
0644
edit
dl
rm
cmd.py
14860
0644
edit
dl
rm
code.py
10614
0644
edit
dl
rm
codecs.py
36276
0644
edit
dl
rm
codeop.py
5994
0644
edit
dl
rm
colorsys.py
4064
0644
edit
dl
rm
compileall.py
12125
0644
edit
dl
rm
configparser.py
53592
0644
edit
dl
rm
contextlib.py
13162
0644
edit
dl
rm
copy.py
8815
0644
edit
dl
rm
copyreg.py
7007
0644
edit
dl
rm
cProfile.py
5380
0755
edit
dl
rm
crypt.py
1864
0644
edit
dl
rm
csv.py
16180
0644
edit
dl
rm
datetime.py
82034
0644
edit
dl
rm
decimal.py
320
0644
edit
dl
rm
difflib.py
84377
0644
edit
dl
rm
dis.py
18132
0644
edit
dl
rm
doctest.py
104391
0644
edit
dl
rm
dummy_threading.py
2815
0644
edit
dl
rm
enum.py
33606
0644
edit
dl
rm
filecmp.py
9830
0644
edit
dl
rm
fileinput.py
14471
0644
edit
dl
rm
fnmatch.py
3166
0644
edit
dl
rm
formatter.py
15143
0644
edit
dl
rm
fractions.py
23639
0644
edit
dl
rm
ftplib.py
35617
0644
edit
dl
rm
functools.py
31346
0644
edit
dl
rm
genericpath.py
5028
0644
edit
dl
rm
getopt.py
7489
0644
edit
dl
rm
getpass.py
5994
0644
edit
dl
rm
gettext.py
21530
0644
edit
dl
rm
glob.py
5638
0644
edit
dl
rm
gzip.py
20334
0644
edit
dl
rm
hashlib.py
8799
0644
edit
dl
rm
heapq.py
22929
0644
edit
dl
rm
hmac.py
6381
0644
edit
dl
rm
imaplib.py
53464
0644
edit
dl
rm
imghdr.py
3795
0644
edit
dl
rm
imp.py
10669
0644
edit
dl
rm
inspect.py
116958
0644
edit
dl
rm
io.py
3517
0644
edit
dl
rm
ipaddress.py
77818
0644
edit
dl
rm
keyword.py
2219
0755
edit
dl
rm
linecache.py
5312
0644
edit
dl
rm
locale.py
77300
0644
edit
dl
rm
lzma.py
12983
0644
edit
dl
rm
macpath.py
5971
0644
edit
dl
rm
macurl2path.py
2732
0644
edit
dl
rm
mailbox.py
78624
0644
edit
dl
rm
mailcap.py
9067
0644
edit
dl
rm
mimetypes.py
21042
0644
edit
dl
rm
modulefinder.py
23027
0644
edit
dl
rm
netrc.py
5684
0644
edit
dl
rm
nntplib.py
43078
0644
edit
dl
rm
ntpath.py
23094
0644
edit
dl
rm
nturl2path.py
2444
0644
edit
dl
rm
numbers.py
10243
0644
edit
dl
rm
opcode.py
5822
0644
edit
dl
rm
operator.py
10863
0644
edit
dl
rm
optparse.py
60371
0644
edit
dl
rm
os.py
37526
0644
edit
dl
rm
pathlib.py
46238
0644
edit
dl
rm
pdb.py
61320
0755
edit
dl
rm
pickle.py
55691
0644
edit
dl
rm
pickletools.py
91775
0644
edit
dl
rm
pipes.py
8916
0644
edit
dl
rm
pkgutil.py
21315
0644
edit
dl
rm
platform.py
47214
0755
edit
dl
rm
plistlib.py
32291
0644
edit
dl
rm
poplib.py
15087
0644
edit
dl
rm
posixpath.py
16324
0644
edit
dl
rm
pprint.py
20860
0644
edit
dl
rm
profile.py
22029
0755
edit
dl
rm
pstats.py
26564
0644
edit
dl
rm
pty.py
4763
0644
edit
dl
rm
pyclbr.py
13558
0644
edit
dl
rm
pydoc.py
103501
0644
edit
dl
rm
py_compile.py
7181
0644
edit
dl
rm
queue.py
8780
0644
edit
dl
rm
quopri.py
7262
0755
edit
dl
rm
random.py
27442
0644
edit
dl
rm
re.py
15552
0644
edit
dl
rm
reprlib.py
5336
0644
edit
dl
rm
rlcompleter.py
7097
0644
edit
dl
rm
runpy.py
11959
0644
edit
dl
rm
sched.py
6511
0644
edit
dl
rm
secrets.py
2038
0644
edit
dl
rm
selectors.py
19438
0644
edit
dl
rm
shelve.py
8515
0644
edit
dl
rm
shlex.py
12956
0644
edit
dl
rm
shutil.py
40829
0644
edit
dl
rm
signal.py
2123
0644
edit
dl
rm
site.py
21268
0644
edit
dl
rm
smtpd.py
34719
0755
edit
dl
rm
smtplib.py
44218
0755
edit
dl
rm
sndhdr.py
7088
0644
edit
dl
rm
socket.py
27443
0644
edit
dl
rm
socketserver.py
27010
0644
edit
dl
rm
sre_compile.py
19338
0644
edit
dl
rm
sre_constants.py
6821
0644
edit
dl
rm
sre_parse.py
36536
0644
edit
dl
rm
ssl.py
44509
0644
edit
dl
rm
stat.py
5038
0644
edit
dl
rm
statistics.py
20673
0644
edit
dl
rm
string.py
11795
0644
edit
dl
rm
stringprep.py
12917
0644
edit
dl
rm
struct.py
257
0644
edit
dl
rm
subprocess.py
62339
0644
edit
dl
rm
sunau.py
18095
0644
edit
dl
rm
symbol.py
2119
0755
edit
dl
rm
symtable.py
7277
0644
edit
dl
rm
sysconfig.py
24876
0644
edit
dl
rm
tabnanny.py
11411
0755
edit
dl
rm
tarfile.py
111776
0755
edit
dl
rm
telnetlib.py
23136
0644
edit
dl
rm
tempfile.py
28066
0644
edit
dl
rm
textwrap.py
19558
0644
edit
dl
rm
this.py
1003
0644
edit
dl
rm
threading.py
50136
0644
edit
dl
rm
timeit.py
13342
0755
edit
dl
rm
token.py
3075
0644
edit
dl
rm
tokenize.py
29496
0644
edit
dl
rm
trace.py
28733
0755
edit
dl
rm
traceback.py
23458
0644
edit
dl
rm
tracemalloc.py
16658
0644
edit
dl
rm
tty.py
879
0644
edit
dl
rm
types.py
8870
0644
edit
dl
rm
typing.py
80274
0644
edit
dl
rm
uu.py
6763
0755
edit
dl
rm
uuid.py
24020
0644
edit
dl
rm
warnings.py
18488
0644
edit
dl
rm
wave.py
17709
0644
edit
dl
rm
weakref.py
20466
0644
edit
dl
rm
webbrowser.py
22266
0755
edit
dl
rm
xdrlib.py
5913
0644
edit
dl
rm
zipapp.py
7157
0644
edit
dl
rm
zipfile.py
79924
0644
edit
dl
rm
_bootlocale.py
1301
0644
edit
dl
rm
_collections_abc.py
26392
0644
edit
dl
rm
_compat_pickle.py
8749
0644
edit
dl
rm
_compression.py
5340
0644
edit
dl
rm
_dummy_thread.py
5118
0644
edit
dl
rm
_markupbase.py
14598
0644
edit
dl
rm
_osx_support.py
19138
0644
edit
dl
rm
_pydecimal.py
230228
0644
edit
dl
rm
_pyio.py
88097
0644
edit
dl
rm
_sitebuiltins.py
3115
0644
edit
dl
rm
_strptime.py
24747
0644
edit
dl
rm
_sysconfigdata_dm_linux_x86_64-linux-gnu.py
30191
0644
edit
dl
rm
_sysconfigdata_m_linux_x86_64-linux-gnu.py
30367
0644
edit
dl
rm
_threading_local.py
7214
0644
edit
dl
rm
_weakrefset.py
5705
0644
edit
dl
rm
__future__.py
4841
0644
edit
dl
rm
__phello__.foo.py
64
0644
edit
dl
rm
Edit:
/usr/lib64/python3.6/webbrowser.py
(22266B)
#! /usr/libexec/platform-python """Interfaces for launching and remotely controlling Web browsers.""" # Maintained by Georg Brandl. import os import shlex import shutil import sys import subprocess __all__ = ["Error", "open", "open_new", "open_new_tab", "get", "register"] class Error(Exception): pass _browsers = {} # Dictionary of available browser controllers _tryorder = [] # Preference order of available browsers def register(name, klass, instance=None, update_tryorder=1): """Register a browser connector and, optionally, connection.""" _browsers[name.lower()] = [klass, instance] if update_tryorder > 0: _tryorder.append(name) elif update_tryorder < 0: _tryorder.insert(0, name) def get(using=None): """Return a browser launcher instance appropriate for the environment.""" if using is not None: alternatives = [using] else: alternatives = _tryorder for browser in alternatives: if '%s' in browser: # User gave us a command line, split it into name and args browser = shlex.split(browser) if browser[-1] == '&': return BackgroundBrowser(browser[:-1]) else: return GenericBrowser(browser) else: # User gave us a browser name or path. try: command = _browsers[browser.lower()] except KeyError: command = _synthesize(browser) if command[1] is not None: return command[1] elif command[0] is not None: return command[0]() raise Error("could not locate runnable browser") # Please note: the following definition hides a builtin function. # It is recommended one does "import webbrowser" and uses webbrowser.open(url) # instead of "from webbrowser import *". def open(url, new=0, autoraise=True): for name in _tryorder: browser = get(name) if browser.open(url, new, autoraise): return True return False def open_new(url): return open(url, 1) def open_new_tab(url): return open(url, 2) def _synthesize(browser, update_tryorder=1): """Attempt to synthesize a controller base on existing controllers. This is useful to create a controller when a user specifies a path to an entry in the BROWSER environment variable -- we can copy a general controller to operate using a specific installation of the desired browser in this way. If we can't create a controller in this way, or if there is no executable for the requested browser, return [None, None]. """ cmd = browser.split()[0] if not shutil.which(cmd): return [None, None] name = os.path.basename(cmd) try: command = _browsers[name.lower()] except KeyError: return [None, None] # now attempt to clone to fit the new name: controller = command[1] if controller and name.lower() == controller.basename: import copy controller = copy.copy(controller) controller.name = browser controller.basename = os.path.basename(browser) register(browser, None, controller, update_tryorder) return [None, controller] return [None, None] # General parent classes class BaseBrowser(object): """Parent class for all browsers. Do not use directly.""" args = ['%s'] def __init__(self, name=""): self.name = name self.basename = name def open(self, url, new=0, autoraise=True): raise NotImplementedError def open_new(self, url): return self.open(url, 1) def open_new_tab(self, url): return self.open(url, 2) @staticmethod def _check_url(url): """Ensures that the URL is safe to pass to subprocesses as a parameter""" if url and url.lstrip().startswith("-"): raise ValueError(f"Invalid URL: {url}") class GenericBrowser(BaseBrowser): """Class for all browsers started with a command and without remote functionality.""" def __init__(self, name): if isinstance(name, str): self.name = name self.args = ["%s"] else: # name should be a list with arguments self.name = name[0] self.args = name[1:] self.basename = os.path.basename(self.name) def open(self, url, new=0, autoraise=True): self._check_url(url) cmdline = [self.name] + [arg.replace("%s", url) for arg in self.args] try: if sys.platform[:3] == 'win': p = subprocess.Popen(cmdline) else: p = subprocess.Popen(cmdline, close_fds=True) return not p.wait() except OSError: return False class BackgroundBrowser(GenericBrowser): """Class for all browsers which are to be started in the background.""" def open(self, url, new=0, autoraise=True): self._check_url(url) cmdline = [self.name] + [arg.replace("%s", url) for arg in self.args] try: if sys.platform[:3] == 'win': p = subprocess.Popen(cmdline) else: p = subprocess.Popen(cmdline, close_fds=True, start_new_session=True) return (p.poll() is None) except OSError: return False class UnixBrowser(BaseBrowser): """Parent class for all Unix browsers with remote functionality.""" raise_opts = None background = False redirect_stdout = True # In remote_args, %s will be replaced with the requested URL. %action will # be replaced depending on the value of 'new' passed to open. # remote_action is used for new=0 (open). If newwin is not None, it is # used for new=1 (open_new). If newtab is not None, it is used for # new=3 (open_new_tab). After both substitutions are made, any empty # strings in the transformed remote_args list will be removed. remote_args = ['%action', '%s'] remote_action = None remote_action_newwin = None remote_action_newtab = None def _invoke(self, args, remote, autoraise): raise_opt = [] if remote and self.raise_opts: # use autoraise argument only for remote invocation autoraise = int(autoraise) opt = self.raise_opts[autoraise] if opt: raise_opt = [opt] cmdline = [self.name] + raise_opt + args if remote or self.background: inout = subprocess.DEVNULL else: # for TTY browsers, we need stdin/out inout = None p = subprocess.Popen(cmdline, close_fds=True, stdin=inout, stdout=(self.redirect_stdout and inout or None), stderr=inout, start_new_session=True) if remote: # wait at most five seconds. If the subprocess is not finished, the # remote invocation has (hopefully) started a new instance. try: rc = p.wait(5) # if remote call failed, open() will try direct invocation return not rc except subprocess.TimeoutExpired: return True elif self.background: if p.poll() is None: return True else: return False else: return not p.wait() def open(self, url, new=0, autoraise=True): if new == 0: action = self.remote_action elif new == 1: action = self.remote_action_newwin elif new == 2: if self.remote_action_newtab is None: action = self.remote_action_newwin else: action = self.remote_action_newtab else: raise Error("Bad 'new' parameter to open(); " + "expected 0, 1, or 2, got %s" % new) self._check_url(url.replace("%action", action)) args = [arg.replace("%action", action).replace("%s", url) for arg in self.remote_args] args = [arg for arg in args if arg] success = self._invoke(args, True, autoraise) if not success: # remote invocation failed, try straight way args = [arg.replace("%s", url) for arg in self.args] return self._invoke(args, False, False) else: return True class Mozilla(UnixBrowser): """Launcher class for Mozilla browsers.""" remote_args = ['%action', '%s'] remote_action = "" remote_action_newwin = "-new-window" remote_action_newtab = "-new-tab" background = True class Netscape(UnixBrowser): """Launcher class for Netscape browser.""" raise_opts = ["-noraise", "-raise"] remote_args = ['-remote', 'openURL(%s%action)'] remote_action = "" remote_action_newwin = ",new-window" remote_action_newtab = ",new-tab" background = True class Galeon(UnixBrowser): """Launcher class for Galeon/Epiphany browsers.""" raise_opts = ["-noraise", ""] remote_args = ['%action', '%s'] remote_action = "-n" remote_action_newwin = "-w" background = True class Chrome(UnixBrowser): "Launcher class for Google Chrome browser." remote_args = ['%action', '%s'] remote_action = "" remote_action_newwin = "--new-window" remote_action_newtab = "" background = True Chromium = Chrome class Opera(UnixBrowser): "Launcher class for Opera browser." remote_args = ['%action', '%s'] remote_action = "" remote_action_newwin = "--new-window" remote_action_newtab = "" background = True class Elinks(UnixBrowser): "Launcher class for Elinks browsers." remote_args = ['-remote', 'openURL(%s%action)'] remote_action = "" remote_action_newwin = ",new-window" remote_action_newtab = ",new-tab" background = False # elinks doesn't like its stdout to be redirected - # it uses redirected stdout as a signal to do -dump redirect_stdout = False class Konqueror(BaseBrowser): """Controller for the KDE File Manager (kfm, or Konqueror). See the output of ``kfmclient --commands`` for more information on the Konqueror remote-control interface. """ def open(self, url, new=0, autoraise=True): self._check_url(url) # XXX Currently I know no way to prevent KFM from opening a new win. if new == 2: action = "newTab" else: action = "openURL" devnull = subprocess.DEVNULL try: p = subprocess.Popen(["kfmclient", action, url], close_fds=True, stdin=devnull, stdout=devnull, stderr=devnull) except OSError: # fall through to next variant pass else: p.wait() # kfmclient's return code unfortunately has no meaning as it seems return True try: p = subprocess.Popen(["konqueror", "--silent", url], close_fds=True, stdin=devnull, stdout=devnull, stderr=devnull, start_new_session=True) except OSError: # fall through to next variant pass else: if p.poll() is None: # Should be running now. return True try: p = subprocess.Popen(["kfm", "-d", url], close_fds=True, stdin=devnull, stdout=devnull, stderr=devnull, start_new_session=True) except OSError: return False else: return (p.poll() is None) class Grail(BaseBrowser): # There should be a way to maintain a connection to Grail, but the # Grail remote control protocol doesn't really allow that at this # point. It probably never will! def _find_grail_rc(self): import glob import pwd import socket import tempfile tempdir = os.path.join(tempfile.gettempdir(), ".grail-unix") user = pwd.getpwuid(os.getuid())[0] filename = os.path.join(tempdir, user + "-*") maybes = glob.glob(filename) if not maybes: return None s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) for fn in maybes: # need to PING each one until we find one that's live try: s.connect(fn) except OSError: # no good; attempt to clean it out, but don't fail: try: os.unlink(fn) except OSError: pass else: return s def _remote(self, action): s = self._find_grail_rc() if not s: return 0 s.send(action) s.close() return 1 def open(self, url, new=0, autoraise=True): self._check_url(url) if new: ok = self._remote("LOADNEW " + url) else: ok = self._remote("LOAD " + url) return ok # # Platform support for Unix # # These are the right tests because all these Unix browsers require either # a console terminal or an X display to run. def register_X_browsers(): # use xdg-open if around if shutil.which("xdg-open"): register("xdg-open", None, BackgroundBrowser("xdg-open")) # The default GNOME3 browser if "GNOME_DESKTOP_SESSION_ID" in os.environ and shutil.which("gvfs-open"): register("gvfs-open", None, BackgroundBrowser("gvfs-open")) # The default GNOME browser if "GNOME_DESKTOP_SESSION_ID" in os.environ and shutil.which("gnome-open"): register("gnome-open", None, BackgroundBrowser("gnome-open")) # The default KDE browser if "KDE_FULL_SESSION" in os.environ and shutil.which("kfmclient"): register("kfmclient", Konqueror, Konqueror("kfmclient")) if shutil.which("x-www-browser"): register("x-www-browser", None, BackgroundBrowser("x-www-browser")) # The Mozilla browsers for browser in ("firefox", "iceweasel", "iceape", "seamonkey"): if shutil.which(browser): register(browser, None, Mozilla(browser)) # The Netscape and old Mozilla browsers for browser in ("mozilla-firefox", "mozilla-firebird", "firebird", "mozilla", "netscape"): if shutil.which(browser): register(browser, None, Netscape(browser)) # Konqueror/kfm, the KDE browser. if shutil.which("kfm"): register("kfm", Konqueror, Konqueror("kfm")) elif shutil.which("konqueror"): register("konqueror", Konqueror, Konqueror("konqueror")) # Gnome's Galeon and Epiphany for browser in ("galeon", "epiphany"): if shutil.which(browser): register(browser, None, Galeon(browser)) # Skipstone, another Gtk/Mozilla based browser if shutil.which("skipstone"): register("skipstone", None, BackgroundBrowser("skipstone")) # Google Chrome/Chromium browsers for browser in ("google-chrome", "chrome", "chromium", "chromium-browser"): if shutil.which(browser): register(browser, None, Chrome(browser)) # Opera, quite popular if shutil.which("opera"): register("opera", None, Opera("opera")) # Next, Mosaic -- old but still in use. if shutil.which("mosaic"): register("mosaic", None, BackgroundBrowser("mosaic")) # Grail, the Python browser. Does anybody still use it? if shutil.which("grail"): register("grail", Grail, None) # Prefer X browsers if present if os.environ.get("DISPLAY"): register_X_browsers() # Also try console browsers if os.environ.get("TERM"): if shutil.which("www-browser"): register("www-browser", None, GenericBrowser("www-browser")) # The Links/elinks browsers <http://artax.karlin.mff.cuni.cz/~mikulas/links/> if shutil.which("links"): register("links", None, GenericBrowser("links")) if shutil.which("elinks"): register("elinks", None, Elinks("elinks")) # The Lynx browser <http://lynx.isc.org/>, <http://lynx.browser.org/> if shutil.which("lynx"): register("lynx", None, GenericBrowser("lynx")) # The w3m browser <http://w3m.sourceforge.net/> if shutil.which("w3m"): register("w3m", None, GenericBrowser("w3m")) # # Platform support for Windows # if sys.platform[:3] == "win": class WindowsDefault(BaseBrowser): def open(self, url, new=0, autoraise=True): self._check_url(url) try: os.startfile(url) except OSError: # [Error 22] No application is associated with the specified # file for this operation: '<URL>' return False else: return True _tryorder = [] _browsers = {} # First try to use the default Windows browser register("windows-default", WindowsDefault) # Detect some common Windows browsers, fallback to IE iexplore = os.path.join(os.environ.get("PROGRAMFILES", "C:\\Program Files"), "Internet Explorer\\IEXPLORE.EXE") for browser in ("firefox", "firebird", "seamonkey", "mozilla", "netscape", "opera", iexplore): if shutil.which(browser): register(browser, None, BackgroundBrowser(browser)) # # Platform support for MacOS # if sys.platform == 'darwin': # Adapted from patch submitted to SourceForge by Steven J. Burr class MacOSX(BaseBrowser): """Launcher class for Aqua browsers on Mac OS X Optionally specify a browser name on instantiation. Note that this will not work for Aqua browsers if the user has moved the application package after installation. If no browser is specified, the default browser, as specified in the Internet System Preferences panel, will be used. """ def __init__(self, name): self.name = name def open(self, url, new=0, autoraise=True): self._check_url(url) assert "'" not in url # hack for local urls if not ':' in url: url = 'file:'+url # new must be 0 or 1 new = int(bool(new)) if self.name == "default": # User called open, open_new or get without a browser parameter script = 'open location "%s"' % url.replace('"', '%22') # opens in default browser else: # User called get and chose a browser if self.name == "OmniWeb": toWindow = "" else: # Include toWindow parameter of OpenURL command for browsers # that support it. 0 == new window; -1 == existing toWindow = "toWindow %d" % (new - 1) cmd = 'OpenURL "%s"' % url.replace('"', '%22') script = '''tell application "%s" activate %s %s end tell''' % (self.name, cmd, toWindow) # Open pipe to AppleScript through osascript command osapipe = os.popen("osascript", "w") if osapipe is None: return False # Write script to osascript's stdin osapipe.write(script) rc = osapipe.close() return not rc class MacOSXOSAScript(BaseBrowser): def __init__(self, name): self._name = name def open(self, url, new=0, autoraise=True): self._check_url(url) if self._name == 'default': script = 'open location "%s"' % url.replace('"', '%22') # opens in default browser else: script = ''' tell application "%s" activate open location "%s" end '''%(self._name, url.replace('"', '%22')) osapipe = os.popen("osascript", "w") if osapipe is None: return False osapipe.write(script) rc = osapipe.close() return not rc # Don't clear _tryorder or _browsers since OS X can use above Unix support # (but we prefer using the OS X specific stuff) register("safari", None, MacOSXOSAScript('safari'), -1) register("firefox", None, MacOSXOSAScript('firefox'), -1) register("chrome", None, MacOSXOSAScript('chrome'), -1) register("MacOSX", None, MacOSXOSAScript('default'), -1) # OK, now that we know what the default preference orders for each # platform are, allow user to override them with the BROWSER variable. if "BROWSER" in os.environ: _userchoices = os.environ["BROWSER"].split(os.pathsep) _userchoices.reverse() # Treat choices in same way as if passed into get() but do register # and prepend to _tryorder for cmdline in _userchoices: if cmdline != '': cmd = _synthesize(cmdline, -1) if cmd[1] is None: register(cmdline, None, GenericBrowser(cmdline), -1) cmdline = None # to make del work if _userchoices was empty del cmdline del _userchoices # what to do if _tryorder is now empty? def main(): import getopt usage = """Usage: %s [-n | -t] url -n: open new window -t: open new tab""" % sys.argv[0] try: opts, args = getopt.getopt(sys.argv[1:], 'ntd') except getopt.error as msg: print(msg, file=sys.stderr) print(usage, file=sys.stderr) sys.exit(1) new_win = 0 for o, a in opts: if o == '-n': new_win = 1 elif o == '-t': new_win = 2 if len(args) != 1: print(usage, file=sys.stderr) sys.exit(1) url = args[0] open(url, new_win) print("\a") if __name__ == "__main__": main()
Save
cmd:
run