MCPcopy
hub / github.com/pimutils/vdirsyncer / open_graphical_browser

Function open_graphical_browser

vdirsyncer/utils.py:203–227  ·  view source on GitHub ↗

Open a graphical web browser. This is basically like `webbrowser.open`, but without trying to launch CLI browsers at all. We're excluding those since it's undesirable to launch those when you're using vdirsyncer on a server. Rather copypaste the URL into the local browser, or use th

(url, new=0, autoraise=True)

Source from the content-addressed store, hash-verified

201
202
203def open_graphical_browser(url, new=0, autoraise=True):
204 '''Open a graphical web browser.
205
206 This is basically like `webbrowser.open`, but without trying to launch CLI
207 browsers at all. We're excluding those since it's undesirable to launch
208 those when you're using vdirsyncer on a server. Rather copypaste the URL
209 into the local browser, or use the URL-yanking features of your terminal
210 emulator.
211 '''
212 import webbrowser
213 cli_names = {'www-browser', 'links', 'links2', 'elinks', 'lynx', 'w3m'}
214
215 if webbrowser._tryorder is None: # Python 3.7
216 webbrowser.register_standard_browsers()
217
218 for name in webbrowser._tryorder:
219 if name in cli_names:
220 continue
221
222 browser = webbrowser.get(name)
223 if browser.open(url, new, autoraise):
224 return
225
226 raise RuntimeError('No graphical browser found. Please open the URL '
227 'manually.')

Callers 1

_init_tokenMethod · 0.85

Calls 1

getMethod · 0.45

Tested by

no test coverage detected