parameters: (self)
docstring: Makes a handshake  after connect and before any other calls.
docstring_summary: Makes a handshake  after connect and before any other calls.
docstring_tokens: Makes a handshake after connect and before any other calls .
function: def handshake(self):
      """Makes a handshake  after connect and before any other calls."""
      msg_len = 8
  
      if self.username is None:
        msg_len += 1
      else:
        msg_len += 5 + len(self.username)
  
      if self.password is None:
        msg_len += 1
      else:
        msg_len += 5 + len(self.password)
  
      self.write_int(msg_len)  # Message length
      self.write_byte(1)  # Handshake operation
      self.write_short(1)  # Version (1.1.0)
      self.write_short(1)
      self.write_short(0)
      self.write_byte(2)  # Thin client
  
      if self.username is None:  # Username
        self.write_byte(101)
      else:
        self.write_byte(9)
        self.write_int(len(self.username))
        self.write_string(self.username)
  
      if self.password is None:  # Password
        self.write_byte(101)
      else:
        self.write_byte(9)
        self.write_int(len(self.password))
        self.write_string(self.password)
  
      self.read_int()  # Result length
      res = self.read_byte()
  
      if res != 1:
        serv_ver_major = self.read_short()
        serv_ver_minor = self.read_short()
        serv_ver_patch = self.read_short()
        err_msg = self._parse_string()
        if err_msg is None:
          raise RuntimeError(
              "Handshake Error [result=%d, version=%d.%d.%d]" %
              (res, serv_ver_major, serv_ver_minor, serv_ver_patch))
        else:
          raise RuntimeError(
              "Handshake Error [result=%d, version=%d.%d.%d, message='%s']" %
              (res, serv_ver_major, serv_ver_minor, serv_ver_patch, err_msg))
function_tokens: def handshake ( self ) : msg_len = 8 if self . username is None : msg_len += 1 else : msg_len += 5 + len ( self . username ) if self . password is None : msg_len += 1 else : msg_len += 5 + len ( self . password ) self . write_int ( msg_len ) # Message length self . write_byte ( 1 ) # Handshake operation self . write_short ( 1 ) # Version (1.1.0) self . write_short ( 1 ) self . write_short ( 0 ) self . write_byte ( 2 ) # Thin client if self . username is None : # Username self . write_byte ( 101 ) else : self . write_byte ( 9 ) self . write_int ( len ( self . username ) ) self . write_string ( self . username ) if self . password is None : # Password self . write_byte ( 101 ) else : self . write_byte ( 9 ) self . write_int ( len ( self . password ) ) self . write_string ( self . password ) self . read_int ( ) # Result length res = self . read_byte ( ) if res != 1 : serv_ver_major = self . read_short ( ) serv_ver_minor = self . read_short ( ) serv_ver_patch = self . read_short ( ) err_msg = self . _parse_string ( ) if err_msg is None : raise RuntimeError ( "Handshake Error [result=%d, version=%d.%d.%d]" % ( res , serv_ver_major , serv_ver_minor , serv_ver_patch ) ) else : raise RuntimeError ( "Handshake Error [result=%d, version=%d.%d.%d, message='%s']" % ( res , serv_ver_major , serv_ver_minor , serv_ver_patch , err_msg ) )