Package wtf :: Package ext :: Module sharedance :: Class SharedanceConnector
[hide private]
[frames] | no frames]

Class SharedanceConnector

source code

object --+
         |
        SharedanceConnector

Sharedance connection abstraction

If magic is enabled (see __init__), the data will be extended with the magic string (_MAGIC), followed by 0 byte, a flag number (decimal notation), a LF, the data length (decimal, too) and another LF. On the read this data will be used to transparently check for consistency and evaluate the flags (Currently there's only one: compressed)

Instance Methods [hide private]
 
__init__(self, spec, compress_threshold=None, timeout=None, weight=None, magic=-1)
Initialization
source code
 
store(self, key, data, _conn=None)
Store data in sharedance
source code
 
fetch(self, key, _conn=None)
Fetch data from sharedance
source code
 
delete(self, key, _conn=None)
Delete data from sharedance
source code
dict
check(self, key=None, content=None, fetch=None)
Check sharedance server for functionality
source code

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

Class Variables [hide private]
str _RETURN_OK = 'OK\n'
OK return value
str _MAGIC = '%#\\U;'
Magic string to mark our own format
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, spec, compress_threshold=None, timeout=None, weight=None, magic=-1)
(Constructor)

source code 

Initialization

The magic parameter determines whether the connection object should transparently handle extended values:

0 or False
No magic should be applied (neither on reads nor writes)
1 or True
Full magic should be applied
-1
No write magic should be applied (but reads are interpreted)
Parameters:
  • spec (tuple) - server spec
  • timeout (float) - Timeout in seconds
  • magic (int) - Magic behaviour
Overrides: object.__init__

store(self, key, data, _conn=None)

source code 
Store data in sharedance
Parameters:
  • key (str) - Key to store under
  • data (str) - Data to store
Decorators:
  • @_Connected
Raises:

fetch(self, key, _conn=None)

source code 
Fetch data from sharedance
Parameters:
  • key (str) - The key to fetch
Decorators:
  • @_Connected
Raises:

delete(self, key, _conn=None)

source code 
Delete data from sharedance
Parameters:
  • key (str) - The key to delete
Decorators:
  • @_Connected

check(self, key=None, content=None, fetch=None)

source code 

Check sharedance server for functionality

The check results are stored in a dict with the following keys:

spec
[tuple] host and port (('host', port))
error
[bool] Was there an error?
status
[unicode] Human readable status description
time
[int] Time taken for the whole check in microseconds (basically a store/fetch/delete cycle)
weight
[int] Weight of this particular sharedance (just for convenience)
Parameters:
  • key (str) - Key to store under. If omitted or None it defaults to CHECK-<random>.
  • content (str) - Content to store. If omitted or None it defaults to a random string
  • fetch (bool) - Try fetching the content? If omitted or None it defaults to True
Returns: dict
Check results