def build_opener(*handlers, **kw):
 def isclass(obj):
  return (isinstance(obj, class_type_) or hasattr(obj, '__bases__'))
 opener = OpenerDirector()
 default_classes = [ProxyHandler, UnknownHandler, HTTPHandler, HTTPDefaultErrorHandler, HTTPRedirectHandler, FTPHandler, FileHandler, HTTPErrorProcessor]
 check_classes = list(default_classes)
 check_classes.append(HTTPSContextHandler)
 skip = []
 for klass in check_classes:
  for check in handlers:
   if isclass(check):
    if issubclass(check, klass):
     skip.append(klass)
   elif isinstance(check, klass):
    skip.append(klass)
 for klass in default_classes:
  if (klass not in skip):
   opener.add_handler(klass())
 ssl_context = kw.get('ssl_context')
 if (HTTPSContextHandler not in skip):
  opener.add_handler(HTTPSContextHandler(ssl_context))
 for h in handlers:
  if isclass(h):
   h = h()
  opener.add_handler(h)
 return opener

def build_opener ( * handlers , ** kw ) : def isclass ( obj ) : return ( isinstance ( obj , class_type_ ) or hasattr ( obj , '__bases__' ) ) opener = OpenerDirector ( ) default_classes = [ ProxyHandler , UnknownHandler , HTTPHandler , HTTPDefaultErrorHandler , HTTPRedirectHandler , FTPHandler , FileHandler , HTTPErrorProcessor ] check_classes = list ( default_classes ) check_classes . append ( HTTPSContextHandler ) skip = [ ] for klass in check_classes : for check in handlers : if isclass ( check ) : if issubclass ( check , klass ) : skip . append ( klass ) elif isinstance ( check , klass ) : skip . append ( klass ) for klass in default_classes : if ( klass not in skip ) : opener . add_handler ( klass ( ) ) ssl_context = kw . get ( 'ssl_context' ) if ( HTTPSContextHandler not in skip ) : opener . add_handler ( HTTPSContextHandler ( ssl_context ) ) for h in handlers : if isclass ( h ) : h = h ( ) opener . add_handler ( h ) return opener
create an opener object from a list of handlers .