Best Python code snippet using devtools-proxy_python
proxy.py
Source:proxy.py
...212 await handler.shutdown()213 for srv in srvs:214 await srv.wait_closed()215 app['f']['close_log']()216def encode_decode_id(max_clients):217 bits_available = 31218 bits_for_client_id = math.ceil(math.log2(max_clients))219 _max_clients = 2 ** bits_for_client_id220 max_request_id = 2 ** (bits_available - bits_for_client_id) - 1221 def encode_id(client_id, request_id):222 if request_id > max_request_id:223 raise OverflowError224 return (client_id << bits_available - bits_for_client_id) | request_id225 def decode_id(encoded_id):226 client_id = encoded_id >> (bits_available - bits_for_client_id)227 request_id = encoded_id & max_request_id228 return client_id, request_id229 return encode_id, decode_id, _max_clients230def default_or_flatten_and_uniq(arg, default):231 # Simple helper for parsing arguments with action='append' and default value232 if arg is None:233 return default234 else:235 return list(set(e for ee in arg for e in ee))236def main():237 parser = argparse.ArgumentParser(238 prog='devtools-proxy',239 description='DevTools Proxy'240 )241 default_host = ['127.0.0.1']242 parser.add_argument(243 '--host',244 type=str, nargs='+', action='append',245 help=f'Hosts to serve on (default: {default_host})',246 )247 default_port = [9222]248 parser.add_argument(249 '--port',250 type=int, nargs='+', action='append',251 help=f'Ports to serve on (default: {default_port})',252 )253 parser.add_argument(254 '--chrome-host',255 type=str, default='127.0.0.1',256 help=('Host on which Chrome is running, '257 'it corresponds with --remote-debugging-address Chrome argument (default: %(default)r)'),258 )259 parser.add_argument(260 '--chrome-port',261 type=int, default=12222,262 help=('Port which Chrome remote debugger is listening, '263 'it corresponds with --remote-debugging-port Chrome argument (default: %(default)r)'),264 )265 parser.add_argument(266 '--max-clients',267 type=int, default=8,268 help='Number of clients which proxy can handle during life cycle (default: %(default)r)',269 )270 parser.add_argument(271 '--log',272 default=sys.stdout, type=argparse.FileType('w'),273 help='Write logs to file',274 )275 parser.add_argument(276 '--version',277 action='version',278 version=VERSION,279 help='Print DevTools Proxy version',280 )281 parser.add_argument(282 '--debug',283 action='store_true', default=False,284 help='Turn on debug mode (default: %(default)r)',285 )286 args = parser.parse_args()287 encode_id, decode_id, max_clients = encode_decode_id(args.max_clients)288 args.port = default_or_flatten_and_uniq(args.port, default_port)289 args.host = default_or_flatten_and_uniq(args.host, default_host)290 arguments = {291 'f': {292 'encode_id': encode_id,293 'decode_id': decode_id,294 'print': lambda *a: args.log.write(' '.join(str(v) for v in a) + '\n'),295 'close_log': lambda: args.log.close(),296 },297 'max_clients': max_clients,298 'debug': args.debug,299 'proxy_hosts': args.host,300 'proxy_ports': args.port,301 'chrome_host': args.chrome_host,...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!