MCPcopy Create free account
hub / github.com/seleniumbase/SeleniumBase / validate_proxy_string

Function validate_proxy_string

seleniumbase/core/proxy_helper.py:170–220  ·  view source on GitHub ↗
(proxy_string, keep_scheme=False)

Source from the content-addressed store, hash-verified

168
169
170def validate_proxy_string(proxy_string, keep_scheme=False):
171 if proxy_string in proxy_list.PROXY_LIST.keys():
172 proxy_string = proxy_list.PROXY_LIST[proxy_string]
173 if not proxy_string:
174 return None
175 proxy_scheme = "http"
176 if proxy_string.startswith("https://"):
177 proxy_scheme = "https"
178 elif proxy_string.startswith("socks4://"):
179 proxy_scheme = "socks4"
180 elif proxy_string.startswith("socks5h://"):
181 proxy_scheme = "socks5h"
182 elif proxy_string.startswith("socks5://"):
183 proxy_scheme = "socks5"
184 valid = False
185 val_ip = re.match(
186 r"^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}:\d+$", proxy_string
187 )
188 if not val_ip:
189 if proxy_string.startswith("http://"):
190 proxy_string = proxy_string.split("http://")[1]
191 elif proxy_string.startswith("https://"):
192 proxy_string = proxy_string.split("https://")[1]
193 elif "://" in proxy_string:
194 if (
195 not proxy_string.startswith("socks4://")
196 and not proxy_string.startswith("socks5://")
197 and not proxy_string.startswith("socks5h://")
198 ):
199 proxy_string = proxy_string.split("://")[1]
200 chunks = proxy_string.split(":")
201 if len(chunks) == 2:
202 if re.match(r"^\d+$", chunks[1]):
203 if page_utils.is_valid_url("http://" + proxy_string):
204 valid = True
205 elif len(chunks) == 3:
206 if re.match(r"^\d+$", chunks[2]):
207 if page_utils.is_valid_url("http:" + ":".join(chunks[1:])):
208 if chunks[0] in [
209 "http", "https", "socks4", "socks5", "socks5h"
210 ]:
211 valid = True
212 else:
213 proxy_string = val_ip.group()
214 valid = True
215 if not valid:
216 __display_proxy_warning(proxy_string)
217 proxy_string = None
218 if keep_scheme:
219 return (proxy_string, proxy_scheme)
220 return proxy_string
221
222
223def __display_proxy_warning(proxy_string):

Callers

nothing calls this directly

Calls 2

__display_proxy_warningFunction · 0.85
is_valid_urlMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…