Return a browser launcher instance appropriate for the environment.
(using=None)
| 38 | |
| 39 | |
| 40 | def get(using=None): |
| 41 | """Return a browser launcher instance appropriate for the environment.""" |
| 42 | if _tryorder is None: |
| 43 | with _lock: |
| 44 | if _tryorder is None: |
| 45 | register_standard_browsers() |
| 46 | if using is not None: |
| 47 | alternatives = [using] |
| 48 | else: |
| 49 | alternatives = _tryorder |
| 50 | for browser in alternatives: |
| 51 | if '%s' in browser: |
| 52 | # User gave us a command line, split it into name and args |
| 53 | browser = shlex.split(browser) |
| 54 | if browser[-1] == '&': |
| 55 | return BackgroundBrowser(browser[:-1]) |
| 56 | else: |
| 57 | return GenericBrowser(browser) |
| 58 | else: |
| 59 | # User gave us a browser name or path. |
| 60 | try: |
| 61 | command = _browsers[browser.lower()] |
| 62 | except KeyError: |
| 63 | command = _synthesize(browser) |
| 64 | if command[1] is not None: |
| 65 | return command[1] |
| 66 | elif command[0] is not None: |
| 67 | return command[0]() |
| 68 | raise Error("could not locate runnable browser") |
| 69 | |
| 70 | |
| 71 | # Please note: the following definition hides a builtin function. |
no test coverage detected