<s> """<STR_LIT>""" <EOL> __author__ = "<STR_LIT>" <EOL> __date__ = "<STR_LIT>" <EOL> __copyright__ = "<STR_LIT>" <EOL> __license__ = "<STR_LIT>" <EOL> __contact__ = "<STR_LIT>" <EOL> __revision__ = '<STR_LIT>' <EOL> import logging <EOL> import sys <EOL> if sys . version_info [ <NUM_LIT:0> ] > <NUM_LIT:2> : <EOL> class_type_ = type <EOL> from urllib . request import ( ProxyHandler , UnknownHandler , <EOL> HTTPDefaultErrorHandler , FTPHandler , <EOL> FileHandler , HTTPErrorProcessor , <EOL> HTTPHandler , OpenerDirector , <EOL> HTTPRedirectHandler ) <EOL> else : <EOL> import types <EOL> class_type_ = types . ClassType <EOL> from urllib2 import ( ProxyHandler , UnknownHandler , HTTPDefaultErrorHandler , <EOL> FTPHandler , FileHandler , HTTPErrorProcessor , <EOL> HTTPHandler , OpenerDirector , HTTPRedirectHandler ) <EOL> from ndg . httpsclient . https import HTTPSContextHandler <EOL> log = logging . getLogger ( __name__ ) <EOL> def build_opener ( * handlers , ** kw ) : <EOL> """<STR_LIT>""" <EOL> def isclass ( obj ) : <EOL> return isinstance ( obj , class_type_ ) or hasattr ( obj , "<STR_LIT>" ) <EOL> opener = OpenerDirector ( ) <EOL> default_classes = [ ProxyHandler , UnknownHandler , HTTPHandler , <EOL> HTTPDefaultErrorHandler , HTTPRedirectHandler , <EOL> FTPHandler , FileHandler , HTTPErrorProcessor ] <EOL> check_classes = list ( default_classes ) <EOL> check_classes . append ( HTTPSContextHandler ) <EOL> skip = [ ] <EOL> for klass in check_classes : <EOL> for check in handlers : <EOL> if isclass ( check ) : <EOL> if issubclass ( check , klass ) : <EOL> skip . append ( klass ) <EOL> elif isinstance ( check , klass ) : <EOL> skip . append ( klass ) <EOL> for klass in default_classes : <EOL> if klass not in skip : <EOL> opener . add_handler ( klass ( ) ) <EOL> ssl_context = kw . get ( '<STR_LIT>' ) <EOL> if HTTPSContextHandler not in skip : <EOL> opener . add_handler ( HTTPSContextHandler ( ssl_context ) ) <EOL> for h in handlers : <EOL> if isclass ( h ) : <EOL> h = h ( ) <EOL> opener . add_handler ( h ) <EOL> return opener </s>
