<s> try : <EOL> from urllib . error import URLError <EOL> import urllib . request as urllib_compat <EOL> except ( ImportError ) : <EOL> from urllib2 import URLError <EOL> import urllib2 as urllib_compat <EOL> try : <EOL> import ssl <EOL> from . validating_https_connection import ValidatingHTTPSConnection <EOL> from . invalid_certificate_exception import InvalidCertificateException <EOL> from . persistent_handler import PersistentHandler <EOL> if hasattr ( urllib_compat , '<STR_LIT>' ) : <EOL> class ValidatingHTTPSHandler ( PersistentHandler , urllib_compat . HTTPSHandler ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , ** kwargs ) : <EOL> self . _debuglevel = <NUM_LIT:0> <EOL> if '<STR_LIT>' in kwargs and kwargs [ '<STR_LIT>' ] : <EOL> self . _debuglevel = <NUM_LIT:5> <EOL> elif '<STR_LIT>' in kwargs : <EOL> self . _debuglevel = kwargs [ '<STR_LIT>' ] <EOL> self . _connection_args = kwargs <EOL> def https_open ( self , req ) : <EOL> def http_class_wrapper ( host , ** kwargs ) : <EOL> full_kwargs = dict ( self . _connection_args ) <EOL> full_kwargs . update ( kwargs ) <EOL> return ValidatingHTTPSConnection ( host , ** full_kwargs ) <EOL> try : <EOL> return self . do_open ( http_class_wrapper , req ) <EOL> except URLError as e : <EOL> if type ( e . reason ) == ssl . SSLError and e . reason . args [ <NUM_LIT:0> ] == <NUM_LIT:1> : <EOL> raise InvalidCertificateException ( req . host , '<STR_LIT>' , <EOL> e . reason . args [ <NUM_LIT:1> ] ) <EOL> raise <EOL> https_request = urllib_compat . AbstractHTTPHandler . do_request_ <EOL> else : <EOL> raise ImportError ( ) <EOL> except ( ImportError ) as e : <EOL> class ValidatingHTTPSHandler ( ) : <EOL> def __init__ ( self , ** kwargs ) : <EOL> raise e </s>
