def read(self, max_length):
if not isinstance(max_length, int_types):<EOL><INDENT>raise TypeError(pretty_message(<EOL>'''<STR_LIT>''',<EOL>type_name(max_length)<EOL>))<EOL><DEDENT>if self._session_context is None:<EOL><INDENT>if self._decrypted_bytes != b'<STR_LIT>':<EOL><INDENT>output = self._decrypted_bytes<EOL>self._decrypted_bytes = b'<STR_LIT>'<EOL>return output<EOL><DEDENT>self._raise_closed()<EOL><DEDENT>buffered_length = len(self._decrypted_bytes)<EOL>if buffered_length >= max_length:<EOL><INDENT>output = self._decrypted_bytes[<NUM_LIT:0>:max_length]<EOL>self._decrypted_bytes = self._decrypted_bytes[max_length:]<EOL>return output<EOL><DEDENT>if buffered_length > <NUM_LIT:0> and not self.select_read(<NUM_LIT:0>):<EOL><INDENT>output = self._decrypted_bytes<EOL>self._decrypted_bytes = b'<STR_LIT>'<EOL>return output<EOL><DEDENT>to_read = max_length - len(self._decrypted_bytes)<EOL>read_buffer = buffer_from_bytes(to_read)<EOL>processed_pointer = new(Security, '<STR_LIT>')<EOL>result = Security.SSLRead(<EOL>self._session_context,<EOL>read_buffer,<EOL>to_read,<EOL>processed_pointer<EOL>)<EOL>if self._exception is not None:<EOL><INDENT>exception = self._exception<EOL>self._exception = None<EOL>raise exception<EOL><DEDENT>if result and result not in set([SecurityConst.errSSLWouldBlock, SecurityConst.errSSLClosedGraceful]):<EOL><INDENT>handle_sec_error(result, TLSError)<EOL><DEDENT>if result and result == SecurityConst.errSSLClosedGraceful:<EOL><INDENT>self._gracefully_closed = True<EOL>self._shutdown(False)<EOL>self._raise_closed()<EOL><DEDENT>bytes_read = deref(processed_pointer)<EOL>output = self._decrypted_bytes + bytes_from_buffer(read_buffer, bytes_read)<EOL>self._decrypted_bytes = output[max_length:]<EOL>return output[<NUM_LIT:0>:max_length]<EOL>
Reads data from the TLS-wrapped socket

:param max_length:
    The number of bytes to read - output may be less than this

:raises:
    socket.socket - when a non-TLS socket error occurs
    oscrypto.errors.TLSError - when a TLS-related error occurs
    oscrypto.errors.TLSDisconnectError - when the connection disconnects
    oscrypto.errors.TLSGracefulDisconnectError - when the remote end gracefully closed the connection
    ValueError - when any of the parameters contain an invalid value
    TypeError - when any of the parameters are of the wrong type
    OSError - when an error is returned by the OS crypto library

:return:
    A byte string of the data read