Changeset 388 for python/vendor/current/Lib/webbrowser.py
- Timestamp:
- Mar 19, 2014, 11:11:30 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
python/vendor/current/Lib/webbrowser.py
r2 r388 56 56 # instead of "from webbrowser import *". 57 57 58 def open(url, new=0, autoraise= 1):58 def open(url, new=0, autoraise=True): 59 59 for name in _tryorder: 60 60 browser = get(name) … … 145 145 self.basename = name 146 146 147 def open(self, url, new=0, autoraise= 1):147 def open(self, url, new=0, autoraise=True): 148 148 raise NotImplementedError 149 149 … … 169 169 self.basename = os.path.basename(self.name) 170 170 171 def open(self, url, new=0, autoraise= 1):171 def open(self, url, new=0, autoraise=True): 172 172 cmdline = [self.name] + [arg.replace("%s", url) 173 173 for arg in self.args] … … 186 186 background.""" 187 187 188 def open(self, url, new=0, autoraise= 1):188 def open(self, url, new=0, autoraise=True): 189 189 cmdline = [self.name] + [arg.replace("%s", url) 190 190 for arg in self.args] … … 217 217 if remote and self.raise_opts: 218 218 # use autoraise argument only for remote invocation 219 autoraise = int( bool(autoraise))219 autoraise = int(autoraise) 220 220 opt = self.raise_opts[autoraise] 221 221 if opt: raise_opt = [opt] … … 238 238 stderr=inout, preexec_fn=setsid) 239 239 if remote: 240 # wait five secon s. If the subprocess is not finished, the240 # wait five seconds. If the subprocess is not finished, the 241 241 # remote invocation has (hopefully) started a new instance. 242 242 time.sleep(1) … … 257 257 return not p.wait() 258 258 259 def open(self, url, new=0, autoraise= 1):259 def open(self, url, new=0, autoraise=True): 260 260 if new == 0: 261 261 action = self.remote_action … … 286 286 287 287 raise_opts = ["-noraise", "-raise"] 288 289 288 remote_args = ['-remote', 'openURL(%s%action)'] 290 289 remote_action = "" 291 290 remote_action_newwin = ",new-window" 292 291 remote_action_newtab = ",new-tab" 293 294 292 background = True 295 293 … … 304 302 remote_action = "-n" 305 303 remote_action_newwin = "-w" 306 307 304 background = True 305 306 307 class Chrome(UnixBrowser): 308 "Launcher class for Google Chrome browser." 309 310 remote_args = ['%action', '%s'] 311 remote_action = "" 312 remote_action_newwin = "--new-window" 313 remote_action_newtab = "" 314 background = True 315 316 Chromium = Chrome 308 317 309 318 … … 311 320 "Launcher class for Opera browser." 312 321 313 raise_opts = ["", "-raise"] 314 322 raise_opts = ["-noraise", ""] 315 323 remote_args = ['-remote', 'openURL(%s%action)'] 316 324 remote_action = "" … … 341 349 """ 342 350 343 def open(self, url, new=0, autoraise= 1):351 def open(self, url, new=0, autoraise=True): 344 352 # XXX Currently I know no way to prevent KFM from opening a new win. 345 353 if new == 2: … … 429 437 return 1 430 438 431 def open(self, url, new=0, autoraise= 1):439 def open(self, url, new=0, autoraise=True): 432 440 if new: 433 441 ok = self._remote("LOADNEW " + url) … … 446 454 def register_X_browsers(): 447 455 456 # use xdg-open if around 457 if _iscommand("xdg-open"): 458 register("xdg-open", None, BackgroundBrowser("xdg-open")) 459 460 # The default GNOME3 browser 461 if "GNOME_DESKTOP_SESSION_ID" in os.environ and _iscommand("gvfs-open"): 462 register("gvfs-open", None, BackgroundBrowser("gvfs-open")) 463 448 464 # The default GNOME browser 449 465 if "GNOME_DESKTOP_SESSION_ID" in os.environ and _iscommand("gnome-open"): … … 454 470 register("kfmclient", Konqueror, Konqueror("kfmclient")) 455 471 472 if _iscommand("x-www-browser"): 473 register("x-www-browser", None, BackgroundBrowser("x-www-browser")) 474 456 475 # The Mozilla/Netscape browsers 457 476 for browser in ("mozilla-firefox", "firefox", 458 477 "mozilla-firebird", "firebird", 478 "iceweasel", "iceape", 459 479 "seamonkey", "mozilla", "netscape"): 460 480 if _iscommand(browser): … … 476 496 register("skipstone", None, BackgroundBrowser("skipstone")) 477 497 498 # Google Chrome/Chromium browsers 499 for browser in ("google-chrome", "chrome", "chromium", "chromium-browser"): 500 if _iscommand(browser): 501 register(browser, None, Chrome(browser)) 502 478 503 # Opera, quite popular 479 504 if _iscommand("opera"): … … 494 519 # Also try console browsers 495 520 if os.environ.get("TERM"): 521 if _iscommand("www-browser"): 522 register("www-browser", None, GenericBrowser("www-browser")) 496 523 # The Links/elinks browsers <http://artax.karlin.mff.cuni.cz/~mikulas/links/> 497 524 if _iscommand("links"): … … 512 539 if sys.platform[:3] == "win": 513 540 class WindowsDefault(BaseBrowser): 514 def open(self, url, new=0, autoraise= 1):541 def open(self, url, new=0, autoraise=True): 515 542 try: 516 543 os.startfile(url) … … 540 567 # 541 568 542 try:543 import ic544 except ImportError:545 pass546 else:547 class InternetConfig(BaseBrowser):548 def open(self, url, new=0, autoraise=1):549 ic.launchurl(url)550 return True # Any way to get status?551 552 register("internet-config", InternetConfig, update_tryorder=-1)553 554 569 if sys.platform == 'darwin': 555 570 # Adapted from patch submitted to SourceForge by Steven J. Burr … … 567 582 self.name = name 568 583 569 def open(self, url, new=0, autoraise= 1):584 def open(self, url, new=0, autoraise=True): 570 585 assert "'" not in url 571 586 # hack for local urls … … 600 615 return not rc 601 616 617 class MacOSXOSAScript(BaseBrowser): 618 def __init__(self, name): 619 self._name = name 620 621 def open(self, url, new=0, autoraise=True): 622 if self._name == 'default': 623 script = 'open location "%s"' % url.replace('"', '%22') # opens in default browser 624 else: 625 script = ''' 626 tell application "%s" 627 activate 628 open location "%s" 629 end 630 '''%(self._name, url.replace('"', '%22')) 631 632 osapipe = os.popen("osascript", "w") 633 if osapipe is None: 634 return False 635 636 osapipe.write(script) 637 rc = osapipe.close() 638 return not rc 639 640 602 641 # Don't clear _tryorder or _browsers since OS X can use above Unix support 603 642 # (but we prefer using the OS X specific stuff) 604 register("MacOSX", None, MacOSX('default'), -1) 643 register("safari", None, MacOSXOSAScript('safari'), -1) 644 register("firefox", None, MacOSXOSAScript('firefox'), -1) 645 register("MacOSX", None, MacOSXOSAScript('default'), -1) 605 646 606 647 … … 651 692 if o == '-n': new_win = 1 652 693 elif o == '-t': new_win = 2 653 if len(args) <>1:694 if len(args) != 1: 654 695 print >>sys.stderr, usage 655 696 sys.exit(1)
Note:
See TracChangeset
for help on using the changeset viewer.