Skip to content
This repository was archived by the owner on Aug 7, 2024. It is now read-only.

Commit 17f6500

Browse files
committed
Merge pull request #246 from era/master
Add __repr__ for status
2 parents 63df9d9 + e063e57 commit 17f6500

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

tests/test_status.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,7 @@ def testNewFromJsonDict(self):
117117
data = json.loads(StatusTest.SAMPLE_JSON)
118118
status = twitter.Status.NewFromJsonDict(data)
119119
self.assertEqual(self._GetSampleStatus(), status)
120+
121+
def testStatusRepresentation(self):
122+
status = self._GetSampleStatus()
123+
self.assertEqual("Status(ID=4391023, screen_name='kesuke', created_at='Fri Jan 26 23:17:14 +0000 2007')", status.__repr__())

twitter/status.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,21 @@ def __str__(self):
399399
"""
400400
return self.AsJsonString()
401401

402+
def __repr__(self):
403+
"""A string representation of this twitter.Status instance.
404+
The return value is the ID of status, username and datetime.
405+
Returns:
406+
A string representation of this twitter.Status instance with
407+
the ID of status, username and datetime.
408+
"""
409+
if self.user:
410+
representation = "Status(ID=%s, screen_name='%s', created_at='%s')" % (
411+
self.id, self.user.screen_name, self.created_at)
412+
else:
413+
representation = "Status(ID=%s, created_at='%s')" % (
414+
self.id, self.created_at)
415+
return representation
416+
402417
def AsJsonString(self, allow_non_ascii=False):
403418
"""A JSON string representation of this twitter.Status instance.
404419
To output non-ascii, set keyword allow_non_ascii=True.

0 commit comments

Comments
 (0)