suds based www SOAP backend (tendril.utils.www.soap)

TODO Some introduction

class tendril.utils.www.soap.ThrottledTransport(**kwargs)[source]

Bases: suds.transport.http.HttpAuthenticated

Provides a throttled HTTP transport for respecting rate limits on rate-restricted SOAP APIs using suds.

This class is a suds.transport.Transport subclass based on the default HttpAuthenticated transport.

Parameters

minimum_spacing (int) – Minimum number of seconds between requests. Default 0.

Todo

Use redis or so to coordinate between threads to allow a maximum requests per hour/day limit.

send(request)[source]

Send a request and return the response. If the minimum number of seconds between requests have not yet elapsed, then the function sleeps for the remaining period and then passes the request along.

class tendril.utils.www.soap.CachedTransport(**kwargs)[source]

Bases: tendril.utils.www.caching.CacheBase, suds.transport.http.HttpAuthenticated

Provides a cached HTTP transport with request-based caching for SOAP APIs using suds.

This is a subclass of CacheBase and the default HttpAuthenticated transport.

Parameters
  • cache_dir – folder where the cache is located.

  • max_age – the maximum age in seconds after which a response is considered stale.

_get_filepath(request)[source]

Return a filename constructed from the md5 hash of a combination of the request URL and message content (encoded as utf-8 if necessary).

Parameters

request – the request object for which a cache filename is needed.

Returns

name of the cache file.

_get_fresh_content(request)[source]

Retrieve a fresh copy of the resource from the source.

Parameters

request – the request object for which the response is needed.

Returns

the response to the request

static _serialize(response)[source]

Serializes the suds response object using cPickle.

If the response has an error status (anything other than 200), raises ValueError. This is used to avoid caching errored responses.

static _deserialize(filecontent)[source]

De-serializes the cache content into a suds response object using cPickle.

send(request)[source]

Send a request and return the response. If a fresh response to the request is available in the cache, that is returned instead. If it isn’t, a fresh response is obtained, cached, and returned.

class tendril.utils.www.soap.CachedThrottledTransport(**kwargs)[source]

Bases: tendril.utils.www.soap.ThrottledTransport, tendril.utils.www.soap.CachedTransport

A cached HTTP transport with both throttling and request-based caching for SOAP APIs using suds.

This is a subclass of CachedTransport and ThrottledTransport.

Keyword arguments not handled here are passed on via ThrottledTransport to HttpTransport.

Parameters
  • cache_dir – folder where the cache is located.

  • max_age – the maximum age in seconds after which a response is considered stale.

  • minimum_spacing – Minimum number of seconds between requests. Default 0.

_get_fresh_content(request)[source]

Retrieve a fresh copy of the resource from the source via ThrottledTransport.send().

Parameters

request – the request object for which the response is needed.

Returns

the response to the request

send(request)[source]

Send a request and return the response, using CachedTransport.send().

tendril.utils.www.soap.get_soap_client(wsdl, cache_requests=True, max_age=600000, minimum_spacing=0)[source]

Creates and returns a suds/SOAP client instance bound to the provided WSDL. If cache_requests is True, then the client is configured to use a CachedThrottledTransport. The transport is constructed to use SOAP_CACHE as the cache folder, along with the max_age and minimum_spacing parameters if provided.

If cache_requests is False, the client uses the default suds.transport.http.HttpAuthenticated transport.