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

Function build_opener

Lib/urllib/request.py:539–573  ·  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

537# make sense to include both
538
539def build_opener(*handlers):
540 """Create an opener object from a list of handlers.
541
542 The opener will use several default handlers, including support
543 for HTTP, FTP and when applicable HTTPS.
544
545 If any of the handlers passed as arguments are subclasses of the
546 default handlers, the default handlers will not be used.
547 """
548 opener = OpenerDirector()
549 default_classes = [ProxyHandler, UnknownHandler, HTTPHandler,
550 HTTPDefaultErrorHandler, HTTPRedirectHandler,
551 FTPHandler, FileHandler, HTTPErrorProcessor,
552 DataHandler]
553 if hasattr(http.client, "HTTPSConnection"):
554 default_classes.append(HTTPSHandler)
555 skip = set()
556 for klass in default_classes:
557 for check in handlers:
558 if isinstance(check, type):
559 if issubclass(check, klass):
560 skip.add(klass)
561 elif isinstance(check, klass):
562 skip.add(klass)
563 for klass in skip:
564 default_classes.remove(klass)
565
566 for klass in default_classes:
567 opener.add_handler(klass())
568
569 for h in handlers:
570 if isinstance(h, type):
571 h = h()
572 opener.add_handler(h)
573 return opener
574
575class BaseHandler:
576 handler_order = 500

Callers 2

test_build_openerMethod · 0.85
urlopenFunction · 0.85

Calls 7

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

Tested by 1

test_build_openerMethod · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…