def auth_publickey(self, username, key, event=None):
if (not self.active) or (not self.initial_kex_done):<EOL><INDENT>raise SSHException('<STR_LIT>')<EOL><DEDENT>if event is None:<EOL><INDENT>my_event = threading.Event()<EOL><DEDENT>else:<EOL><INDENT>my_event = event<EOL><DEDENT>self.auth_handler = AuthHandler(self)<EOL>self.auth_handler.auth_publickey(username, key, my_event)<EOL>if event is not None:<EOL><INDENT>return []<EOL><DEDENT>return self.auth_handler.wait_for_response(my_event)<EOL>
Authenticate to the server using a private key.  The key is used to
sign data from the server, so it must include the private part.

If an C{event} is passed in, this method will return immediately, and
the event will be triggered once authentication succeeds or fails.  On
success, L{is_authenticated} will return C{True}.  On failure, you may
use L{get_exception} to get more detailed error information.

Since 1.1, if no event is passed, this method will block until the
authentication succeeds or fails.  On failure, an exception is raised.
Otherwise, the method simply returns.

If the server requires multi-step authentication (which is very rare),
this method will return a list of auth types permissible for the next
step.  Otherwise, in the normal case, an empty list is returned.

@param username: the username to authenticate as
@type username: string
@param key: the private key to authenticate with
@type key: L{PKey <pkey.PKey>}
@param event: an event to trigger when the authentication attempt is
    complete (whether it was successful or not)
@type event: threading.Event
@return: list of auth types permissible for the next stage of
    authentication (normally empty)
@rtype: list

@raise BadAuthenticationType: if public-key authentication isn't
    allowed by the server for this user (and no event was passed in)
@raise AuthenticationException: if the authentication failed (and no
    event was passed in)
@raise SSHException: if there was a network error