15
15
16
16
extern struct tgl_state * TLS ;
17
17
18
+ // TGL Python Exceptions
19
+ extern PyObject * TglError ;
20
+ extern PyObject * PeerError ;
21
+ extern PyObject * MsgError ;
22
+
18
23
//
19
24
// tgl_peer_t wrapper
20
25
//
@@ -42,7 +47,7 @@ tgl_Peer_init(tgl_Peer *self, PyObject *args, PyObject *kwds)
42
47
& peer_id .type ,
43
48
& peer_id .id ))
44
49
{
45
- PyErr_Format (PyErr_NewException ( "tgl.PeerInvalid" , NULL , NULL ) , "Peer must specify type and id" );
50
+ PyErr_Format (PeerError , "Peer must specify type and id" );
46
51
return -1 ;
47
52
}
48
53
self -> peer = tgl_peer_get (TLS , peer_id );
@@ -68,7 +73,7 @@ tgl_Peer_getname (tgl_Peer *self, void *closure)
68
73
ret = PyUnicode_FromString (self -> peer -> encr_chat .print_name );
69
74
break ;
70
75
default :
71
- PyErr_SetString (PyExc_TypeError , "peer.type_name not supported!" );
76
+ PyErr_SetString (PeerError , "peer.type_name not supported!" );
72
77
Py_RETURN_NONE ;
73
78
}
74
79
@@ -87,15 +92,15 @@ tgl_Peer_getuser_id (tgl_Peer *self, void *closure)
87
92
ret = PyLong_FromLong (self -> peer -> id .id );
88
93
break ;
89
94
case TGL_PEER_CHAT :
90
- PyErr_SetString (PyExc_TypeError , "peer.type_name == 'chat' has no user_id" );
95
+ PyErr_SetString (PeerError , "peer.type_name == 'chat' has no user_id" );
91
96
Py_RETURN_NONE ;
92
97
93
98
break ;
94
99
case TGL_PEER_ENCR_CHAT :
95
100
ret = PyLong_FromLong (self -> peer -> encr_chat .user_id );
96
101
break ;
97
102
default :
98
- PyErr_SetString (PyExc_TypeError , "peer.type_name not supported!" );
103
+ PyErr_SetString (PeerError , "peer.type_name not supported!" );
99
104
Py_RETURN_NONE ;
100
105
}
101
106
@@ -122,11 +127,11 @@ tgl_Peer_getuser_list (tgl_Peer *self, void *closure)
122
127
break ;
123
128
case TGL_PEER_ENCR_CHAT :
124
129
case TGL_PEER_USER :
125
- PyErr_SetString (PyExc_TypeError , "Only peer.type_name == 'chat' has user_list" );
130
+ PyErr_SetString (PeerError , "Only peer.type_name == 'chat' has user_list" );
126
131
Py_RETURN_NONE ;
127
132
break ;
128
133
default :
129
- PyErr_SetString (PyExc_TypeError , "peer.type_name not supported!" );
134
+ PyErr_SetString (PeerError , "peer.type_name not supported!" );
130
135
Py_RETURN_NONE ;
131
136
}
132
137
@@ -149,11 +154,11 @@ tgl_Peer_getuser_status(tgl_Peer *self, void *closure)
149
154
break ;
150
155
case TGL_PEER_CHAT :
151
156
case TGL_PEER_ENCR_CHAT :
152
- PyErr_SetString (PyExc_TypeError , "Only peer.type_name == 'user' has user_status" );
157
+ PyErr_SetString (PeerError , "Only peer.type_name == 'user' has user_status" );
153
158
Py_RETURN_NONE ;
154
159
break ;
155
160
default :
156
- PyErr_SetString (PyExc_TypeError , "peer.type_name not supported!" );
161
+ PyErr_SetString (PeerError , "peer.type_name not supported!" );
157
162
Py_RETURN_NONE ;
158
163
}
159
164
@@ -172,11 +177,11 @@ tgl_Peer_getphone (tgl_Peer *self, void *closure)
172
177
break ;
173
178
case TGL_PEER_CHAT :
174
179
case TGL_PEER_ENCR_CHAT :
175
- PyErr_SetString (PyExc_TypeError , "Only peer.type_name == 'user' has phone" );
180
+ PyErr_SetString (PeerError , "Only peer.type_name == 'user' has phone" );
176
181
Py_RETURN_NONE ;
177
182
break ;
178
183
default :
179
- PyErr_SetString (PyExc_TypeError , "peer.type_name not supported!" );
184
+ PyErr_SetString (PeerError , "peer.type_name not supported!" );
180
185
Py_RETURN_NONE ;
181
186
}
182
187
@@ -195,11 +200,11 @@ tgl_Peer_getusername (tgl_Peer *self, void *closure)
195
200
break ;
196
201
case TGL_PEER_CHAT :
197
202
case TGL_PEER_ENCR_CHAT :
198
- PyErr_SetString (PyExc_TypeError , "Only peer.type_name == 'user' has username" );
203
+ PyErr_SetString (PeerError , "Only peer.type_name == 'user' has username" );
199
204
Py_RETURN_NONE ;
200
205
break ;
201
206
default :
202
- PyErr_SetString (PyExc_TypeError , "peer.type_name not supported!" );
207
+ PyErr_SetString (PeerError , "peer.type_name not supported!" );
203
208
Py_RETURN_NONE ;
204
209
}
205
210
@@ -218,11 +223,11 @@ tgl_Peer_getfirst_name (tgl_Peer *self, void *closure)
218
223
break ;
219
224
case TGL_PEER_CHAT :
220
225
case TGL_PEER_ENCR_CHAT :
221
- PyErr_SetString (PyExc_TypeError , "Only peer.type_name == 'user' has first_name" );
226
+ PyErr_SetString (PeerError , "Only peer.type_name == 'user' has first_name" );
222
227
Py_RETURN_NONE ;
223
228
break ;
224
229
default :
225
- PyErr_SetString (PyExc_TypeError , "peer.type_name not supported!" );
230
+ PyErr_SetString (PeerError , "peer.type_name not supported!" );
226
231
Py_RETURN_NONE ;
227
232
}
228
233
@@ -241,11 +246,11 @@ tgl_Peer_getlast_name (tgl_Peer *self, void *closure)
241
246
break ;
242
247
case TGL_PEER_CHAT :
243
248
case TGL_PEER_ENCR_CHAT :
244
- PyErr_SetString (PyExc_TypeError , "Only peer.type_name == 'user' has last_name" );
249
+ PyErr_SetString (PeerError , "Only peer.type_name == 'user' has last_name" );
245
250
Py_RETURN_NONE ;
246
251
break ;
247
252
default :
248
- PyErr_SetString (PyExc_TypeError , "peer.type_name not supported!" );
253
+ PyErr_SetString (PeerError , "peer.type_name not supported!" );
249
254
Py_RETURN_NONE ;
250
255
}
251
256
@@ -266,11 +271,11 @@ tgl_Peer_getuser (tgl_Peer *self, void *closure)
266
271
ret = (PyObject * )self ;
267
272
break ;
268
273
case TGL_PEER_CHAT :
269
- PyErr_SetString (PyExc_TypeError , "Only peer.type_name == 'chat' does not have user" );
274
+ PyErr_SetString (PeerError , "Only peer.type_name == 'chat' does not have user" );
270
275
Py_RETURN_NONE ;
271
276
break ;
272
277
default :
273
- PyErr_SetString (PyExc_TypeError , "peer.type_name not supported!" );
278
+ PyErr_SetString (PeerError , "peer.type_name not supported!" );
274
279
Py_RETURN_NONE ;
275
280
}
276
281
@@ -448,7 +453,8 @@ tgl_Msg_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
448
453
static int
449
454
tgl_Msg_init (tgl_Msg * self , PyObject * args , PyObject * kwds )
450
455
{
451
- return 0 ;
456
+ PyErr_SetString (MsgError , "You cannot instantiate a tgl.Msg object, only the API can send them." );
457
+ return -1 ;
452
458
}
453
459
454
460
static PyObject *
0 commit comments