def read_all(self, n, check_rekey=False):
out = '<STR_LIT>'<EOL>if len(self.__remainder) > <NUM_LIT:0>:<EOL><INDENT>out = self.__remainder[:n]<EOL>self.__remainder = self.__remainder[n:]<EOL>n -= len(out)<EOL><DEDENT>if PY22:<EOL><INDENT>return self._py22_read_all(n, out)<EOL><DEDENT>while n > <NUM_LIT:0>:<EOL><INDENT>got_timeout = False<EOL>try:<EOL><INDENT>x = self.__socket.recv(n)<EOL>if len(x) == <NUM_LIT:0>:<EOL><INDENT>raise EOFError()<EOL><DEDENT>out += x<EOL>n -= len(x)<EOL><DEDENT>except socket.timeout:<EOL><INDENT>got_timeout = True<EOL><DEDENT>except socket.error as e:<EOL><INDENT>if (type(e.args) is tuple) and (len(e.args) > <NUM_LIT:0>) and (e.args[<NUM_LIT:0>] == errno.EAGAIN):<EOL><INDENT>got_timeout = True<EOL><DEDENT>elif (type(e.args) is tuple) and (len(e.args) > <NUM_LIT:0>) and (e.args[<NUM_LIT:0>] == errno.EINTR):<EOL><INDENT>pass<EOL><DEDENT>elif self.__closed:<EOL><INDENT>raise EOFError()<EOL><DEDENT>else:<EOL><INDENT>raise<EOL><DEDENT><DEDENT>if got_timeout:<EOL><INDENT>if self.__closed:<EOL><INDENT>raise EOFError()<EOL><DEDENT>if check_rekey and (len(out) == <NUM_LIT:0>) and self.__need_rekey:<EOL><INDENT>raise NeedRekeyException()<EOL><DEDENT>self._check_keepalive()<EOL><DEDENT><DEDENT>return out<EOL>
Read as close to N bytes as possible, blocking as long as necessary.

@param n: number of bytes to read
@type n: int
@return: the data read
@rtype: str
@raise EOFError: if the socket was closed before all the bytes could
    be read