MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / build_opener

Function build_opener

tools/python-3.11.9-amd64/Lib/urllib/request.py:569–603  ·  view source on GitHub ↗

Create an opener object from a list of handlers. The opener will use several default handlers, including support for HTTP, FTP and when applicable HTTPS. If any of the handlers passed as arguments are subclasses of the default handlers, the default handlers will not be used.

(*handlers)

Source from the content-addressed store, hash-verified

567# make sense to include both
568
569def build_opener(*handlers):
570 """Create an opener object from a list of handlers.
571
572 The opener will use several default handlers, including support
573 for HTTP, FTP and when applicable HTTPS.
574
575 If any of the handlers passed as arguments are subclasses of the
576 default handlers, the default handlers will not be used.
577 """
578 opener = OpenerDirector()
579 default_classes = [ProxyHandler, UnknownHandler, HTTPHandler,
580 HTTPDefaultErrorHandler, HTTPRedirectHandler,
581 FTPHandler, FileHandler, HTTPErrorProcessor,
582 DataHandler]
583 if hasattr(http.client, "HTTPSConnection"):
584 default_classes.append(HTTPSHandler)
585 skip = set()
586 for klass in default_classes:
587 for check in handlers:
588 if isinstance(check, type):
589 if issubclass(check, klass):
590 skip.add(klass)
591 elif isinstance(check, klass):
592 skip.add(klass)
593 for klass in skip:
594 default_classes.remove(klass)
595
596 for klass in default_classes:
597 opener.add_handler(klass())
598
599 for h in handlers:
600 if isinstance(h, type):
601 h = h()
602 opener.add_handler(h)
603 return opener
604
605class BaseHandler:
606 handler_order = 500

Callers 3

urlopenFunction · 0.85
__init__Method · 0.85
send_requestMethod · 0.85

Calls 7

add_handlerMethod · 0.95
OpenerDirectorClass · 0.85
hFunction · 0.85
setFunction · 0.50
appendMethod · 0.45
addMethod · 0.45
removeMethod · 0.45

Tested by

no test coverage detected