def recv(self): """Receive packets from the socket """ try: return self.buffer.popleft() except IndexError: pass pktnr = -1 try: buf = self.sock.recv(self.recvsize) while buf: totalsize = len(buf) if pktnr == -1 and totalsize > 4: pktsize = utils.intread(buf[0:3]) pktnr = utils.intread(buf[3]) if pktnr > -1 and totalsize >= pktsize+4: size = pktsize+4 self.buffer.append(buf[0:size]) buf = buf[size:] pktnr = -1 if len(buf) == 0: break elif len(buf) < pktsize+4: buf += self.sock.recv(self.recvsize) except socket.timeout, e: raise errors.InterfaceError(errno=2013)
def recv(self): """Receive packets from the socket """ try: return self.buffer.popleft() except IndexError: pass pktnr = -1 try: buf = self.sock.recv(self.recvsize) while buf: totalsize = len(buf) if pktnr == -1 and totalsize > 4: pktsize = utils.intread(buf[0:3]) pktnr = utils.intread(buf[3]) if pktnr > -1 and totalsize >= pktsize + 4: size = pktsize + 4 self.buffer.append(buf[0:size]) buf = buf[size:] pktnr = -1 if len(buf) == 0: break elif len(buf) < pktsize + 4: buf += self.sock.recv(self.recvsize) except socket.timeout, e: raise errors.InterfaceError(errno=2013)
def _scramble_password(self, passwd, seed): """Scramble a password ready to send to MySQL""" hash4 = None try: hash1 = sha1(passwd).digest() hash2 = sha1(hash1).digest() # Password as found in mysql.user() hash3 = sha1(seed + hash2).digest() xored = [ utils.intread(h1) ^ utils.intread(h3) for (h1,h3) in zip(hash1, hash3) ] hash4 = struct.pack('20B', *xored) except Exception, e: raise errors.InterfaceError('Failed scrambling password; %s' % e)