33from calendar import timegm
44import rfc822
55import time
6+ from sets import Set
67
78from twitter import json , Hashtag , TwitterError , Url
9+ from twitter .media import Media
810
911
1012class Status (object ):
@@ -118,7 +120,8 @@ def __init__(self, **kwargs):
118120 'media' : None ,
119121 'withheld_copyright' : None ,
120122 'withheld_in_countries' : None ,
121- 'withheld_scope' : None }
123+ 'withheld_scope' : None ,
124+ }
122125
123126 for (param , default ) in param_defaults .iteritems ():
124127 setattr (self , param , kwargs .get (param , default ))
@@ -400,19 +403,19 @@ def __str__(self):
400403 return self .AsJsonString ()
401404
402405 def __repr__ (self ):
403- """A string representation of this twitter.Status instance.
406+ """A string representation of this twitter.Status instance.
404407 The return value is the ID of status, username and datetime.
405408 Returns:
406409 A string representation of this twitter.Status instance with
407410 the ID of status, username and datetime.
408411 """
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
412+ if self .user :
413+ representation = "Status(ID=%s, screen_name='%s', created_at='%s')" % (
414+ self .id , self .user .screen_name , self .created_at )
415+ else :
416+ representation = "Status(ID=%s, created_at='%s')" % (
417+ self .id , self .created_at )
418+ return representation
416419
417420 def AsJsonString (self , allow_non_ascii = False ):
418421 """A JSON string representation of this twitter.Status instance.
@@ -525,7 +528,7 @@ def NewFromJsonDict(data):
525528 urls = None
526529 user_mentions = None
527530 hashtags = None
528- media = None
531+ media = Set ()
529532 if 'entities' in data :
530533 if 'urls' in data ['entities' ]:
531534 urls = [Url .NewFromJsonDict (u ) for u in data ['entities' ]['urls' ]]
@@ -536,14 +539,14 @@ def NewFromJsonDict(data):
536539 if 'hashtags' in data ['entities' ]:
537540 hashtags = [Hashtag .NewFromJsonDict (h ) for h in data ['entities' ]['hashtags' ]]
538541 if 'media' in data ['entities' ]:
539- media = data ['entities' ]['media' ]
540- else :
541- media = []
542+ for m in data ['entities' ]['media' ]:
543+ media .add (Media .NewFromJsonDict (m ))
542544
543545 # the new extended entities
544546 if 'extended_entities' in data :
545547 if 'media' in data ['extended_entities' ]:
546- media = [m for m in data ['extended_entities' ]['media' ]]
548+ for m in data ['extended_entities' ]['media' ]:
549+ media .add (Media .NewFromJsonDict (m ))
547550
548551 return Status (created_at = data .get ('created_at' , None ),
549552 favorited = data .get ('favorited' , None ),
@@ -574,4 +577,5 @@ def NewFromJsonDict(data):
574577 scopes = data .get ('scopes' , None ),
575578 withheld_copyright = data .get ('withheld_copyright' , None ),
576579 withheld_in_countries = data .get ('withheld_in_countries' , None ),
577- withheld_scope = data .get ('withheld_scope' , None ))
580+ withheld_scope = data .get ('withheld_scope' , None ),
581+ )
0 commit comments