Created
August 10, 2011 18:30
-
-
Save sampsyo/1137717 to your computer and use it in GitHub Desktop.
making MusicBrainz getters using templates
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def _make_id_getter(entity): | |
def getter(id, **kwargs): | |
includes = [] | |
for name in kwargs: | |
if not name.startswith('inc_'): | |
raise TypeError('got unexpected keyword argument...') | |
elif kwargs[name]: | |
includes.append(name[4:]) | |
return _do_mb_query(entity, id, includes) | |
getter.__name__ = 'get_%s_by_id' % entity | |
getter.__doc__ = """Fetches a %s given its MBID. Possible keyword | |
arguments specifying includes: | |
%s | |
""" % (entity, '\n'.join(['inc_' + i for i in VALID_INCLUDES[entity]])) | |
return getter | |
get_artist_by_id = _make_id_getter('artist') | |
get_label_by_id = _make_id_getter('label') | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment