Package musicbrainz2 :: Module utils
[frames | no frames]

Module musicbrainz2.utils

Various utilities to simplify common tasks.

This module contains helper functions to make common tasks easier.

Author: Matthias Friedrich <matt@mafr.de>

Function Summary
  extractFragment(uriStr, uriPrefix)
Extract the fragment part from a URI.
  extractUuid(uriStr, resType)
Extract the UUID part from a MusicBrainz identifier.
  getCountryName(id_)
Returns a country's name based on an ISO-3166 country code.
  getLanguageName(id_)
Returns a language name based on an ISO-639-2/T code.
  getReleaseTypeName(releaseType)
Returns the name of a release type URI.
  getScriptName(id_)
Returns a script name based on an ISO-15924 code.

Function Details

extractFragment(uriStr, uriPrefix=None)

Extract the fragment part from a URI.

If uriStr is None or no absolute URI, then it is returned unchanged.

The uriPrefix parameter can be used for error checking. If uriStr is an absolute URI, then the function checks if it starts with uriPrefix. If it doesn't, a ValueError exception is raised.
Parameters:
uriStr - a string containing an absolute URI
uriPrefix - a string containing an URI prefix
Returns:
a string containing the fragment, or None
Raises:
ValueError - the given URI doesn't start with uriPrefix

extractUuid(uriStr, resType=None)

Extract the UUID part from a MusicBrainz identifier.

This function takes a MusicBrainz ID (an absolute URI) as the input and returns the UUID part of the URI, thus turning it into a relative URI. If uriStr is None or a relative URI, then it is returned unchanged.

The resType parameter can be used for error checking. Set it to 'artist', 'release', or 'track' to make sure uriStr is a syntactically valid MusicBrainz identifier of the given resource type. If it isn't, a ValueError exception is raised. This error checking only works if uriStr is an absolute URI, of course.

Example:
>>> from musicbrainz2.utils import extractUuid
>>>  extractUuid('http://musicbrainz.org/artist/c0b2500e-0cef-4130-869d-732b23ed9df5', 'artist')
'c0b2500e-0cef-4130-869d-732b23ed9df5'

>>>
Parameters:
uriStr - a string containing a MusicBrainz ID (an URI), or None
resType - a string containing a resource type
Returns:
a string containing a relative URI, or None
Raises:
ValueError - the given URI is no valid MusicBrainz ID

getCountryName(id_)

Returns a country's name based on an ISO-3166 country code.

The country table this function is based on has been modified for MusicBrainz purposes by using the extension mechanism defined in ISO-3166. All IDs are still valid ISO-3166 country codes, but some IDs have been added to include historic countries and some of the country names have been modified to make them better suited for display purposes.

If the country ID is not found, None is returned. This may happen for example, when new countries are added to the MusicBrainz web service which aren't known to this library yet.
Parameters:
id_ - a two-letter upper case string containing an ISO-3166 code
Returns:
a string containing the country's name, or None

See Also: musicbrainz2.model

getLanguageName(id_)

Returns a language name based on an ISO-639-2/T code.

This function uses a subset of the ISO-639-2/T code table to map language IDs (terminologic, not bibliographic ones!) to names.
Parameters:
id_ - a three-letter upper case string containing an ISO-639-2/T code
Returns:
a string containing the language's name, or None

See Also: musicbrainz2.model

getReleaseTypeName(releaseType)

Returns the name of a release type URI.
Parameters:
releaseType - a string containing a release type URI
Returns:
a string containing a printable name for the release type

See Also: musicbrainz2.model.Release

getScriptName(id_)

Returns a script name based on an ISO-15924 code.

This function uses a subset of the ISO-15924 code table to map script IDs to names.
Parameters:
id_ - a four-letter string containing an ISO-15924 script code
Returns:
a string containing the script's name, or None

See Also: musicbrainz2.model


Generated by Epydoc 2.1 on Sat Aug 26 18:34:31 2006 http://epydoc.sf.net