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

Add __repr__ for status #246

Merged
merged 2 commits into from
Sep 25, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions tests/test_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,7 @@ def testNewFromJsonDict(self):
data = json.loads(StatusTest.SAMPLE_JSON)
status = twitter.Status.NewFromJsonDict(data)
self.assertEqual(self._GetSampleStatus(), status)

def testStatusRepresentation(self):
status = self._GetSampleStatus()
self.assertEqual("Status(ID=4391023, screen_name='kesuke', created_at='Fri Jan 26 23:17:14 +0000 2007')", status.__repr__())
15 changes: 15 additions & 0 deletions twitter/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,21 @@ def __str__(self):
"""
return self.AsJsonString()

def __repr__(self):
"""A string representation of this twitter.Status instance.
The return value is the ID of status, username and datetime.
Returns:
A string representation of this twitter.Status instance with
the ID of status, username and datetime.
"""
if self.user:
representation = "Status(ID=%s, screen_name='%s', created_at='%s')" % (
self.id, self.user.screen_name, self.created_at)
else:
representation = "Status(ID=%s, created_at='%s')" % (
self.id, self.created_at)
return representation

def AsJsonString(self, allow_non_ascii=False):
"""A JSON string representation of this twitter.Status instance.
To output non-ascii, set keyword allow_non_ascii=True.
Expand Down