#NEWLINE# def __negotiatesocks4( self , destaddr , destport ) : #NEWLINE# #INDENT# '__negotiatesocks4(self,destaddr,destport)\n        Negotiates a connection through a SOCKS4 server.\n        ' #NEWLINE# rmtrslv = False #NEWLINE# try : #NEWLINE# #INDENT# ipaddr = socket . inet_aton ( destaddr ) #NEWLINE# #UNINDENT# except socket . error : #NEWLINE# #INDENT# if self . __proxy [ 3 ] : #NEWLINE# #INDENT# ipaddr = struct . pack ( 'BBBB' , 0 , 0 , 0 , 1 ) #NEWLINE# rmtrslv = True #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# ipaddr = socket . inet_aton ( socket . gethostbyname ( destaddr ) ) #NEWLINE# #UNINDENT# #UNINDENT# req = ( struct . pack ( '>BBH' , 4 , 1 , destport ) + ipaddr ) #NEWLINE# if ( self . __proxy [ 4 ] != None ) : #NEWLINE# #INDENT# req = ( req + self . __proxy [ 4 ] ) #NEWLINE# #UNINDENT# req = ( req + chr ( 0 ) . encode ( ) ) #NEWLINE# if rmtrslv : #NEWLINE# #INDENT# req = ( ( req + destaddr ) + chr ( 0 ) . encode ( ) ) #NEWLINE# #UNINDENT# self . sendall ( req ) #NEWLINE# resp = self . __recvall ( 8 ) #NEWLINE# if ( ipaddr [ 0 : 1 ] != chr ( 0 ) . encode ( ) ) : #NEWLINE# #INDENT# self . close ( ) #NEWLINE# raise GeneralProxyError ( ( 1 , _generalerrors [ 1 ] ) ) #NEWLINE# #UNINDENT# if ( resp [ 1 : 2 ] != chr ( 90 ) . encode ( ) ) : #NEWLINE# #INDENT# self . close ( ) #NEWLINE# if ( ord ( resp [ 1 : 2 ] ) in ( 91 , 92 , 93 ) ) : #NEWLINE# #INDENT# self . close ( ) #NEWLINE# raise Socks4Error ( ( ord ( resp [ 1 : 2 ] ) , _socks4errors [ ( ord ( resp [ 1 : 2 ] ) - 90 ) ] ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise Socks4Error ( ( 94 , _socks4errors [ 4 ] ) ) #NEWLINE# #UNINDENT# #UNINDENT# self . __proxysockname = ( socket . inet_ntoa ( resp [ 4 : ] ) , struct . unpack ( '>H' , resp [ 2 : 4 ] ) [ 0 ] ) #NEWLINE# if ( rmtrslv != None ) : #NEWLINE# #INDENT# self . __proxypeername = ( socket . inet_ntoa ( ipaddr ) , destport ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# self . __proxypeername = ( destaddr , destport )