Skip to content
This repository was archived by the owner on Apr 12, 2018. It is now read-only.

Commit 26c9480

Browse files
committed
Merge branch 'develop'
2 parents acc8624 + 76d8152 commit 26c9480

File tree

1 file changed

+52
-3
lines changed

1 file changed

+52
-3
lines changed

swf/exceptions.py

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,59 @@
55
#
66
# See the file LICENSE for copying permission.
77

8+
89
class SWFError(Exception):
9-
def __init__(self, message, raw_error, *args):
10-
Exception.__init__(self, message, *args)
11-
self.kind, self.details = raw_error.split(':')
10+
def __init__(self, message, raw_error='', *args, **kwargs):
11+
"""
12+
Examples:
13+
14+
>>> error = SWFError('message')
15+
>>> error.message
16+
'message'
17+
>>> error.details
18+
''
19+
>>> error = SWFError('message', 'kind')
20+
>>> error.message
21+
'message'
22+
>>> error.kind
23+
'kind'
24+
>>> error.details
25+
''
26+
>>> error = SWFError('message', 'kind:')
27+
>>> error.message
28+
'message'
29+
>>> error.kind
30+
'kind'
31+
>>> error.details
32+
''
33+
>>> error = SWFError('message', 'kind:details')
34+
>>> error.message
35+
'message'
36+
>>> error.kind
37+
'kind'
38+
>>> error.details
39+
'details'
40+
>>> error = SWFError('message', 'kind: details ')
41+
>>> error.message
42+
'message'
43+
>>> error.kind
44+
'kind'
45+
>>> error.details
46+
'details'
47+
48+
"""
49+
Exception.__init__(self, message, *args, **kwargs)
50+
51+
values = raw_error.split(':', 1)
52+
53+
if len(values) == 2:
54+
self.details = values[1].strip()
55+
else:
56+
self.details = ''
57+
58+
self.kind = values[0].strip()
59+
self.type_ = (self.kind.lower().strip().replace(' ', '_') if
60+
self.kind else None)
1261

1362
def __repr__(self):
1463
msg = self.message

0 commit comments

Comments
 (0)