Package musicbrainz2 :: Module webservice :: Class WebService

[frames] | no frames]

# Class WebService

source code

     object --+
              |
    IWebService --+
                  |
                 WebService

An interface to the MusicBrainz XML web service via HTTP.

By default, this class uses the MusicBrainz server but may be configured for accessing other servers as well using the constructor. This implements IWebService, so additional documentation on method parameters can be found there.

Instance Methods

__init__(self, host=`'``musicbrainz.org``'`, port=80, pathPrefix=`'``/ws``'`, username=None, password=None, realm=`'``musicbrainz.org``'`, opener=None, userAgent=None) Constructor. | source code

get(self, entity, id_, include=`(``)`, filter=`{``}`, version=`'``1``'`) Query the web service via HTTP-GET. | source code

post(self, entity, id_, data, version=`'``1``'`) Send data to the web service via HTTP-POST. | source code

Inherited from `object`: `__delattr__`, `__format__`, `__getattribute__`, `__hash__`, `__new__`, `__reduce__`, `__reduce_ex__`, `__repr__`, `__setattr__`, `__sizeof__`, `__str__`, `__subclasshook__`

Properties
Inherited from `object`: `__class__`

Method Details

### __init__(self, host=`'``musicbrainz.org``'`, port=80, pathPrefix=`'``/ws``'`, username=None, password=None, realm=`'``musicbrainz.org``'`, opener=None, userAgent=None)
(Constructor)

source code

Constructor.

This can be used without parameters. In this case, the MusicBrainz server will be used.

Parameters:
  - `host` - a string containing a host name
  - `port` - an integer containing a port number
  - `pathPrefix` - a string prepended to all URLs
  - `username` - a string containing a MusicBrainz user name
  - `password` - a string containing the user's password
  - `realm` - a string containing the realm used for authentication
  - `opener` - an `urllib2.OpenerDirector` object used for queries
  - `userAgent` - a string containing the user agent
Overrides: object.__init__

### get(self, entity, id_, include=`(``)`, filter=`{``}`, version=`'``1``'`)

source code

Query the web service via HTTP-GET.

Returns a file-like object containing the result or raises a WebServiceError. Conditions leading to errors may be invalid entities, IDs, `include` or `filter` parameters and unsupported version numbers.

Parameters:
  - `entity` - a string containing the entity's name
  - `id_` - a string containing a UUID, or the empty string
  - `include` - a tuple containing values for the 'inc' parameter
  - `filter` - parameters, depending on the entity
  - `version` - a string containing the web service version to use
Returns:
  a file-like object
Raises:
  - `ConnectionError` - couldn't connect to server
  - `RequestError` - invalid IDs or parameters
  - `AuthenticationError` - invalid user name and/or password
  - `ResourceNotFoundError` - resource doesn't exist
Overrides: IWebService.get

See Also: IWebService.get

### post(self, entity, id_, data, version=`'``1``'`)

source code

Send data to the web service via HTTP-POST.

Note that this may require authentication. You can set user name, password and realm in the constructor.

Parameters:
  - `entity` - a string containing the entity's name
  - `id_` - a string containing a UUID, or the empty string
  - `data` - A string containing the data to post
  - `version` - a string containing the web service version to use
Returns:
  a file-like object
Raises:
  - `ConnectionError` - couldn't connect to server
  - `RequestError` - invalid IDs or parameters
  - `AuthenticationError` - invalid user name and/or password
  - `ResourceNotFoundError` - resource doesn't exist
Overrides: IWebService.post

See Also: IWebService.post