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

Source Code for Module lastfm.base

 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 -class LastfmBase(object):
8 """Base class for all the classes in this package""" 9 10 @staticmethod
11 - def top_property(list_property_name):
12 def decorator(func): 13 def wrapper(ob): 14 top_list = getattr(ob, list_property_name) 15 return (len(top_list) and top_list[0] or None)
16 return property(fget = wrapper, doc = func.__doc__)
17 return decorator 18 19 @staticmethod
20 - def cached_property(func):
21 func_name = func.func_code.co_name 22 attribute_name = "_%s" % func_name 23 24 def wrapper(ob): 25 cache_attribute = getattr(ob, attribute_name, None) 26 if cache_attribute is None: 27 cache_attribute = func(ob) 28 setattr(ob, attribute_name, cache_attribute) 29 try: 30 cp = copy.copy(cache_attribute) 31 return cp 32 except LastfmError: 33 return cache_attribute
34 35 return property(fget = wrapper, doc = func.__doc__) 36 37 @staticmethod
38 - def autheticate(func):
39 def wrapper(self, *args, **kwargs): 40 from lastfm.user import User 41 user = None 42 if isinstance(self, User): 43 user = self.name 44 if self.autheticated: 45 return func(self, *args, **kwargs) 46 elif hasattr(self, 'user'): 47 user = self.user.name 48 if self.user.autheticated: 49 return func(self, *args, **kwargs) 50 51 raise AuthenticationFailedError( 52 "user '%s' does not have permissions to access the service" % user)
53 return wrapper 54
55 - def __gt__(self, other):
56 return not (self.__lt__(other) or self.__eq(other))
57
58 - def __ne__(self, other):
59 return not self.__eq__(other)
60
61 - def __ge__(self, other):
62 return not self.__lt__(other)
63
64 - def __le__(self, other):
65 return not self.__gt__(other)
66 67 import copy 68 from lastfm.error import LastfmError, AuthenticationFailedError 69