original_docstring: __negotiatesocks5(self,destaddr,destport)
  		Negotiates a connection through a SOCKS5 server.
  		
docstring: negotiatesocks5(self,destaddr,destport)
  Negotiates a connection through a SOCKS5 server.
docstring_tokens: negotiatesocks5 ( self destaddr destport ) Negotiates a connection through a SOCKS5 server .
code: def __negotiatesocks5(self,destaddr,destport):
  		"""__negotiatesocks5(self,destaddr,destport)
  		Negotiates a connection through a SOCKS5 server.
  		"""
  		# First we'll send the authentication packages we support.
  		if (self.__proxy[4]!=None) and (self.__proxy[5]!=None):
  			# The username/password details were supplied to the
  			# setproxy method so we support the USERNAME/PASSWORD
  			# authentication (in addition to the standard none).
  			self.sendall("\x05\x02\x00\x02")
  		else:
  			# No username/password were entered, therefore we
  			# only support connections with no authentication.
  			self.sendall("\x05\x01\x00")
  		# We'll receive the server's response to determine which
  		# method was selected
  		chosenauth = self.__recvall(2)
  		if chosenauth[0] != "\x05":
  			self.close()
  			raise GeneralProxyError((1,_generalerrors[1]))
  		# Check the chosen authentication method
  		if chosenauth[1] == "\x00":
  			# No authentication is required
  			pass
  		elif chosenauth[1] == "\x02":
  			# Okay, we need to perform a basic username/password
  			# authentication.
  			self.sendall("\x01" + chr(len(self.__proxy[4])) + self.__proxy[4] + chr(len(self.proxy[5])) + self.__proxy[5])
  			authstat = self.__recvall(2)
  			if authstat[0] != "\x01":
  				# Bad response
  				self.close()
  				raise GeneralProxyError((1,_generalerrors[1]))
  			if authstat[1] != "\x00":
  				# Authentication failed
  				self.close()
  				raise Socks5AuthError,((3,_socks5autherrors[3]))
  			# Authentication succeeded
  		else:
  			# Reaching here is always bad
  			self.close()
  			if chosenauth[1] == "\xFF":
  				raise Socks5AuthError((2,_socks5autherrors[2]))
  			else:
  				raise GeneralProxyError((1,_generalerrors[1]))
  		# Now we can request the actual connection
  		req = "\x05\x01\x00"
  		# If the given destination address is an IP address, we'll
  		# use the IPv4 address request even if remote resolving was specified.
  		try:
  			ipaddr = socket.inet_aton(destaddr)
  			req = req + "\x01" + ipaddr
  		except socket.error:
  			# Well it's not an IP number,  so it's probably a DNS name.
  			if self.__proxy[3]==True:
  				# Resolve remotely
  				ipaddr = None
  				req = req + "\x03" + chr(len(destaddr)) + destaddr
  			else:
  				# Resolve locally
  				ipaddr = socket.inet_aton(socket.gethostbyname(destaddr))
  				req = req + "\x01" + ipaddr
  		req = req + struct.pack(">H",destport)
  		self.sendall(req)
  		# Get the response
  		resp = self.__recvall(4)
  		if resp[0] != "\x05":
  			self.close()
  			raise GeneralProxyError((1,_generalerrors[1]))
  		elif resp[1] != "\x00":
  			# Connection failed
  			self.close()
  			if ord(resp[1])<=8:
  				raise Socks5Error(ord(resp[1]),_generalerrors[ord(resp[1])])
  			else:
  				raise Socks5Error(9,_generalerrors[9])
  		# Get the bound address/port
  		elif resp[3] == "\x01":
  			boundaddr = self.__recvall(4)
  		elif resp[3] == "\x03":
  			resp = resp + self.recv(1)
  			boundaddr = self.__recvall(resp[4])
  		else:
  			self.close()
  			raise GeneralProxyError((1,_generalerrors[1]))
  		boundport = struct.unpack(">H",self.__recvall(2))[0]
  		self.__proxysockname = (boundaddr,boundport)
  		if ipaddr != None:
  			self.__proxypeername = (socket.inet_ntoa(ipaddr),destport)
  		else:
  			self.__proxypeername = (destaddr,destport)
code_tokens: def __negotiatesocks5 ( self , destaddr , destport ) : if ( self . __proxy [ 4 ] != None ) and ( self . __proxy [ 5 ] != None ) : self . sendall ( "\x05\x02\x00\x02" ) else : self . sendall ( "\x05\x01\x00" ) chosenauth = self . __recvall ( 2 ) if chosenauth [ 0 ] != "\x05" : self . close ( ) raise GeneralProxyError ( ( 1 , _generalerrors [ 1 ] ) ) if chosenauth [ 1 ] == "\x00" : pass elif chosenauth [ 1 ] == "\x02" : self . sendall ( "\x01" + chr ( len ( self . __proxy [ 4 ] ) ) + self . __proxy [ 4 ] + chr ( len ( self . proxy [ 5 ] ) ) + self . __proxy [ 5 ] ) authstat = self . __recvall ( 2 ) if authstat [ 0 ] != "\x01" : self . close ( ) raise GeneralProxyError ( ( 1 , _generalerrors [ 1 ] ) ) if authstat [ 1 ] != "\x00" : self . close ( ) raise Socks5AuthError , ( ( 3 , _socks5autherrors [ 3 ] ) ) else : self . close ( ) if chosenauth [ 1 ] == "\xFF" : raise Socks5AuthError ( ( 2 , _socks5autherrors [ 2 ] ) ) else : raise GeneralProxyError ( ( 1 , _generalerrors [ 1 ] ) ) req = "\x05\x01\x00" try : ipaddr = socket . inet_aton ( destaddr ) req = req + "\x01" + ipaddr except socket . error : if self . __proxy [ 3 ] == True : ipaddr = None req = req + "\x03" + chr ( len ( destaddr ) ) + destaddr else : ipaddr = socket . inet_aton ( socket . gethostbyname ( destaddr ) ) req = req + "\x01" + ipaddr req = req + struct . pack ( ">H" , destport ) self . sendall ( req ) resp = self . __recvall ( 4 ) if resp [ 0 ] != "\x05" : self . close ( ) raise GeneralProxyError ( ( 1 , _generalerrors [ 1 ] ) ) elif resp [ 1 ] != "\x00" : self . close ( ) if ord ( resp [ 1 ] ) <= 8 : raise Socks5Error ( ord ( resp [ 1 ] ) , _generalerrors [ ord ( resp [ 1 ] ) ] ) else : raise Socks5Error ( 9 , _generalerrors [ 9 ] ) elif resp [ 3 ] == "\x01" : boundaddr = self . __recvall ( 4 ) elif resp [ 3 ] == "\x03" : resp = resp + self . recv ( 1 ) boundaddr = self . __recvall ( resp [ 4 ] ) else : self . close ( ) raise GeneralProxyError ( ( 1 , _generalerrors [ 1 ] ) ) boundport = struct . unpack ( ">H" , self . __recvall ( 2 ) ) [ 0 ] self . __proxysockname = ( boundaddr , boundport ) if ipaddr != None : self . __proxypeername = ( socket . inet_ntoa ( ipaddr ) , destport ) else : self . __proxypeername = ( destaddr , destport )
short_docstring: __negotiatesocks5(self,destaddr,destport)
  Negotiates a connection through a SOCKS5 server.
short_docstring_tokens: __negotiatesocks5 ( self destaddr destport ) Negotiates a connection through a SOCKS5 server .
comment: """__negotiatesocks5(self,destaddr,destport)
  		Negotiates a connection through a SOCKS5 server.
  		"""$SEP$# First we'll send the authentication packages we support.
  $SEP$# The username/password details were supplied to the
  $SEP$# setproxy method so we support the USERNAME/PASSWORD
  $SEP$# authentication (in addition to the standard none).
  $SEP$# No username/password were entered, therefore we
  $SEP$# only support connections with no authentication.
  $SEP$# We'll receive the server's response to determine which
  $SEP$# method was selected
  $SEP$# Check the chosen authentication method
  $SEP$# No authentication is required
  $SEP$# Okay, we need to perform a basic username/password
  $SEP$# authentication.
  $SEP$# Bad response
  $SEP$# Authentication failed
  $SEP$# Authentication succeeded
  $SEP$# Reaching here is always bad
  $SEP$# Now we can request the actual connection
  $SEP$# If the given destination address is an IP address, we'll
  $SEP$# use the IPv4 address request even if remote resolving was specified.
  $SEP$# Well it's not an IP number,  so it's probably a DNS name.
  $SEP$# Resolve remotely
  $SEP$# Resolve locally
  $SEP$# Get the response
  $SEP$# Connection failed
  $SEP$# Get the bound address/port
  