@classmethod<EOL><INDENT>def wrap(cls, socket, hostname, session=None):<DEDENT>
if not isinstance(socket, socket_.socket):<EOL><INDENT>raise TypeError(pretty_message(<EOL>'''<STR_LIT>''',<EOL>type_name(socket)<EOL>))<EOL><DEDENT>if not isinstance(hostname, str_cls):<EOL><INDENT>raise TypeError(pretty_message(<EOL>'''<STR_LIT>''',<EOL>type_name(hostname)<EOL>))<EOL><DEDENT>if session is not None and not isinstance(session, TLSSession):<EOL><INDENT>raise TypeError(pretty_message(<EOL>'''<STR_LIT>''',<EOL>type_name(session)<EOL>))<EOL><DEDENT>new_socket = cls(None, None, session=session)<EOL>new_socket._socket = socket<EOL>new_socket._hostname = hostname<EOL>new_socket._handshake()<EOL>return new_socket<EOL>
Takes an existing socket and adds TLS

:param socket:
    A socket.socket object to wrap with TLS

:param hostname:
    A unicode string of the hostname or IP the socket is connected to

:param session:
    An existing TLSSession object to allow for session reuse, specific
    protocol or manual certificate validation

:raises:
    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