MCPcopy Index your code
hub / github.com/python/cpython / _synthesize

Function _synthesize

Lib/webbrowser.py:114–143  ·  view source on GitHub ↗

Attempt to synthesize a controller based on existing controllers. This is useful to create a controller when a user specifies a path to an entry in the BROWSER environment variable -- we can copy a general controller to operate using a specific installation of the desired browser in

(browser, *, preferred=False)

Source from the content-addressed store, hash-verified

112
113
114def _synthesize(browser, *, preferred=False):
115 """Attempt to synthesize a controller based on existing controllers.
116
117 This is useful to create a controller when a user specifies a path to
118 an entry in the BROWSER environment variable -- we can copy a general
119 controller to operate using a specific installation of the desired
120 browser in this way.
121
122 If we can't create a controller in this way, or if there is no
123 executable for the requested browser, return [None, None].
124
125 """
126 cmd = browser.split()[0]
127 if not shutil.which(cmd):
128 return [None, None]
129 name = os.path.basename(cmd)
130 try:
131 command = _browsers[name.lower()]
132 except KeyError:
133 return [None, None]
134 # now attempt to clone to fit the new name:
135 controller = command[1]
136 if controller and name.lower() == controller.basename:
137 import copy
138 controller = copy.copy(controller)
139 controller.name = browser
140 controller.basename = os.path.basename(browser)
141 register(browser, None, instance=controller, preferred=preferred)
142 return [None, controller]
143 return [None, None]
144
145
146# General parent classes

Callers 2

getFunction · 0.85

Calls 5

registerFunction · 0.70
splitMethod · 0.45
basenameMethod · 0.45
lowerMethod · 0.45
copyMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…