Package echonest :: Package web :: Module util
[hide private]
[frames] | no frames]

Module util

source code

Utility functions to support the Echo Nest web API interface. This module is not meant for other uses and should not be used unless modifying or extending the package.

Version: $Revision: 0 $

Classes [hide private]
  EchoNestAPIError
Generic API errors.
  EchoNestAPIKeyError
An Error returned by the API regarding the API Key.
  EchoNestAPIThingIDError
An Error returned by the API regarding the ThingID.
Functions [hide private]
 
apiFunctionPrototype(method, id)
This function is the basis for most of the 'get_xxx' functions in this package.
source code
call graph 
 
parseXMLString(xmlString)
This function is meant to modularize the handling of XML strings returned by the web API.
source code
call graph 
 
postChunked(host, selector, fields, files)
Attempt to replace postMultipart() with nearly-identical interface.
source code
 
postMultipart(host, selector, fields, files)
Adapted from http://code.activestate.com/recipes/146306/ .
source code
 
encodeMultipartFormdata(fields, files)
Adapted from http://code.activestate.com/recipes/146306/ .
source code
 
getContentType(filename)
Adapted from http://code.activestate.com/recipes/146306/ .
source code
Variables [hide private]
  SUCCESS_STATUS_CODES = (0)
  FAILURE_THING_ID_STATUS_CODES = (7, 6)
  FAILURE_API_KEY_STATUS_CODES = (12)
Function Details [hide private]

parseXMLString(xmlString)

source code 
call graph 
This function is meant to modularize the handling of XML strings returned by the web API. Overriding this method will change how the entire package parses XML strings.
Parameters:
  • xmlString - The plaintext string of XML to parse.
Returns:
An object representation of the XML string, in this case a xml.dom.minidom representation.

postChunked(host, selector, fields, files)

source code 

Attempt to replace postMultipart() with nearly-identical interface. (The files tuple no longer requires the filename, and we only return the response body.) Uses the urllib2_file.py originally from http://fabien.seisen.org which was also drawn heavily from http://code.activestate.com/recipes/146306/ .

This urllib2_file.py is more desirable because of the chunked uploading from a file pointer (no need to read entire file into memory) and the ability to work from behind a proxy (due to its basis on urllib2).

postMultipart(host, selector, fields, files)

source code 

Adapted from http://code.activestate.com/recipes/146306/ .

Post fields and files to an http host as multipart/form-data. fields is a sequence of (name, value) elements for regular form fields. files is a sequence of (name, filename, value) elements for data to be uploaded as files Return the server's response page.

encodeMultipartFormdata(fields, files)

source code 

Adapted from http://code.activestate.com/recipes/146306/ .

fields is a sequence of (name, value) elements for regular form fields. files is a sequence of (name, filename, value) elements for data to be uploaded as files Return (content_type, body) ready for httplib.HTTP instance