#!/usr/bin/python
#
# $Id: error.py,v 1.1.1.1 2009-12-02 06:54:14 jloden Exp $
#

# Base Traverse error class
class TVError(Exception):
    """TVError exception is base exception for all Traverse API exceptions."""
    def __init__(self, reason):
        self.reason = reason

    def __str__(self):
        return repr(self.reason)

    def getMessage(self):
        """return the exception reason string."""
        return self.reason

# SimpleServerClient errors
class InvalidCommand(TVError):
    """InvalidCommand raised when a command format cannot be parsed correctly."""
    pass

# SocketIO errors
class SocketError(TVError):
    """SocketError exception, base class for SocketIO exceptions."""
    pass

class NotConnectedError(SocketError):
    """
    NotConnectedError exception, raised when no connection to a BVE API
    server is found.
    """

    # set default message for NotConnectedError exceptions
    def __init__(self, reason="Not connected to a socket server"):
        self.reason = reason

class SocketReadError(SocketError):
    """SocketReadError exception, raised when reading data fails."""
    pass

class SocketSendError(SocketError):
    """SocketSendError exception, raised when sending data fails."""
    pass

# SocketServer
class ResponseError(SocketError):
    """ResponseError raised when unable to parse an API response."""
    pass

class LoginFailure(TVError):
    """LoginFailure raised when unable to log into the SocketServer."""
    pass

# backward compatibility only
NVError = TVError
