Package lastfm :: Module shout
[hide private]
[frames] | no frames]

Source Code for Module lastfm.shout

 1  #!/usr/bin/env python 
 2   
 3  __author__ = "Abhinav Sarkar <abhinav@abhinavsarkar.net>" 
 4  __version__ = "0.2" 
 5  __license__ = "GNU Lesser General Public License" 
 6   
 7  from lastfm.base import LastfmBase 
 8  from lastfm.mixins import Cacheable 
9 10 -class Shout(LastfmBase, Cacheable):
11 """A class representing a shout.""" 12
13 - def init(self, 14 body = None, 15 author = None, 16 date = None):
17 self._body = body 18 self._author = author 19 self._date = date
20 21 @LastfmBase.cached_property
22 - def body(self):
23 return self._body
24 25 @LastfmBase.cached_property
26 - def author(self):
27 return self._author
28 29 @LastfmBase.cached_property
30 - def date(self):
31 return self._date
32 33 @staticmethod
34 - def _hash_func(*args, **kwds):
35 try: 36 return hash("%s%s" % (kwds['body'], kwds['author'])) 37 except KeyError: 38 raise InvalidParametersError("body and author have to be provided for hashing")
39
40 - def __hash__(self):
41 return self.__class__._hash_func(body = self.body, author = self.author)
42
43 - def __eq__(self, other):
44 return ( 45 self.body == other.body and 46 self.author == other.author 47 )
48
49 - def __lt__(self, other):
50 if self.author != other.author: 51 return self.author < other.author 52 else: 53 if self.date != other.date: 54 return self.date < other.date 55 else: 56 return self.body < other.body
57
58 - def __repr__(self):
59 return "<lastfm.Shout: '%s' by %s>" % (self.body, self.author.name)
60 61 from lastfm.error import InvalidParametersError 62