1
|
|
|
# -*- coding: utf-8 -*- |
2
|
|
|
from __future__ import absolute_import, unicode_literals |
3
|
|
|
import six |
4
|
|
|
|
5
|
|
|
from school_api.utils import to_text, to_binary |
6
|
|
|
|
7
|
|
|
|
8
|
|
|
class SchoolException(Exception): |
9
|
|
|
"""Base exception for school-api""" |
10
|
|
|
|
11
|
|
|
def __init__(self, name, school_code, errmsg): |
12
|
|
|
self.name = name |
13
|
|
|
self.errmsg = errmsg |
14
|
|
|
self.school_code = school_code |
15
|
|
|
|
16
|
|
|
def __repr__(self): |
17
|
|
|
_repr = 'school_code:{school_code}, Error message: {name},{msg}'.format( |
18
|
|
|
school_code=self.school_code, |
19
|
|
|
name=self.name, |
20
|
|
|
msg=self.errmsg |
21
|
|
|
) |
22
|
|
|
msg = to_binary(_repr) if six.PY2 else to_text(_repr) |
23
|
|
|
return msg |
24
|
|
|
|
25
|
|
|
def __str__(self): |
26
|
|
|
_repr = '{msg}'.format( |
27
|
|
|
msg=self.errmsg |
28
|
|
|
) |
29
|
|
|
msg = to_binary(_repr) if six.PY2 else to_text(_repr) |
30
|
|
|
return msg |
31
|
|
|
|
32
|
|
|
|
33
|
|
|
class LoginException(SchoolException): |
34
|
|
|
|
35
|
|
|
def __init__(self, school_code, errmsg): |
36
|
|
|
super(LoginException, self).__init__('登录接口', school_code, errmsg) |
37
|
|
|
|
38
|
|
|
|
39
|
|
|
class IdentityException(LoginException): |
40
|
|
|
pass |
41
|
|
|
|
42
|
|
|
|
43
|
|
|
class CheckCodeException(LoginException): |
44
|
|
|
pass |
45
|
|
|
|
46
|
|
|
|
47
|
|
|
class ScheduleException(SchoolException): |
48
|
|
|
|
49
|
|
|
def __init__(self, school_code, errmsg): |
50
|
|
|
super(ScheduleException, self).__init__('课表接口', school_code, errmsg) |
51
|
|
|
|
52
|
|
|
|
53
|
|
|
class ScoreException(SchoolException): |
54
|
|
|
|
55
|
|
|
def __init__(self, school_code, errmsg): |
56
|
|
|
super(ScoreException, self).__init__('成绩接口', school_code, errmsg) |
57
|
|
|
|
58
|
|
|
|
59
|
|
|
class UserInfoException(SchoolException): |
60
|
|
|
|
61
|
|
|
def __init__(self, school_code, errmsg): |
62
|
|
|
super(UserInfoException, self).__init__('用户信息接口', school_code, errmsg) |
63
|
|
|
|
64
|
|
|
|
65
|
|
|
class PermissionException(SchoolException): |
66
|
|
|
|
67
|
|
|
def __init__(self, school_code, errmsg): |
68
|
|
|
super(PermissionException, self).__init__('接口权限', school_code, errmsg) |
69
|
|
|
|
70
|
|
|
|
71
|
|
|
class OtherException(SchoolException): |
72
|
|
|
|
73
|
|
|
def __init__(self, school_code, errmsg): |
74
|
|
|
super(OtherException, self).__init__('Other', school_code, errmsg) |
75
|
|
|
|