Package biblio :: Package webquery :: Module querythrottle :: Class BaseQueryThrottle
[hide private]
[frames] | no frames]

Class BaseQueryThrottle

source code

  object --+    
           |    
impl.ReprObj --+
               |
              BaseQueryThrottle
Known Subclasses:

A limit upon query usage.

Often webservices will request that users restrict themselves to a request every second, or no more than 1000 a day, etc. This is a base class for implementing those limits. Different restrictions can be implemented in derived classes.

Limits are constructed with set behaviour

Instance Methods [hide private]
 
__init__(self, fail_action=None, wait_duration=1.0)
Ctor, allowing the polling period and failure behaviour to be set.
source code
 
check_limit(self, wquery)
Has the query exceeded its limit?
source code
 
within_limit(self, wquery)
Has the query exceeded its limit?
source code
 
log_success(self, wquery)
Sucessful queries will probably effect the success of future ones, so here is a place to log them.
source code

Inherited from impl.ReprObj: __repr__, __str__, __unicode__

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __setattr__

Class Variables [hide private]
  _repr_fields = ['fail_action', 'wait_duration']
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, fail_action=None, wait_duration=1.0)
(Constructor)

source code 
Ctor, allowing the polling period and failure behaviour to be set.
Overrides: object.__init__

check_limit(self, wquery)

source code 

Has the query exceeded its limit?

This is a primarily internal method for testing whether a limit has been reached. Handling that circumstance is left to the calling method check_limit. This should be overridden in derived class to implement different throttling methods.

Parameters:
  • wquery - The object or service to be throttled. This allows the same limit to service several objects in different ways (e.g. by having them share the same limit, or be handled independently).
Returns:
A boolean, giving whether the query is within limit or not.

within_limit(self, wquery)

source code 

Has the query exceeded its limit?

This should be called by services to test whether a limit has been reached. Handling that circumstance is left to the calling method check_limit. This should be overridden in derived class to implement different throttling methods.

Parameters: