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  from lastfm.decorators import cached_property
    10
    11 -class Shout(LastfmBase, Cacheable):
    12      """A class representing a shout."""
    13
    14 -    def init(self,
    15               body = None,
    16               author = None,
    17               date = None,
    18               **kwargs):
    19          self._body = body
    20          self._author = author
    21          self._date = date
    22
    23      @cached_property
    24 -    def body(self):
    25          return self._body
    26
    27      @cached_property
    28 -    def author(self):
    29          return self._author
    30
    31      @cached_property
    32 -    def date(self):
    33          return self._date
    34
    35      @staticmethod
    36 -    def _hash_func(*args, **kwds):
    37          try:
    38              return hash("%s%s" % (kwds['body'], kwds['author']))
    39          except KeyError:
    40              raise InvalidParametersError("body and author have to be provided for hashing")
    41
    42 -    def __hash__(self):
    43          return self.__class__._hash_func(body = self.body, author = self.author)
    44
    45 -    def __eq__(self, other):
    46          return (
    47                  self.body == other.body and
    48                  self.author == other.author
    49              )
    50
    51 -    def __lt__(self, other):
    52          if self.author != other.author:
    53              return self.author < other.author
    54          else:
    55              if self.date != other.date:
    56                  return self.date < other.date
    57              else:
    58                  return self.body < other.body
    59
    60 -    def __repr__(self):
    61          return "<lastfm.Shout: '%s' by %s>" % (self.body, self.author.name)
    62
    63  from lastfm.error import InvalidParametersError
    64