Mercurial > cpython-lru_cache-weakref
annotate Lib/webbrowser.py @ 79691:05c8928362ee
Merge __next__ method link fixes with 3.3.
| author | Ezio Melotti <ezio.melotti@gmail.com> |
|---|---|
| date | Fri, 12 Oct 2012 13:46:37 +0300 |
| parents | d853354e1470 |
| children | 50d19c2fac82 |
| rev | line source |
|---|---|
|
59522
fcfe324663a6
convert shebang lines: python -> python3
Benjamin Peterson <benjamin@python.org>
parents:
55913
diff
changeset
|
1 #! /usr/bin/env python3 |
| 16926 | 2 """Interfaces for launching and remotely controlling Web browsers.""" |
|
42193
090588a17490
Merged revisions 56154-56264 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
3 # Maintained by Georg Brandl. |
|
13476
8f66c5ffa26c
New module to control Web browsers; see the documentation for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
4 |
|
50540
4229a4b14f1d
Merged revisions 67653,67655,67682-67683,67724,67755,67780-67783,67786,67789,67841,67843,67865,67881,67884,67925,67929,67931 via svnmerge from
Georg Brandl <georg@python.org>
parents:
50037
diff
changeset
|
5 import io |
|
13476
8f66c5ffa26c
New module to control Web browsers; see the documentation for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
6 import os |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40775
diff
changeset
|
7 import shlex |
|
13476
8f66c5ffa26c
New module to control Web browsers; see the documentation for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
8 import sys |
|
35685
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
9 import stat |
|
36352
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
10 import subprocess |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
11 import time |
|
13476
8f66c5ffa26c
New module to control Web browsers; see the documentation for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
12 |
|
35685
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
13 __all__ = ["Error", "open", "open_new", "open_new_tab", "get", "register"] |
|
16889
0feb63490093
final round of __all__ lists (I hope) - skipped urllib2 because Moshe may be
Skip Montanaro <skip@pobox.com>
parents:
16833
diff
changeset
|
14 |
|
13476
8f66c5ffa26c
New module to control Web browsers; see the documentation for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
15 class Error(Exception): |
|
8f66c5ffa26c
New module to control Web browsers; see the documentation for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
16 pass |
|
8f66c5ffa26c
New module to control Web browsers; see the documentation for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
17 |
|
16535
084b3dc9b6ff
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
16161
diff
changeset
|
18 _browsers = {} # Dictionary of available browser controllers |
|
084b3dc9b6ff
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
16161
diff
changeset
|
19 _tryorder = [] # Preference order of available browsers |
|
13476
8f66c5ffa26c
New module to control Web browsers; see the documentation for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
20 |
|
35685
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
21 def register(name, klass, instance=None, update_tryorder=1): |
|
13476
8f66c5ffa26c
New module to control Web browsers; see the documentation for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
22 """Register a browser connector and, optionally, connection.""" |
|
8f66c5ffa26c
New module to control Web browsers; see the documentation for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
23 _browsers[name.lower()] = [klass, instance] |
|
35685
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
24 if update_tryorder > 0: |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
25 _tryorder.append(name) |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
26 elif update_tryorder < 0: |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
27 _tryorder.insert(0, name) |
|
13476
8f66c5ffa26c
New module to control Web browsers; see the documentation for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
28 |
|
16153
df7bfb34b2a2
Rewrite webbrowser.py to fix various bugs following Ka-Ping Yee's
Eric S. Raymond <esr@thyrsus.com>
parents:
15874
diff
changeset
|
29 def get(using=None): |
|
df7bfb34b2a2
Rewrite webbrowser.py to fix various bugs following Ka-Ping Yee's
Eric S. Raymond <esr@thyrsus.com>
parents:
15874
diff
changeset
|
30 """Return a browser launcher instance appropriate for the environment.""" |
|
23628
ea979c5206b7
Replaced boolean tests with is None.
Raymond Hettinger <python@rcn.com>
parents:
23620
diff
changeset
|
31 if using is not None: |
|
16153
df7bfb34b2a2
Rewrite webbrowser.py to fix various bugs following Ka-Ping Yee's
Eric S. Raymond <esr@thyrsus.com>
parents:
15874
diff
changeset
|
32 alternatives = [using] |
|
df7bfb34b2a2
Rewrite webbrowser.py to fix various bugs following Ka-Ping Yee's
Eric S. Raymond <esr@thyrsus.com>
parents:
15874
diff
changeset
|
33 else: |
|
df7bfb34b2a2
Rewrite webbrowser.py to fix various bugs following Ka-Ping Yee's
Eric S. Raymond <esr@thyrsus.com>
parents:
15874
diff
changeset
|
34 alternatives = _tryorder |
|
df7bfb34b2a2
Rewrite webbrowser.py to fix various bugs following Ka-Ping Yee's
Eric S. Raymond <esr@thyrsus.com>
parents:
15874
diff
changeset
|
35 for browser in alternatives: |
|
31967
3d046d063a84
Replace str.find()!=1 with the more readable "in" operator.
Raymond Hettinger <python@rcn.com>
parents:
26404
diff
changeset
|
36 if '%s' in browser: |
|
36352
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
37 # User gave us a command line, split it into name and args |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40775
diff
changeset
|
38 browser = shlex.split(browser) |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40775
diff
changeset
|
39 if browser[-1] == '&': |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40775
diff
changeset
|
40 return BackgroundBrowser(browser[:-1]) |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40775
diff
changeset
|
41 else: |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40775
diff
changeset
|
42 return GenericBrowser(browser) |
|
16153
df7bfb34b2a2
Rewrite webbrowser.py to fix various bugs following Ka-Ping Yee's
Eric S. Raymond <esr@thyrsus.com>
parents:
15874
diff
changeset
|
43 else: |
|
35685
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
44 # User gave us a browser name or path. |
|
17461
a004c62e696e
_synthesize(): Helper function: when the users passes a specific
Fred Drake <fdrake@acm.org>
parents:
17270
diff
changeset
|
45 try: |
|
a004c62e696e
_synthesize(): Helper function: when the users passes a specific
Fred Drake <fdrake@acm.org>
parents:
17270
diff
changeset
|
46 command = _browsers[browser.lower()] |
|
a004c62e696e
_synthesize(): Helper function: when the users passes a specific
Fred Drake <fdrake@acm.org>
parents:
17270
diff
changeset
|
47 except KeyError: |
|
a004c62e696e
_synthesize(): Helper function: when the users passes a specific
Fred Drake <fdrake@acm.org>
parents:
17270
diff
changeset
|
48 command = _synthesize(browser) |
|
35685
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
49 if command[1] is not None: |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
50 return command[1] |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
51 elif command[0] is not None: |
|
16153
df7bfb34b2a2
Rewrite webbrowser.py to fix various bugs following Ka-Ping Yee's
Eric S. Raymond <esr@thyrsus.com>
parents:
15874
diff
changeset
|
52 return command[0]() |
|
df7bfb34b2a2
Rewrite webbrowser.py to fix various bugs following Ka-Ping Yee's
Eric S. Raymond <esr@thyrsus.com>
parents:
15874
diff
changeset
|
53 raise Error("could not locate runnable browser") |
|
13476
8f66c5ffa26c
New module to control Web browsers; see the documentation for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
54 |
|
8f66c5ffa26c
New module to control Web browsers; see the documentation for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
55 # Please note: the following definition hides a builtin function. |
|
35685
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
56 # It is recommended one does "import webbrowser" and uses webbrowser.open(url) |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
57 # instead of "from webbrowser import *". |
|
13476
8f66c5ffa26c
New module to control Web browsers; see the documentation for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
58 |
|
55584
5fbac09c0e91
Merged revisions 74264 via svnmerge from
Georg Brandl <georg@python.org>
parents:
50540
diff
changeset
|
59 def open(url, new=0, autoraise=True): |
|
35685
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
60 for name in _tryorder: |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
61 browser = get(name) |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
62 if browser.open(url, new, autoraise): |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
63 return True |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
64 return False |
|
13476
8f66c5ffa26c
New module to control Web browsers; see the documentation for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
65 |
| 18720 | 66 def open_new(url): |
|
35685
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
67 return open(url, 1) |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
68 |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
69 def open_new_tab(url): |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
70 return open(url, 2) |
|
13476
8f66c5ffa26c
New module to control Web browsers; see the documentation for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
71 |
|
17461
a004c62e696e
_synthesize(): Helper function: when the users passes a specific
Fred Drake <fdrake@acm.org>
parents:
17270
diff
changeset
|
72 |
|
35685
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
73 def _synthesize(browser, update_tryorder=1): |
|
17461
a004c62e696e
_synthesize(): Helper function: when the users passes a specific
Fred Drake <fdrake@acm.org>
parents:
17270
diff
changeset
|
74 """Attempt to synthesize a controller base on existing controllers. |
|
a004c62e696e
_synthesize(): Helper function: when the users passes a specific
Fred Drake <fdrake@acm.org>
parents:
17270
diff
changeset
|
75 |
|
a004c62e696e
_synthesize(): Helper function: when the users passes a specific
Fred Drake <fdrake@acm.org>
parents:
17270
diff
changeset
|
76 This is useful to create a controller when a user specifies a path to |
|
a004c62e696e
_synthesize(): Helper function: when the users passes a specific
Fred Drake <fdrake@acm.org>
parents:
17270
diff
changeset
|
77 an entry in the BROWSER environment variable -- we can copy a general |
|
a004c62e696e
_synthesize(): Helper function: when the users passes a specific
Fred Drake <fdrake@acm.org>
parents:
17270
diff
changeset
|
78 controller to operate using a specific installation of the desired |
|
a004c62e696e
_synthesize(): Helper function: when the users passes a specific
Fred Drake <fdrake@acm.org>
parents:
17270
diff
changeset
|
79 browser in this way. |
|
a004c62e696e
_synthesize(): Helper function: when the users passes a specific
Fred Drake <fdrake@acm.org>
parents:
17270
diff
changeset
|
80 |
|
a004c62e696e
_synthesize(): Helper function: when the users passes a specific
Fred Drake <fdrake@acm.org>
parents:
17270
diff
changeset
|
81 If we can't create a controller in this way, or if there is no |
|
a004c62e696e
_synthesize(): Helper function: when the users passes a specific
Fred Drake <fdrake@acm.org>
parents:
17270
diff
changeset
|
82 executable for the requested browser, return [None, None]. |
|
a004c62e696e
_synthesize(): Helper function: when the users passes a specific
Fred Drake <fdrake@acm.org>
parents:
17270
diff
changeset
|
83 |
|
a004c62e696e
_synthesize(): Helper function: when the users passes a specific
Fred Drake <fdrake@acm.org>
parents:
17270
diff
changeset
|
84 """ |
|
35685
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
85 cmd = browser.split()[0] |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
86 if not _iscommand(cmd): |
|
17461
a004c62e696e
_synthesize(): Helper function: when the users passes a specific
Fred Drake <fdrake@acm.org>
parents:
17270
diff
changeset
|
87 return [None, None] |
|
35685
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
88 name = os.path.basename(cmd) |
|
17461
a004c62e696e
_synthesize(): Helper function: when the users passes a specific
Fred Drake <fdrake@acm.org>
parents:
17270
diff
changeset
|
89 try: |
|
a004c62e696e
_synthesize(): Helper function: when the users passes a specific
Fred Drake <fdrake@acm.org>
parents:
17270
diff
changeset
|
90 command = _browsers[name.lower()] |
|
a004c62e696e
_synthesize(): Helper function: when the users passes a specific
Fred Drake <fdrake@acm.org>
parents:
17270
diff
changeset
|
91 except KeyError: |
|
a004c62e696e
_synthesize(): Helper function: when the users passes a specific
Fred Drake <fdrake@acm.org>
parents:
17270
diff
changeset
|
92 return [None, None] |
|
a004c62e696e
_synthesize(): Helper function: when the users passes a specific
Fred Drake <fdrake@acm.org>
parents:
17270
diff
changeset
|
93 # now attempt to clone to fit the new name: |
|
a004c62e696e
_synthesize(): Helper function: when the users passes a specific
Fred Drake <fdrake@acm.org>
parents:
17270
diff
changeset
|
94 controller = command[1] |
|
a004c62e696e
_synthesize(): Helper function: when the users passes a specific
Fred Drake <fdrake@acm.org>
parents:
17270
diff
changeset
|
95 if controller and name.lower() == controller.basename: |
|
a004c62e696e
_synthesize(): Helper function: when the users passes a specific
Fred Drake <fdrake@acm.org>
parents:
17270
diff
changeset
|
96 import copy |
|
a004c62e696e
_synthesize(): Helper function: when the users passes a specific
Fred Drake <fdrake@acm.org>
parents:
17270
diff
changeset
|
97 controller = copy.copy(controller) |
|
a004c62e696e
_synthesize(): Helper function: when the users passes a specific
Fred Drake <fdrake@acm.org>
parents:
17270
diff
changeset
|
98 controller.name = browser |
|
a004c62e696e
_synthesize(): Helper function: when the users passes a specific
Fred Drake <fdrake@acm.org>
parents:
17270
diff
changeset
|
99 controller.basename = os.path.basename(browser) |
|
35685
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
100 register(browser, None, controller, update_tryorder) |
|
17461
a004c62e696e
_synthesize(): Helper function: when the users passes a specific
Fred Drake <fdrake@acm.org>
parents:
17270
diff
changeset
|
101 return [None, controller] |
|
19208
7b53fb3ba011
Fix malformed line (PyChecker)
Andrew M. Kuchling <amk@amk.ca>
parents:
18720
diff
changeset
|
102 return [None, None] |
|
17461
a004c62e696e
_synthesize(): Helper function: when the users passes a specific
Fred Drake <fdrake@acm.org>
parents:
17270
diff
changeset
|
103 |
| 18720 | 104 |
|
35685
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
105 if sys.platform[:3] == "win": |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
106 def _isexecutable(cmd): |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
107 cmd = cmd.lower() |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
108 if os.path.isfile(cmd) and cmd.endswith((".exe", ".bat")): |
|
35685
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
109 return True |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
110 for ext in ".exe", ".bat": |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
111 if os.path.isfile(cmd + ext): |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
112 return True |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
113 return False |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
114 else: |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
115 def _isexecutable(cmd): |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
116 if os.path.isfile(cmd): |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
117 mode = os.stat(cmd)[stat.ST_MODE] |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
118 if mode & stat.S_IXUSR or mode & stat.S_IXGRP or mode & stat.S_IXOTH: |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
119 return True |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
120 return False |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
121 |
| 18720 | 122 def _iscommand(cmd): |
|
35685
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
123 """Return True if cmd is executable or can be found on the executable |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
124 search path.""" |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
125 if _isexecutable(cmd): |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
126 return True |
| 18720 | 127 path = os.environ.get("PATH") |
| 128 if not path: | |
|
22830
a9dd5e6d6805
Convert a pile of obvious "yes/no" functions to return bool.
Tim Peters <tim.peters@gmail.com>
parents:
22303
diff
changeset
|
129 return False |
| 18720 | 130 for d in path.split(os.pathsep): |
| 131 exe = os.path.join(d, cmd) | |
|
35685
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
132 if _isexecutable(exe): |
|
22830
a9dd5e6d6805
Convert a pile of obvious "yes/no" functions to return bool.
Tim Peters <tim.peters@gmail.com>
parents:
22303
diff
changeset
|
133 return True |
|
a9dd5e6d6805
Convert a pile of obvious "yes/no" functions to return bool.
Tim Peters <tim.peters@gmail.com>
parents:
22303
diff
changeset
|
134 return False |
| 18720 | 135 |
| 136 | |
|
35685
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
137 # General parent classes |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
138 |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
139 class BaseBrowser(object): |
|
36352
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
140 """Parent class for all browsers. Do not use directly.""" |
|
36362
ca6c800ad5a0
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
36352
diff
changeset
|
141 |
|
36352
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
142 args = ['%s'] |
|
36362
ca6c800ad5a0
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
36352
diff
changeset
|
143 |
|
35685
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
144 def __init__(self, name=""): |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
145 self.name = name |
|
35707
5685ec59f35b
Fix errors in _synthesize because of missing basename attribute of
Georg Brandl <georg@python.org>
parents:
35692
diff
changeset
|
146 self.basename = name |
|
36121
686306a67e9b
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
35920
diff
changeset
|
147 |
|
55584
5fbac09c0e91
Merged revisions 74264 via svnmerge from
Georg Brandl <georg@python.org>
parents:
50540
diff
changeset
|
148 def open(self, url, new=0, autoraise=True): |
| 35692 | 149 raise NotImplementedError |
| 150 | |
|
35685
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
151 def open_new(self, url): |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
152 return self.open(url, 1) |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
153 |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
154 def open_new_tab(self, url): |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
155 return self.open(url, 2) |
| 18720 | 156 |
| 157 | |
|
35685
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
158 class GenericBrowser(BaseBrowser): |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
159 """Class for all browsers started with a command |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
160 and without remote functionality.""" |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
161 |
|
36352
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
162 def __init__(self, name): |
|
43577
ace45b361e87
Patch# 1258 by Christian Heimes: kill basestring.
Guido van Rossum <guido@python.org>
parents:
42193
diff
changeset
|
163 if isinstance(name, str): |
|
36352
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
164 self.name = name |
|
42193
090588a17490
Merged revisions 56154-56264 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
165 self.args = ["%s"] |
|
36352
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
166 else: |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
167 # name should be a list with arguments |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
168 self.name = name[0] |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
169 self.args = name[1:] |
|
35707
5685ec59f35b
Fix errors in _synthesize because of missing basename attribute of
Georg Brandl <georg@python.org>
parents:
35692
diff
changeset
|
170 self.basename = os.path.basename(self.name) |
| 18720 | 171 |
|
55584
5fbac09c0e91
Merged revisions 74264 via svnmerge from
Georg Brandl <georg@python.org>
parents:
50540
diff
changeset
|
172 def open(self, url, new=0, autoraise=True): |
|
36362
ca6c800ad5a0
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
36352
diff
changeset
|
173 cmdline = [self.name] + [arg.replace("%s", url) |
|
36352
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
174 for arg in self.args] |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
175 try: |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39648
diff
changeset
|
176 if sys.platform[:3] == 'win': |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39648
diff
changeset
|
177 p = subprocess.Popen(cmdline) |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39648
diff
changeset
|
178 else: |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39648
diff
changeset
|
179 p = subprocess.Popen(cmdline, close_fds=True) |
|
36352
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
180 return not p.wait() |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
181 except OSError: |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
182 return False |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
183 |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
184 |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
185 class BackgroundBrowser(GenericBrowser): |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
186 """Class for all browsers which are to be started in the |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
187 background.""" |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
188 |
|
55584
5fbac09c0e91
Merged revisions 74264 via svnmerge from
Georg Brandl <georg@python.org>
parents:
50540
diff
changeset
|
189 def open(self, url, new=0, autoraise=True): |
|
36352
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
190 cmdline = [self.name] + [arg.replace("%s", url) |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
191 for arg in self.args] |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
192 try: |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39648
diff
changeset
|
193 if sys.platform[:3] == 'win': |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39648
diff
changeset
|
194 p = subprocess.Popen(cmdline) |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39648
diff
changeset
|
195 else: |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39648
diff
changeset
|
196 setsid = getattr(os, 'setsid', None) |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39648
diff
changeset
|
197 if not setsid: |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39648
diff
changeset
|
198 setsid = getattr(os, 'setpgrp', None) |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39648
diff
changeset
|
199 p = subprocess.Popen(cmdline, close_fds=True, preexec_fn=setsid) |
|
36352
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
200 return (p.poll() is None) |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
201 except OSError: |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
202 return False |
| 18720 | 203 |
| 204 | |
|
35685
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
205 class UnixBrowser(BaseBrowser): |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
206 """Parent class for all Unix browsers with remote functionality.""" |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
207 |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
208 raise_opts = None |
|
78844
6768aa70c2d3
#15509: If %action substitution produces a null string, drop it.
R David Murray <rdmurray@bitdance.com>
parents:
71443
diff
changeset
|
209 background = False |
|
6768aa70c2d3
#15509: If %action substitution produces a null string, drop it.
R David Murray <rdmurray@bitdance.com>
parents:
71443
diff
changeset
|
210 redirect_stdout = True |
|
6768aa70c2d3
#15509: If %action substitution produces a null string, drop it.
R David Murray <rdmurray@bitdance.com>
parents:
71443
diff
changeset
|
211 # In remote_args, %s will be replaced with the requested URL. %action will |
|
6768aa70c2d3
#15509: If %action substitution produces a null string, drop it.
R David Murray <rdmurray@bitdance.com>
parents:
71443
diff
changeset
|
212 # be replaced depending on the value of 'new' passed to open. |
|
6768aa70c2d3
#15509: If %action substitution produces a null string, drop it.
R David Murray <rdmurray@bitdance.com>
parents:
71443
diff
changeset
|
213 # remote_action is used for new=0 (open). If newwin is not None, it is |
|
6768aa70c2d3
#15509: If %action substitution produces a null string, drop it.
R David Murray <rdmurray@bitdance.com>
parents:
71443
diff
changeset
|
214 # used for new=1 (open_new). If newtab is not None, it is used for |
|
6768aa70c2d3
#15509: If %action substitution produces a null string, drop it.
R David Murray <rdmurray@bitdance.com>
parents:
71443
diff
changeset
|
215 # new=3 (open_new_tab). After both substitutions are made, any empty |
|
6768aa70c2d3
#15509: If %action substitution produces a null string, drop it.
R David Murray <rdmurray@bitdance.com>
parents:
71443
diff
changeset
|
216 # strings in the transformed remote_args list will be removed. |
|
36352
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
217 remote_args = ['%action', '%s'] |
|
35685
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
218 remote_action = None |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
219 remote_action_newwin = None |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
220 remote_action_newtab = None |
|
36352
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
221 |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
222 def _invoke(self, args, remote, autoraise): |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
223 raise_opt = [] |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
224 if remote and self.raise_opts: |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
225 # use autoraise argument only for remote invocation |
|
55584
5fbac09c0e91
Merged revisions 74264 via svnmerge from
Georg Brandl <georg@python.org>
parents:
50540
diff
changeset
|
226 autoraise = int(autoraise) |
|
36352
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
227 opt = self.raise_opts[autoraise] |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
228 if opt: raise_opt = [opt] |
|
35685
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
229 |
|
36352
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
230 cmdline = [self.name] + raise_opt + args |
|
36362
ca6c800ad5a0
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
36352
diff
changeset
|
231 |
|
36352
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
232 if remote or self.background: |
|
78846
901c790e4417
#15447: Use subprocess.DEVNULL in webbrowser, instead of opening
R David Murray <rdmurray@bitdance.com>
parents:
78845
diff
changeset
|
233 inout = subprocess.DEVNULL |
|
36352
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
234 else: |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
235 # for TTY browsers, we need stdin/out |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
236 inout = None |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
237 p = subprocess.Popen(cmdline, close_fds=True, stdin=inout, |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
238 stdout=(self.redirect_stdout and inout or None), |
|
68521
d71476b9a55d
Use start_new_session in the webbrowser module rather than a python os.setsid preeexec_fn.
Gregory P. Smith <greg@krypto.org>
parents:
68257
diff
changeset
|
239 stderr=inout, start_new_session=True) |
|
36352
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
240 if remote: |
|
78362
a16403affccd
Closes #15499: Sleep is hardcoded in webbrowser.UnixBrowser
Jesus Cea <jcea@jcea.es>
parents:
76100
diff
changeset
|
241 # wait at most five seconds. If the subprocess is not finished, the |
|
36352
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
242 # remote invocation has (hopefully) started a new instance. |
|
78362
a16403affccd
Closes #15499: Sleep is hardcoded in webbrowser.UnixBrowser
Jesus Cea <jcea@jcea.es>
parents:
76100
diff
changeset
|
243 try: |
|
a16403affccd
Closes #15499: Sleep is hardcoded in webbrowser.UnixBrowser
Jesus Cea <jcea@jcea.es>
parents:
76100
diff
changeset
|
244 rc = p.wait(5) |
|
a16403affccd
Closes #15499: Sleep is hardcoded in webbrowser.UnixBrowser
Jesus Cea <jcea@jcea.es>
parents:
76100
diff
changeset
|
245 # if remote call failed, open() will try direct invocation |
|
a16403affccd
Closes #15499: Sleep is hardcoded in webbrowser.UnixBrowser
Jesus Cea <jcea@jcea.es>
parents:
76100
diff
changeset
|
246 return not rc |
|
a16403affccd
Closes #15499: Sleep is hardcoded in webbrowser.UnixBrowser
Jesus Cea <jcea@jcea.es>
parents:
76100
diff
changeset
|
247 except subprocess.TimeoutExpired: |
|
a16403affccd
Closes #15499: Sleep is hardcoded in webbrowser.UnixBrowser
Jesus Cea <jcea@jcea.es>
parents:
76100
diff
changeset
|
248 return True |
|
36352
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
249 elif self.background: |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
250 if p.poll() is None: |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
251 return True |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
252 else: |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
253 return False |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
254 else: |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
255 return not p.wait() |
| 18720 | 256 |
|
55584
5fbac09c0e91
Merged revisions 74264 via svnmerge from
Georg Brandl <georg@python.org>
parents:
50540
diff
changeset
|
257 def open(self, url, new=0, autoraise=True): |
|
35685
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
258 if new == 0: |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
259 action = self.remote_action |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
260 elif new == 1: |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
261 action = self.remote_action_newwin |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
262 elif new == 2: |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
263 if self.remote_action_newtab is None: |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
264 action = self.remote_action_newwin |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
265 else: |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
266 action = self.remote_action_newtab |
| 18720 | 267 else: |
|
36352
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
268 raise Error("Bad 'new' parameter to open(); " + |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
269 "expected 0, 1, or 2, got %s" % new) |
|
36362
ca6c800ad5a0
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
36352
diff
changeset
|
270 |
|
36352
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
271 args = [arg.replace("%s", url).replace("%action", action) |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
272 for arg in self.remote_args] |
|
78844
6768aa70c2d3
#15509: If %action substitution produces a null string, drop it.
R David Murray <rdmurray@bitdance.com>
parents:
71443
diff
changeset
|
273 args = [arg for arg in args if arg] |
|
36352
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
274 success = self._invoke(args, True, autoraise) |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
275 if not success: |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
276 # remote invocation failed, try straight way |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
277 args = [arg.replace("%s", url) for arg in self.args] |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
278 return self._invoke(args, False, False) |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
279 else: |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
280 return True |
| 18720 | 281 |
| 282 | |
|
35685
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
283 class Mozilla(UnixBrowser): |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
284 """Launcher class for Mozilla/Netscape browsers.""" |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
285 |
|
36352
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
286 raise_opts = ["-noraise", "-raise"] |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
287 remote_args = ['-remote', 'openURL(%s%action)'] |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
288 remote_action = "" |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
289 remote_action_newwin = ",new-window" |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
290 remote_action_newtab = ",new-tab" |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
291 background = True |
|
25715
2adadc19923c
SF # 585913, Adds Galeon support to webbrowser.py
Neal Norwitz <nnorwitz@gmail.com>
parents:
23628
diff
changeset
|
292 |
|
35685
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
293 Netscape = Mozilla |
|
25715
2adadc19923c
SF # 585913, Adds Galeon support to webbrowser.py
Neal Norwitz <nnorwitz@gmail.com>
parents:
23628
diff
changeset
|
294 |
|
2adadc19923c
SF # 585913, Adds Galeon support to webbrowser.py
Neal Norwitz <nnorwitz@gmail.com>
parents:
23628
diff
changeset
|
295 |
|
35685
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
296 class Galeon(UnixBrowser): |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
297 """Launcher class for Galeon/Epiphany browsers.""" |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
298 |
|
36352
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
299 raise_opts = ["-noraise", ""] |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
300 remote_args = ['%action', '%s'] |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
301 remote_action = "-n" |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
302 remote_action_newwin = "-w" |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
303 background = True |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
304 |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
305 |
|
74110
7faa90a6324c
Issue 13620 - Support chrome browser in webbrowser.py module.
Senthil Kumaran <senthil@uthcode.com>
parents:
71443
diff
changeset
|
306 class Chrome(UnixBrowser): |
|
7faa90a6324c
Issue 13620 - Support chrome browser in webbrowser.py module.
Senthil Kumaran <senthil@uthcode.com>
parents:
71443
diff
changeset
|
307 "Launcher class for Google Chrome browser." |
|
7faa90a6324c
Issue 13620 - Support chrome browser in webbrowser.py module.
Senthil Kumaran <senthil@uthcode.com>
parents:
71443
diff
changeset
|
308 |
|
7faa90a6324c
Issue 13620 - Support chrome browser in webbrowser.py module.
Senthil Kumaran <senthil@uthcode.com>
parents:
71443
diff
changeset
|
309 remote_args = ['%action', '%s'] |
|
7faa90a6324c
Issue 13620 - Support chrome browser in webbrowser.py module.
Senthil Kumaran <senthil@uthcode.com>
parents:
71443
diff
changeset
|
310 remote_action = "" |
|
7faa90a6324c
Issue 13620 - Support chrome browser in webbrowser.py module.
Senthil Kumaran <senthil@uthcode.com>
parents:
71443
diff
changeset
|
311 remote_action_newwin = "--new-window" |
|
7faa90a6324c
Issue 13620 - Support chrome browser in webbrowser.py module.
Senthil Kumaran <senthil@uthcode.com>
parents:
71443
diff
changeset
|
312 remote_action_newtab = "" |
|
7faa90a6324c
Issue 13620 - Support chrome browser in webbrowser.py module.
Senthil Kumaran <senthil@uthcode.com>
parents:
71443
diff
changeset
|
313 background = True |
|
7faa90a6324c
Issue 13620 - Support chrome browser in webbrowser.py module.
Senthil Kumaran <senthil@uthcode.com>
parents:
71443
diff
changeset
|
314 |
|
7faa90a6324c
Issue 13620 - Support chrome browser in webbrowser.py module.
Senthil Kumaran <senthil@uthcode.com>
parents:
71443
diff
changeset
|
315 Chromium = Chrome |
|
7faa90a6324c
Issue 13620 - Support chrome browser in webbrowser.py module.
Senthil Kumaran <senthil@uthcode.com>
parents:
71443
diff
changeset
|
316 |
|
7faa90a6324c
Issue 13620 - Support chrome browser in webbrowser.py module.
Senthil Kumaran <senthil@uthcode.com>
parents:
71443
diff
changeset
|
317 |
|
36352
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
318 class Opera(UnixBrowser): |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
319 "Launcher class for Opera browser." |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
320 |
|
67198
5bbc1dc459a5
Issue 10738: Fix webbrowser.Opera.raise_opts value.
Terry Reedy <tjreedy@udel.edu>
parents:
55913
diff
changeset
|
321 raise_opts = ["-noraise", ""] |
|
36352
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
322 remote_args = ['-remote', 'openURL(%s%action)'] |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
323 remote_action = "" |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
324 remote_action_newwin = ",new-window" |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
325 remote_action_newtab = ",new-page" |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
326 background = True |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
327 |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
328 |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
329 class Elinks(UnixBrowser): |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
330 "Launcher class for Elinks browsers." |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
331 |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
332 remote_args = ['-remote', 'openURL(%s%action)'] |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
333 remote_action = "" |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
334 remote_action_newwin = ",new-window" |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
335 remote_action_newtab = ",new-tab" |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
336 background = False |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
337 |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
338 # elinks doesn't like its stdout to be redirected - |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
339 # it uses redirected stdout as a signal to do -dump |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
340 redirect_stdout = False |
|
35685
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
341 |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
342 |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
343 class Konqueror(BaseBrowser): |
| 18720 | 344 """Controller for the KDE File Manager (kfm, or Konqueror). |
| 345 | |
|
36352
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
346 See the output of ``kfmclient --commands`` |
| 18720 | 347 for more information on the Konqueror remote-control interface. |
| 348 """ | |
| 349 | |
|
55584
5fbac09c0e91
Merged revisions 74264 via svnmerge from
Georg Brandl <georg@python.org>
parents:
50540
diff
changeset
|
350 def open(self, url, new=0, autoraise=True): |
|
36352
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
351 # XXX Currently I know no way to prevent KFM from opening a new win. |
|
35685
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
352 if new == 2: |
|
36352
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
353 action = "newTab" |
|
35685
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
354 else: |
|
36352
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
355 action = "openURL" |
|
36362
ca6c800ad5a0
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
36352
diff
changeset
|
356 |
|
78846
901c790e4417
#15447: Use subprocess.DEVNULL in webbrowser, instead of opening
R David Murray <rdmurray@bitdance.com>
parents:
78845
diff
changeset
|
357 devnull = subprocess.DEVNULL |
|
36352
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
358 # if possible, put browser in separate process group, so |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
359 # keyboard interrupts don't affect browser as well as Python |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
360 setsid = getattr(os, 'setsid', None) |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
361 if not setsid: |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
362 setsid = getattr(os, 'setpgrp', None) |
|
36362
ca6c800ad5a0
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
36352
diff
changeset
|
363 |
|
36352
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
364 try: |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
365 p = subprocess.Popen(["kfmclient", action, url], |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
366 close_fds=True, stdin=devnull, |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
367 stdout=devnull, stderr=devnull) |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
368 except OSError: |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
369 # fall through to next variant |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
370 pass |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
371 else: |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
372 p.wait() |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
373 # kfmclient's return code unfortunately has no meaning as it seems |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
374 return True |
|
35685
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
375 |
|
36352
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
376 try: |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
377 p = subprocess.Popen(["konqueror", "--silent", url], |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
378 close_fds=True, stdin=devnull, |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
379 stdout=devnull, stderr=devnull, |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
380 preexec_fn=setsid) |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
381 except OSError: |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
382 # fall through to next variant |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
383 pass |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
384 else: |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
385 if p.poll() is None: |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
386 # Should be running now. |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
387 return True |
|
36362
ca6c800ad5a0
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
36352
diff
changeset
|
388 |
|
36352
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
389 try: |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
390 p = subprocess.Popen(["kfm", "-d", url], |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
391 close_fds=True, stdin=devnull, |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
392 stdout=devnull, stderr=devnull, |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
393 preexec_fn=setsid) |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
394 except OSError: |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
395 return False |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
396 else: |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
397 return (p.poll() is None) |
|
35685
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
398 |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
399 |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
400 class Grail(BaseBrowser): |
| 18720 | 401 # There should be a way to maintain a connection to Grail, but the |
| 402 # Grail remote control protocol doesn't really allow that at this | |
|
36352
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
403 # point. It probably never will! |
| 18720 | 404 def _find_grail_rc(self): |
| 405 import glob | |
| 406 import pwd | |
| 407 import socket | |
| 408 import tempfile | |
| 409 tempdir = os.path.join(tempfile.gettempdir(), | |
| 410 ".grail-unix") | |
|
20417
c168eda736e4
_os should be os; reported by Neal Norwitz.
Fred Drake <fdrake@acm.org>
parents:
19208
diff
changeset
|
411 user = pwd.getpwuid(os.getuid())[0] |
| 18720 | 412 filename = os.path.join(tempdir, user + "-*") |
| 413 maybes = glob.glob(filename) | |
| 414 if not maybes: | |
| 415 return None | |
| 416 s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) | |
| 417 for fn in maybes: | |
| 418 # need to PING each one until we find one that's live | |
| 419 try: | |
| 420 s.connect(fn) | |
| 421 except socket.error: | |
| 422 # no good; attempt to clean it out, but don't fail: | |
| 423 try: | |
| 424 os.unlink(fn) | |
| 425 except IOError: | |
| 426 pass | |
| 427 else: | |
| 428 return s | |
| 429 | |
| 430 def _remote(self, action): | |
| 431 s = self._find_grail_rc() | |
| 432 if not s: | |
| 433 return 0 | |
| 434 s.send(action) | |
| 435 s.close() | |
| 436 return 1 | |
| 437 | |
|
55584
5fbac09c0e91
Merged revisions 74264 via svnmerge from
Georg Brandl <georg@python.org>
parents:
50540
diff
changeset
|
438 def open(self, url, new=0, autoraise=True): |
| 18720 | 439 if new: |
|
35685
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
440 ok = self._remote("LOADNEW " + url) |
| 18720 | 441 else: |
|
35685
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
442 ok = self._remote("LOAD " + url) |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
443 return ok |
| 18720 | 444 |
| 445 | |
|
16535
084b3dc9b6ff
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
16161
diff
changeset
|
446 # |
|
16153
df7bfb34b2a2
Rewrite webbrowser.py to fix various bugs following Ka-Ping Yee's
Eric S. Raymond <esr@thyrsus.com>
parents:
15874
diff
changeset
|
447 # Platform support for Unix |
|
df7bfb34b2a2
Rewrite webbrowser.py to fix various bugs following Ka-Ping Yee's
Eric S. Raymond <esr@thyrsus.com>
parents:
15874
diff
changeset
|
448 # |
|
13476
8f66c5ffa26c
New module to control Web browsers; see the documentation for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
449 |
|
35685
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
450 # These are the right tests because all these Unix browsers require either |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
451 # a console terminal or an X display to run. |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
452 |
| 35692 | 453 def register_X_browsers(): |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40775
diff
changeset
|
454 |
|
76100
70c58903b52e
- Issue #14493: Use gvfs-open/xdg-open in Lib/webbrowser.py.
Matthias Klose <doko@ubuntu.com>
parents:
74110
diff
changeset
|
455 # use xdg-open if around |
|
70c58903b52e
- Issue #14493: Use gvfs-open/xdg-open in Lib/webbrowser.py.
Matthias Klose <doko@ubuntu.com>
parents:
74110
diff
changeset
|
456 if _iscommand("xdg-open"): |
|
70c58903b52e
- Issue #14493: Use gvfs-open/xdg-open in Lib/webbrowser.py.
Matthias Klose <doko@ubuntu.com>
parents:
74110
diff
changeset
|
457 register("xdg-open", None, BackgroundBrowser("xdg-open")) |
|
70c58903b52e
- Issue #14493: Use gvfs-open/xdg-open in Lib/webbrowser.py.
Matthias Klose <doko@ubuntu.com>
parents:
74110
diff
changeset
|
458 |
|
70c58903b52e
- Issue #14493: Use gvfs-open/xdg-open in Lib/webbrowser.py.
Matthias Klose <doko@ubuntu.com>
parents:
74110
diff
changeset
|
459 # The default GNOME3 browser |
|
70c58903b52e
- Issue #14493: Use gvfs-open/xdg-open in Lib/webbrowser.py.
Matthias Klose <doko@ubuntu.com>
parents:
74110
diff
changeset
|
460 if "GNOME_DESKTOP_SESSION_ID" in os.environ and _iscommand("gvfs-open"): |
|
70c58903b52e
- Issue #14493: Use gvfs-open/xdg-open in Lib/webbrowser.py.
Matthias Klose <doko@ubuntu.com>
parents:
74110
diff
changeset
|
461 register("gvfs-open", None, BackgroundBrowser("gvfs-open")) |
|
70c58903b52e
- Issue #14493: Use gvfs-open/xdg-open in Lib/webbrowser.py.
Matthias Klose <doko@ubuntu.com>
parents:
74110
diff
changeset
|
462 |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40775
diff
changeset
|
463 # The default GNOME browser |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40775
diff
changeset
|
464 if "GNOME_DESKTOP_SESSION_ID" in os.environ and _iscommand("gnome-open"): |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40775
diff
changeset
|
465 register("gnome-open", None, BackgroundBrowser("gnome-open")) |
|
13476
8f66c5ffa26c
New module to control Web browsers; see the documentation for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
466 |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40775
diff
changeset
|
467 # The default KDE browser |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40775
diff
changeset
|
468 if "KDE_FULL_SESSION" in os.environ and _iscommand("kfmclient"): |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40775
diff
changeset
|
469 register("kfmclient", Konqueror, Konqueror("kfmclient")) |
| 26404 | 470 |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40775
diff
changeset
|
471 # The Mozilla/Netscape browsers |
|
35920
e11323189c84
Prefer GNOME browser over mozilla.
Georg Brandl <georg@python.org>
parents:
35851
diff
changeset
|
472 for browser in ("mozilla-firefox", "firefox", |
|
e11323189c84
Prefer GNOME browser over mozilla.
Georg Brandl <georg@python.org>
parents:
35851
diff
changeset
|
473 "mozilla-firebird", "firebird", |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
36362
diff
changeset
|
474 "seamonkey", "mozilla", "netscape"): |
|
35920
e11323189c84
Prefer GNOME browser over mozilla.
Georg Brandl <georg@python.org>
parents:
35851
diff
changeset
|
475 if _iscommand(browser): |
|
e11323189c84
Prefer GNOME browser over mozilla.
Georg Brandl <georg@python.org>
parents:
35851
diff
changeset
|
476 register(browser, None, Mozilla(browser)) |
|
e11323189c84
Prefer GNOME browser over mozilla.
Georg Brandl <georg@python.org>
parents:
35851
diff
changeset
|
477 |
|
35685
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
478 # Konqueror/kfm, the KDE browser. |
|
35707
5685ec59f35b
Fix errors in _synthesize because of missing basename attribute of
Georg Brandl <georg@python.org>
parents:
35692
diff
changeset
|
479 if _iscommand("kfm"): |
|
5685ec59f35b
Fix errors in _synthesize because of missing basename attribute of
Georg Brandl <georg@python.org>
parents:
35692
diff
changeset
|
480 register("kfm", Konqueror, Konqueror("kfm")) |
|
5685ec59f35b
Fix errors in _synthesize because of missing basename attribute of
Georg Brandl <georg@python.org>
parents:
35692
diff
changeset
|
481 elif _iscommand("konqueror"): |
|
5685ec59f35b
Fix errors in _synthesize because of missing basename attribute of
Georg Brandl <georg@python.org>
parents:
35692
diff
changeset
|
482 register("konqueror", Konqueror, Konqueror("konqueror")) |
|
16153
df7bfb34b2a2
Rewrite webbrowser.py to fix various bugs following Ka-Ping Yee's
Eric S. Raymond <esr@thyrsus.com>
parents:
15874
diff
changeset
|
483 |
|
35685
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
484 # Gnome's Galeon and Epiphany |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
485 for browser in ("galeon", "epiphany"): |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
486 if _iscommand(browser): |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
487 register(browser, None, Galeon(browser)) |
|
16153
df7bfb34b2a2
Rewrite webbrowser.py to fix various bugs following Ka-Ping Yee's
Eric S. Raymond <esr@thyrsus.com>
parents:
15874
diff
changeset
|
488 |
|
35685
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
489 # Skipstone, another Gtk/Mozilla based browser |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
490 if _iscommand("skipstone"): |
|
36352
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
491 register("skipstone", None, BackgroundBrowser("skipstone")) |
|
25715
2adadc19923c
SF # 585913, Adds Galeon support to webbrowser.py
Neal Norwitz <nnorwitz@gmail.com>
parents:
23628
diff
changeset
|
492 |
|
74110
7faa90a6324c
Issue 13620 - Support chrome browser in webbrowser.py module.
Senthil Kumaran <senthil@uthcode.com>
parents:
71443
diff
changeset
|
493 # Google Chrome/Chromium browsers |
|
7faa90a6324c
Issue 13620 - Support chrome browser in webbrowser.py module.
Senthil Kumaran <senthil@uthcode.com>
parents:
71443
diff
changeset
|
494 for browser in ("google-chrome", "chrome", "chromium", "chromium-browser"): |
|
7faa90a6324c
Issue 13620 - Support chrome browser in webbrowser.py module.
Senthil Kumaran <senthil@uthcode.com>
parents:
71443
diff
changeset
|
495 if _iscommand(browser): |
|
7faa90a6324c
Issue 13620 - Support chrome browser in webbrowser.py module.
Senthil Kumaran <senthil@uthcode.com>
parents:
71443
diff
changeset
|
496 register(browser, None, Chrome(browser)) |
|
7faa90a6324c
Issue 13620 - Support chrome browser in webbrowser.py module.
Senthil Kumaran <senthil@uthcode.com>
parents:
71443
diff
changeset
|
497 |
|
35685
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
498 # Opera, quite popular |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
499 if _iscommand("opera"): |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
500 register("opera", None, Opera("opera")) |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
501 |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
502 # Next, Mosaic -- old but still in use. |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
503 if _iscommand("mosaic"): |
|
36352
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
504 register("mosaic", None, BackgroundBrowser("mosaic")) |
| 26404 | 505 |
|
35685
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
506 # Grail, the Python browser. Does anybody still use it? |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
507 if _iscommand("grail"): |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
508 register("grail", Grail, None) |
| 18720 | 509 |
| 35692 | 510 # Prefer X browsers if present |
| 511 if os.environ.get("DISPLAY"): | |
| 512 register_X_browsers() | |
| 513 | |
|
35685
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
514 # Also try console browsers |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
515 if os.environ.get("TERM"): |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
516 # The Links/elinks browsers <http://artax.karlin.mff.cuni.cz/~mikulas/links/> |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
517 if _iscommand("links"): |
|
36352
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
518 register("links", None, GenericBrowser("links")) |
|
35685
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
519 if _iscommand("elinks"): |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
520 register("elinks", None, Elinks("elinks")) |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
521 # The Lynx browser <http://lynx.isc.org/>, <http://lynx.browser.org/> |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
522 if _iscommand("lynx"): |
|
36352
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
523 register("lynx", None, GenericBrowser("lynx")) |
|
35685
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
524 # The w3m browser <http://w3m.sourceforge.net/> |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
525 if _iscommand("w3m"): |
|
36352
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
526 register("w3m", None, GenericBrowser("w3m")) |
|
13476
8f66c5ffa26c
New module to control Web browsers; see the documentation for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
527 |
|
16153
df7bfb34b2a2
Rewrite webbrowser.py to fix various bugs following Ka-Ping Yee's
Eric S. Raymond <esr@thyrsus.com>
parents:
15874
diff
changeset
|
528 # |
|
df7bfb34b2a2
Rewrite webbrowser.py to fix various bugs following Ka-Ping Yee's
Eric S. Raymond <esr@thyrsus.com>
parents:
15874
diff
changeset
|
529 # Platform support for Windows |
|
df7bfb34b2a2
Rewrite webbrowser.py to fix various bugs following Ka-Ping Yee's
Eric S. Raymond <esr@thyrsus.com>
parents:
15874
diff
changeset
|
530 # |
|
13476
8f66c5ffa26c
New module to control Web browsers; see the documentation for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
531 |
|
8f66c5ffa26c
New module to control Web browsers; see the documentation for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
532 if sys.platform[:3] == "win": |
|
35685
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
533 class WindowsDefault(BaseBrowser): |
|
55584
5fbac09c0e91
Merged revisions 74264 via svnmerge from
Georg Brandl <georg@python.org>
parents:
50540
diff
changeset
|
534 def open(self, url, new=0, autoraise=True): |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40775
diff
changeset
|
535 try: |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40775
diff
changeset
|
536 os.startfile(url) |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40775
diff
changeset
|
537 except WindowsError: |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40775
diff
changeset
|
538 # [Error 22] No application is associated with the specified |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40775
diff
changeset
|
539 # file for this operation: '<URL>' |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40775
diff
changeset
|
540 return False |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40775
diff
changeset
|
541 else: |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40775
diff
changeset
|
542 return True |
|
35685
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
543 |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
544 _tryorder = [] |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
545 _browsers = {} |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40775
diff
changeset
|
546 |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40775
diff
changeset
|
547 # First try to use the default Windows browser |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40775
diff
changeset
|
548 register("windows-default", WindowsDefault) |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40775
diff
changeset
|
549 |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40775
diff
changeset
|
550 # Detect some common Windows browsers, fallback to IE |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40775
diff
changeset
|
551 iexplore = os.path.join(os.environ.get("PROGRAMFILES", "C:\\Program Files"), |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40775
diff
changeset
|
552 "Internet Explorer\\IEXPLORE.EXE") |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
36362
diff
changeset
|
553 for browser in ("firefox", "firebird", "seamonkey", "mozilla", |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40775
diff
changeset
|
554 "netscape", "opera", iexplore): |
|
35685
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
555 if _iscommand(browser): |
|
36352
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
556 register(browser, None, BackgroundBrowser(browser)) |
|
16153
df7bfb34b2a2
Rewrite webbrowser.py to fix various bugs following Ka-Ping Yee's
Eric S. Raymond <esr@thyrsus.com>
parents:
15874
diff
changeset
|
557 |
|
13476
8f66c5ffa26c
New module to control Web browsers; see the documentation for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
558 # |
|
16153
df7bfb34b2a2
Rewrite webbrowser.py to fix various bugs following Ka-Ping Yee's
Eric S. Raymond <esr@thyrsus.com>
parents:
15874
diff
changeset
|
559 # Platform support for MacOS |
|
df7bfb34b2a2
Rewrite webbrowser.py to fix various bugs following Ka-Ping Yee's
Eric S. Raymond <esr@thyrsus.com>
parents:
15874
diff
changeset
|
560 # |
|
13476
8f66c5ffa26c
New module to control Web browsers; see the documentation for
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
561 |
|
35685
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
562 if sys.platform == 'darwin': |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
563 # Adapted from patch submitted to SourceForge by Steven J. Burr |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
564 class MacOSX(BaseBrowser): |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
565 """Launcher class for Aqua browsers on Mac OS X |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
566 |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
567 Optionally specify a browser name on instantiation. Note that this |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
568 will not work for Aqua browsers if the user has moved the application |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
569 package after installation. |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
570 |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
571 If no browser is specified, the default browser, as specified in the |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
572 Internet System Preferences panel, will be used. |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
573 """ |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
574 def __init__(self, name): |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
575 self.name = name |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
576 |
|
55584
5fbac09c0e91
Merged revisions 74264 via svnmerge from
Georg Brandl <georg@python.org>
parents:
50540
diff
changeset
|
577 def open(self, url, new=0, autoraise=True): |
|
35685
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
578 assert "'" not in url |
|
36352
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
579 # hack for local urls |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
580 if not ':' in url: |
|
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
581 url = 'file:'+url |
|
36362
ca6c800ad5a0
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
36352
diff
changeset
|
582 |
|
35685
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
583 # new must be 0 or 1 |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
584 new = int(bool(new)) |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
585 if self.name == "default": |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
586 # User called open, open_new or get without a browser parameter |
|
35851
413c68b31487
Bug #1338995: fix problem with new webbrowser.py.
Georg Brandl <georg@python.org>
parents:
35707
diff
changeset
|
587 script = 'open location "%s"' % url.replace('"', '%22') # opens in default browser |
|
35685
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
588 else: |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
589 # User called get and chose a browser |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
590 if self.name == "OmniWeb": |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
591 toWindow = "" |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
592 else: |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
593 # Include toWindow parameter of OpenURL command for browsers |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
594 # that support it. 0 == new window; -1 == existing |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
595 toWindow = "toWindow %d" % (new - 1) |
|
35851
413c68b31487
Bug #1338995: fix problem with new webbrowser.py.
Georg Brandl <georg@python.org>
parents:
35707
diff
changeset
|
596 cmd = 'OpenURL "%s"' % url.replace('"', '%22') |
|
35685
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
597 script = '''tell application "%s" |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
598 activate |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
599 %s %s |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
600 end tell''' % (self.name, cmd, toWindow) |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
601 # Open pipe to AppleScript through osascript command |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
602 osapipe = os.popen("osascript", "w") |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
603 if osapipe is None: |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
604 return False |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
605 # Write script to osascript's stdin |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
606 osapipe.write(script) |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
607 rc = osapipe.close() |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
608 return not rc |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
609 |
|
61159
7d98e0ea9db3
Merged revisions 80698 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
59522
diff
changeset
|
610 class MacOSXOSAScript(BaseBrowser): |
|
7d98e0ea9db3
Merged revisions 80698 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
59522
diff
changeset
|
611 def __init__(self, name): |
|
7d98e0ea9db3
Merged revisions 80698 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
59522
diff
changeset
|
612 self._name = name |
|
7d98e0ea9db3
Merged revisions 80698 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
59522
diff
changeset
|
613 |
|
7d98e0ea9db3
Merged revisions 80698 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
59522
diff
changeset
|
614 def open(self, url, new=0, autoraise=True): |
|
7d98e0ea9db3
Merged revisions 80698 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
59522
diff
changeset
|
615 if self._name == 'default': |
|
7d98e0ea9db3
Merged revisions 80698 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
59522
diff
changeset
|
616 script = 'open location "%s"' % url.replace('"', '%22') # opens in default browser |
|
7d98e0ea9db3
Merged revisions 80698 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
59522
diff
changeset
|
617 else: |
|
7d98e0ea9db3
Merged revisions 80698 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
59522
diff
changeset
|
618 script = ''' |
|
7d98e0ea9db3
Merged revisions 80698 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
59522
diff
changeset
|
619 tell application "%s" |
|
7d98e0ea9db3
Merged revisions 80698 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
59522
diff
changeset
|
620 activate |
|
7d98e0ea9db3
Merged revisions 80698 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
59522
diff
changeset
|
621 open location "%s" |
|
7d98e0ea9db3
Merged revisions 80698 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
59522
diff
changeset
|
622 end |
|
7d98e0ea9db3
Merged revisions 80698 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
59522
diff
changeset
|
623 '''%(self._name, url.replace('"', '%22')) |
|
7d98e0ea9db3
Merged revisions 80698 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
59522
diff
changeset
|
624 |
|
7d98e0ea9db3
Merged revisions 80698 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
59522
diff
changeset
|
625 osapipe = os.popen("osascript", "w") |
|
7d98e0ea9db3
Merged revisions 80698 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
59522
diff
changeset
|
626 if osapipe is None: |
|
7d98e0ea9db3
Merged revisions 80698 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
59522
diff
changeset
|
627 return False |
|
7d98e0ea9db3
Merged revisions 80698 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
59522
diff
changeset
|
628 |
|
7d98e0ea9db3
Merged revisions 80698 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
59522
diff
changeset
|
629 osapipe.write(script) |
|
7d98e0ea9db3
Merged revisions 80698 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
59522
diff
changeset
|
630 rc = osapipe.close() |
|
7d98e0ea9db3
Merged revisions 80698 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
59522
diff
changeset
|
631 return not rc |
|
7d98e0ea9db3
Merged revisions 80698 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
59522
diff
changeset
|
632 |
|
7d98e0ea9db3
Merged revisions 80698 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
59522
diff
changeset
|
633 |
|
35685
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
634 # Don't clear _tryorder or _browsers since OS X can use above Unix support |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
635 # (but we prefer using the OS X specific stuff) |
|
61159
7d98e0ea9db3
Merged revisions 80698 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
59522
diff
changeset
|
636 register("safari", None, MacOSXOSAScript('safari'), -1) |
|
7d98e0ea9db3
Merged revisions 80698 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
59522
diff
changeset
|
637 register("firefox", None, MacOSXOSAScript('firefox'), -1) |
|
7d98e0ea9db3
Merged revisions 80698 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
59522
diff
changeset
|
638 register("MacOSX", None, MacOSXOSAScript('default'), -1) |
|
35685
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
639 |
|
16153
df7bfb34b2a2
Rewrite webbrowser.py to fix various bugs following Ka-Ping Yee's
Eric S. Raymond <esr@thyrsus.com>
parents:
15874
diff
changeset
|
640 |
|
df7bfb34b2a2
Rewrite webbrowser.py to fix various bugs following Ka-Ping Yee's
Eric S. Raymond <esr@thyrsus.com>
parents:
15874
diff
changeset
|
641 # OK, now that we know what the default preference orders for each |
|
df7bfb34b2a2
Rewrite webbrowser.py to fix various bugs following Ka-Ping Yee's
Eric S. Raymond <esr@thyrsus.com>
parents:
15874
diff
changeset
|
642 # platform are, allow user to override them with the BROWSER variable. |
|
23620
a1de0bab5475
SF 563203. Replaced 'has_key()' with 'in'.
Raymond Hettinger <python@rcn.com>
parents:
22830
diff
changeset
|
643 if "BROWSER" in os.environ: |
|
35685
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
644 _userchoices = os.environ["BROWSER"].split(os.pathsep) |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
645 _userchoices.reverse() |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
646 |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
647 # Treat choices in same way as if passed into get() but do register |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
648 # and prepend to _tryorder |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
649 for cmdline in _userchoices: |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
650 if cmdline != '': |
|
55913
3fb1c1fbe26c
Merged revisions 74745 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
55584
diff
changeset
|
651 cmd = _synthesize(cmdline, -1) |
|
3fb1c1fbe26c
Merged revisions 74745 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
55584
diff
changeset
|
652 if cmd[1] is None: |
|
3fb1c1fbe26c
Merged revisions 74745 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
55584
diff
changeset
|
653 register(cmdline, None, GenericBrowser(cmdline), -1) |
|
35685
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
654 cmdline = None # to make del work if _userchoices was empty |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
655 del cmdline |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
656 del _userchoices |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
657 |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
658 # what to do if _tryorder is now empty? |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
659 |
|
18714
5c73621c9559
this closes patches item 429136 and brings the release21-maint version into
Skip Montanaro <skip@pobox.com>
parents:
17461
diff
changeset
|
660 |
|
35685
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
661 def main(): |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
662 import getopt |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
663 usage = """Usage: %s [-n | -t] url |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
664 -n: open new window |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
665 -t: open new tab""" % sys.argv[0] |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
666 try: |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
667 opts, args = getopt.getopt(sys.argv[1:], 'ntd') |
|
40587
6b18a095c2e7
SF patch 1631942 by Collin Winter:
Guido van Rossum <guido@python.org>
parents:
40450
diff
changeset
|
668 except getopt.error as msg: |
|
40775
4cdf21a0dbbc
Fix most trivially-findable print statements.
Guido van Rossum <guido@python.org>
parents:
40587
diff
changeset
|
669 print(msg, file=sys.stderr) |
|
4cdf21a0dbbc
Fix most trivially-findable print statements.
Guido van Rossum <guido@python.org>
parents:
40587
diff
changeset
|
670 print(usage, file=sys.stderr) |
|
35685
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
671 sys.exit(1) |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
672 new_win = 0 |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
673 for o, a in opts: |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
674 if o == '-n': new_win = 1 |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
675 elif o == '-t': new_win = 2 |
|
39648
efe3f2c0da5e
Killed the <> operator. You must now use !=.
Guido van Rossum <guido@python.org>
parents:
39647
diff
changeset
|
676 if len(args) != 1: |
|
40775
4cdf21a0dbbc
Fix most trivially-findable print statements.
Guido van Rossum <guido@python.org>
parents:
40587
diff
changeset
|
677 print(usage, file=sys.stderr) |
|
35685
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
678 sys.exit(1) |
|
18714
5c73621c9559
this closes patches item 429136 and brings the release21-maint version into
Skip Montanaro <skip@pobox.com>
parents:
17461
diff
changeset
|
679 |
|
35685
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
680 url = args[0] |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
681 open(url, new_win) |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
682 |
|
40775
4cdf21a0dbbc
Fix most trivially-findable print statements.
Guido van Rossum <guido@python.org>
parents:
40587
diff
changeset
|
683 print("\a") |
|
36352
6e12707371a1
Try to resolve the remaining webbrowser issues (backgrounding, local urls)
Georg Brandl <georg@python.org>
parents:
36121
diff
changeset
|
684 |
|
35685
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
685 if __name__ == "__main__": |
|
3be835350082
Patch #754022: Greatly enhanced webbrowser.py.
Georg Brandl <georg@python.org>
parents:
32605
diff
changeset
|
686 main() |
