def read(self, size=<NUM_LIT:0>):
res = self.unread<EOL>self.unread = "<STR_LIT>"<EOL>while res == "<STR_LIT>" or size < <NUM_LIT:0> or (size > <NUM_LIT:0> and len(res) < size):<EOL><INDENT>try:<EOL><INDENT>res += compat.to_native(self.queue.get(True, <NUM_LIT:0.1>))<EOL><DEDENT>except compat.queue.Empty:<EOL><INDENT>if self.is_closed:<EOL><INDENT>break<EOL><DEDENT><DEDENT><DEDENT>if size > <NUM_LIT:0> and len(res) > size:<EOL><INDENT>self.unread = res[size:]<EOL>res = res[:size]<EOL><DEDENT>return res<EOL>
Read a chunk of bytes from queue.

        size = 0: Read next chunk (arbitrary length)
             > 0: Read one chunk of `size` bytes (or less if stream was closed)
             < 0: Read all bytes as single chunk (i.e. blocks until stream is closed)

        This method blocks until the requested size become available.
        However, if close() was called, '' is returned immediately.