Skip to content
Snippets Groups Projects
Commit 84ee2aea authored by Henrik tom Wörden's avatar Henrik tom Wörden
Browse files

MAINT: whitespace changes

parent 42183bc2
Branches
Tags
No related merge requests found
......@@ -72,6 +72,7 @@ class ServerErrorException(CaosDBException):
xml = etree.fromstring(body)
error = xml.xpath('/Response/Error')[0]
msg = error.get("description")
if error.text is not None:
msg = msg + "\n\n" + error.text
CaosDBException.__init__(self, msg)
......@@ -114,15 +115,18 @@ class TransactionError(CaosDBException):
def _calc_bases(self):
types = dict()
# collect each class once
for err in self.errors:
types[id(type(err))] = type(err)
# delete redundant super classes
if len(types.values()) > 1:
# remove TransactionError
try:
del types[id(TransactionError)]
except KeyError:
pass
if len(types.values()) > 1:
# remove EntityError
try:
......@@ -131,10 +135,13 @@ class TransactionError(CaosDBException):
pass
ret = ()
for t in types.values():
ret += (t,)
if ret == ():
ret = (type(self),)
return ret
def __init__(self, container=None, error=None, msg=None):
......@@ -145,6 +152,7 @@ class TransactionError(CaosDBException):
def print_errs(self):
print(self)
for err in self.errors:
err.print_errs()
......@@ -158,6 +166,7 @@ class TransactionError(CaosDBException):
newinstance = newtype(container=self.container, error=self.msg)
newinstance.errors = self.errors
newinstance.get_entities = self.get_entities
return newinstance
def get_container(self):
......@@ -165,6 +174,7 @@ class TransactionError(CaosDBException):
@return: The container that raised this TransactionError during the last
transaction.
'''
return self.container
def add_error(self, error):
......@@ -177,12 +187,15 @@ class TransactionError(CaosDBException):
@return: self.
"""
if hasattr(error, "__iter__"):
for e in error:
self.add_error(e)
return self
elif isinstance(error, TransactionError):
self.errors.append(error)
return self
else:
raise TypeError(
......@@ -192,17 +205,21 @@ class TransactionError(CaosDBException):
'''
@return: A list of all EntityError objects.
'''
if hasattr(self, 'errors'):
return self.errors
return None
def _repr_reasons(self, indent):
if self.get_errors() is not None and len(self.get_errors()) > 0:
ret = "\n" + indent + " +--| REASONS |--"
for c in self.get_errors():
ret += '\n' + indent + ' | -> ' + \
c.__str__(indent=indent + ' |')
ret += "\n" + indent + " +----------------"
return ret
else:
return ''
......@@ -214,6 +231,7 @@ class TransactionError(CaosDBException):
def __str__(self, indent=''):
ret = self._repr_head(indent=indent)
ret += self._repr_reasons(indent=indent)
return ret
def __repr__(self):
......@@ -224,8 +242,10 @@ class TransactionError(CaosDBException):
@return: A list of all Entity objects with errors.
'''
ret = []
if hasattr(self, 'get_entity') and self.get_entity() is not None:
ret.append(self.get_entity())
for error in self.errors:
if hasattr(error, 'get_entity'):
if error.get_entity() not in ret:
......@@ -247,10 +267,12 @@ class EntityError(TransactionError):
if len(t) > 1:
ret = ()
'''remove EntityError'''
for i in range(len(t)):
if t[i] != EntityError:
ret += (t[i],)
t = ret
return t
def _convert(self):
......@@ -260,12 +282,14 @@ class EntityError(TransactionError):
setattr(newinstance, 'msg', self.msg)
setattr(newinstance, 'errors', self.errors)
setattr(newinstance, 'container', self.container)
return newinstance
def __init__(self, error=None, container=None, entity=None):
TransactionError.__init__(self, container=container)
self.error = error
self.entity = entity
if error is not None and hasattr(error, "encode"):
self.msg = error
elif error is not None and hasattr(error, 'description'):
......@@ -279,8 +303,10 @@ class EntityError(TransactionError):
'''
@return: The entity that caused this error.
'''
if hasattr(self, 'entity'):
return self.entity
return None
@property
......@@ -294,6 +320,7 @@ class EntityError(TransactionError):
'''
@return: Error Message object of this Error.
'''
return self.error
def _repr_head(self, indent):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment