Skip to content

Commit af9f7b6

Browse files
committed
Use a simple version of repr for Python < 2.7.9
This is due to a bug http://bugs.python.org/issue22023 This addresses #587
1 parent ce2debc commit af9f7b6

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

‎python-types.c

+9-4
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#include "python-tg.h"
2020

2121
extern struct tgl_state *TLS;
22-
2322
// TGL Python Exceptions
2423
extern PyObject *TglError;
2524
extern PyObject *PeerError;
@@ -944,14 +943,18 @@ tgl_Peer_repr(tgl_Peer *self)
944943

945944
switch(self->peer->id.type) {
946945
case TGL_PEER_USER:
947-
ret = PyUnicode_FromFormat("<tgl.Peer: type=user, id=%ld, username=%R, name=%R, first_name=%R, last_name=%R, phone=%R>",
946+
#if PY_VERSION_HEX < 0x02070900
947+
ret = PyUnicode_FromFormat("<tgl.Peer: id=%ld>", self->peer->id.id);
948+
#else
949+
ret = PyUnicode_FromFormat("<tgl.Peer: type=user, id=%ld, username=%R, name=%R, first_name=%R, last_name=%R, phone=%R>",
948950
self->peer->id.id,
949951
PyObject_GetAttrString((PyObject*)self, "username"),
950952
PyObject_GetAttrString((PyObject*)self, "name"),
951953
PyObject_GetAttrString((PyObject*)self, "first_name"),
952954
PyObject_GetAttrString((PyObject*)self, "last_name"),
953955
PyObject_GetAttrString((PyObject*)self, "phone")
954956
);
957+
#endif
955958
break;
956959
case TGL_PEER_CHAT:
957960
ret = PyUnicode_FromFormat("<tgl.Peer: type=chat, id=%ld, name=%s>",
@@ -1423,7 +1426,9 @@ static PyObject *
14231426
tgl_Msg_repr(tgl_Msg *self)
14241427
{
14251428
PyObject *ret;
1426-
1429+
#if PY_VERSION_HEX < 0x02070900
1430+
ret = PyUnicode_FromFormat("<tgl.Msg id=%ld>", self->msg->id);
1431+
#else
14271432
ret = PyUnicode_FromFormat("<tgl.Msg id=%ld, flags=%d, mention=%R, out=%R, unread=%R, service=%R, src=%R, "
14281433
"dest=%R, text=%R, media=%R, date=%R, fwd_src=%R, fwd_date=%R, reply_id=%R, reply=%R>",
14291434
self->msg->id, self->msg->flags,
@@ -1441,7 +1446,7 @@ tgl_Msg_repr(tgl_Msg *self)
14411446
PyObject_GetAttrString((PyObject*)self, "reply_id"),
14421447
PyObject_GetAttrString((PyObject*)self, "reply")
14431448
);
1444-
1449+
#endif
14451450
return ret;
14461451
}
14471452

0 commit comments

Comments
 (0)