Skip to content

Commit

Permalink
improve exceptions to take message, et al.
Browse files Browse the repository at this point in the history
  • Loading branch information
choppsv1 committed Apr 8, 2016
1 parent fc1313a commit 72b7988
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
31 changes: 19 additions & 12 deletions netconf/error.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ def get_error_info (self):
def get_error_severity (self):
return self._get_error_val("error-severity")

# RFC6241

# error-type
RPCERR_TYPE_TRANSPORT = 0
RPCERR_TYPE_RPC = 1
Expand Down Expand Up @@ -135,33 +137,38 @@ def __init__ (self, origmsg):


class RPCSvrInvalidValue (RPCServerError):
def __init__ (self, origmsg):
RPCServerError.__init__(self, origmsg, RPCERR_TYPE_RPC, RPCERR_TAG_INVALID_VALUE)
def __init__ (self, origmsg, **kwargs):
RPCServerError.__init__(self, origmsg, RPCERR_TYPE_RPC, RPCERR_TAG_INVALID_VALUE, **kwargs)


class RPCSvrMissingElement (RPCServerError):
def __init__ (self, origmsg, element):
RPCServerError.__init__(self, origmsg, RPCERR_TYPE_RPC, RPCERR_TAG_MISSING_ELEMENT, info=element.tag)
def __init__ (self, origmsg, tag, **kwargs):
try:
# Old API had this as an element...
tag = tag.tag
except AttributeError:
pass
RPCServerError.__init__(self, origmsg, RPCERR_TYPE_RPC, RPCERR_TAG_MISSING_ELEMENT, info=tag, **kwargs)


class RPCSvrBadElement (RPCServerError):
def __init__ (self, origmsg, element):
RPCServerError.__init__(self, origmsg, RPCERR_TYPE_RPC, RPCERR_TAG_BAD_ELEMENT, info=element.tag)
def __init__ (self, origmsg, element, **kwargs):
RPCServerError.__init__(self, origmsg, RPCERR_TYPE_RPC, RPCERR_TAG_BAD_ELEMENT, info=element.tag, **kwargs)


class RPCSvrUnknownElement (RPCServerError):
def __init__ (self, origmsg, element):
RPCServerError.__init__(self, origmsg, RPCERR_TYPE_RPC, RPCERR_TAG_UNKNOWN_ELEMENT, info=element.tag)
def __init__ (self, origmsg, element, **kwargs):
RPCServerError.__init__(self, origmsg, RPCERR_TYPE_RPC, RPCERR_TAG_UNKNOWN_ELEMENT, info=element.tag, **kwargs)


class RPCSvrErrNotImpl (RPCServerError):
def __init__ (self, origmsg):
RPCServerError.__init__(self, origmsg, RPCERR_TYPE_PROTOCOL, RPCERR_TAG_OPERATION_NOT_SUPPORTED)
def __init__ (self, origmsg, **kwargs):
RPCServerError.__init__(self, origmsg, RPCERR_TYPE_PROTOCOL, RPCERR_TAG_OPERATION_NOT_SUPPORTED, **kwargs)


class RPCSvrException (RPCServerError):
def __init__ (self, origmsg, exception):
RPCServerError.__init__(self, origmsg, RPCERR_TYPE_PROTOCOL, RPCERR_TAG_OPERATION_FAILED, info=str(exception))
def __init__ (self, origmsg, exception, **kwargs):
RPCServerError.__init__(self, origmsg, RPCERR_TYPE_PROTOCOL, RPCERR_TAG_OPERATION_FAILED, info=str(exception), **kwargs)

__author__ = 'Christian Hopps'
__date__ = 'February 19 2015'
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def read(fname):
return open(os.path.join(os.path.dirname(__file__), fname)).read()

setup (name='netconf',
version='0.4.0',
version='0.4.1',
description='Netconf Client/Server Library',
long_description=read("README.rst"),
author='Christian E. Hopps',
Expand Down

0 comments on commit 72b7988

Please sign in to comment.