#NEWLINE# def getUrlFd( url , headers = None , data = None , timeout = None ) : #NEWLINE# #INDENT# "getUrlFd(url, headers=None, data=None, timeout=None)\n\n    Opens the given url and returns a file object.  Headers and data are\n    a dict and string, respectively, as per urllib.request.Request's\n    arguments." #NEWLINE# if ( headers is None ) : #NEWLINE# #INDENT# headers = defaultHeaders #NEWLINE# #UNINDENT# if ( minisix . PY3 and isinstance ( data , str ) ) : #NEWLINE# #INDENT# data = data . encode ( ) #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# if ( not isinstance ( url , Request ) ) : #NEWLINE# #INDENT# ( scheme , loc , path , query , frag ) = urlsplit ( url ) #NEWLINE# ( user , host ) = splituser ( loc ) #NEWLINE# url = urlunsplit ( ( scheme , host , path , query , '' ) ) #NEWLINE# request = Request ( url , headers = headers , data = data ) #NEWLINE# if user : #NEWLINE# #INDENT# request . add_header ( 'Authorization' , ( 'Basic %s' % base64 . b64encode ( user ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# request = url #NEWLINE# request . add_data ( data ) #NEWLINE# #UNINDENT# httpProxy = force ( proxy ) #NEWLINE# if httpProxy : #NEWLINE# #INDENT# request . set_proxy ( httpProxy , 'http' ) #NEWLINE# #UNINDENT# fd = urlopen ( request , timeout = timeout ) #NEWLINE# return fd #NEWLINE# #UNINDENT# except socket . timeout as e : #NEWLINE# #INDENT# raise Error ( TIMED_OUT ) #NEWLINE# #UNINDENT# except sockerrors as e : #NEWLINE# #INDENT# raise Error ( strError ( e ) ) #NEWLINE# #UNINDENT# except InvalidURL as e : #NEWLINE# #INDENT# raise Error ( ( 'Invalid URL: %s' % e ) ) #NEWLINE# #UNINDENT# except HTTPError as e : #NEWLINE# #INDENT# raise Error ( strError ( e ) ) #NEWLINE# #UNINDENT# except URLError as e : #NEWLINE# #INDENT# raise Error ( strError ( e . reason ) ) #NEWLINE# #UNINDENT# except ValueError as e : #NEWLINE# #INDENT# raise Error ( strError ( e ) )