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

Function build_opener

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

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

Callers 2

test_build_openerMethod · 0.85
urlopenFunction · 0.85

Calls 10

add_handlerMethod · 0.95
OpenerDirectorClass · 0.85
hasattrFunction · 0.85
setFunction · 0.85
isinstanceFunction · 0.85
issubclassFunction · 0.85
hClass · 0.85
appendMethod · 0.45
addMethod · 0.45
removeMethod · 0.45

Tested by 1

test_build_openerMethod · 0.68