MCPcopy Index your code
hub / github.com/RustPython/RustPython / _synthesize

Function _synthesize

Lib/webbrowser.py:115–144  ·  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

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

Callers 2

getFunction · 0.85

Calls 5

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

Tested by

no test coverage detected