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

Module decorators

source code

Module containting the decorators used in the package


Version: 0.2

Author: Abhinav Sarkar <abhinav@abhinavsarkar.net>

License: GNU Lesser General Public License

Functions [hide private]
property
top_property(list_property_name)
A decorator to return a property that returns the first value of list attribute corresponding to the provided list property name.
source code
property
cached_property(func)
A decorator to cache the atrribute of the object.
source code
function
authenticate(func)
A decorator to check if the current user is authenticated or not.
source code
Variables [hide private]
  __package__ = 'lastfm'

Imports: copy, LastfmError, AuthenticationFailedError


Function Details [hide private]

top_property(list_property_name)

source code 

A decorator to return a property that returns the first value of list attribute corresponding to the provided list property name.

For example, if the list property is top_albums, then the decorator returns a property that returns the first (top most) album.

Parameters:
  • list_property_name (str) - the name of the list property. Like 'top_albums'.
Returns: property
a property that returns the first value of list attribute corresponding to the provided list property name

cached_property(func)

source code 

A decorator to cache the atrribute of the object. When called for the first time, the value of the attribute is retrived and saved in an instance variable. Later calls return the copy of the cached value, so that the original cached value cannot be modified.

Parameters:
  • func (function) - the getter function of the attribute
Returns: property
a property that wraps the getter function of the attribute

authenticate(func)

source code 

A decorator to check if the current user is authenticated or not. Used only on the functions that need authentication. If not authenticated then an exception is raised.

Parameters:
  • func (function) - a function that needs to be authentication, for being called
Returns: function
a function that wraps the original function
Raises: