Merged in sileht/wsme/sileht/unicode-clientsideerror (pull request #16)

Support unicode message in ClientSideError
This commit is contained in:
Christophe de Vienne 2013-08-11 16:10:13 +02:00
commit 22787cd8d0
2 changed files with 18 additions and 9 deletions

View File

@ -5,19 +5,24 @@ from wsme.utils import _
class ClientSideError(RuntimeError):
def __init__(self, msg=None):
super(ClientSideError, self).__init__(msg if msg else self.faultstring)
self.msg = msg
super(ClientSideError, self).__init__(self.faultstring)
@property
def faultstring(self):
if self.msg is None:
return str(self)
elif isinstance(self.msg, six.text_type):
return self.msg
else:
return six.u(self.msg)
class InvalidInput(ClientSideError):
def __init__(self, fieldname, value, msg=''):
self.fieldname = fieldname
self.value = value
self.msg = msg
super(InvalidInput, self).__init__()
super(InvalidInput, self).__init__(msg)
@property
def faultstring(self):
@ -29,8 +34,7 @@ class InvalidInput(ClientSideError):
class MissingArgument(ClientSideError):
def __init__(self, argname, msg=''):
self.argname = argname
self.msg = msg
super(MissingArgument, self).__init__()
super(MissingArgument, self).__init__(msg)
@property
def faultstring(self):
@ -41,8 +45,7 @@ class MissingArgument(ClientSideError):
class UnknownArgument(ClientSideError):
def __init__(self, argname, msg=''):
self.argname = argname
self.msg = msg
super(UnknownArgument, self).__init__()
super(UnknownArgument, self).__init__(msg)
@property
def faultstring(self):

View File

@ -7,7 +7,13 @@ from six import u
def test_clientside_error():
e = ClientSideError("Test")
assert e.faultstring == "Test"
assert e.faultstring == u("Test")
def test_unicode_clientside_error():
e = ClientSideError(u("\u30d5\u30a1\u30b7\u30ea"))
assert e.faultstring == u("\u30d5\u30a1\u30b7\u30ea")
def test_invalidinput():