From bffe887cc226abf575d280e828490607d0e57c84 Mon Sep 17 00:00:00 2001 From: lericson Date: Fri, 31 Jul 2009 22:04:49 +0200 Subject: [PATCH] Add lots of informative text (known as documentation). --- pylibmc.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/pylibmc.py b/pylibmc.py index 6bb3d21..adcfd2e 100644 --- a/pylibmc.py +++ b/pylibmc.py @@ -1,5 +1,8 @@ """`python-memcached`-compatible wrapper around `_pylibmc`. +The interface is pretty much exactly the same as python-memcached, with some +minor differences. If you should happen to spot any, file a bug! + >>> mc = Client(["127.0.0.1"]) >>> b = mc.behaviors >>> b.keys() @@ -42,6 +45,12 @@ class BehaviorDict(dict): class Client(_pylibmc.client): def __init__(self, servers, *args, **kwds): + """Initialize a memcached client instance. + + This connects to the servers in *servers*, which will default to being + TCP servers. If it looks like a filesystem path, a UNIX socket. If + prefixed with `udp:`, a UDP connection. + """ addr_tups = [] for server in servers: addr = server @@ -65,13 +74,26 @@ class Client(_pylibmc.client): super(Client, self).__init__(addr_tups) def get_behaviors(self): + """Gets the behaviors from the underlying C client instance. + + Reverses the integer constants for `hash` and `distribution` into more + understandable string values. See *set_behaviors* for info. + """ behaviors = super(Client, self).get_behaviors() behaviors["hash"] = hashers_rvs[behaviors["hash"]] behaviors["distribution"] = distributions_rvs[behaviors["distribution"]] return BehaviorDict(self, behaviors) def set_behaviors(self, behaviors): - # Morph some. + """Sets the behaviors on the underlying C client instance. + + Takes care of morphing the `hash` key, if specified, into the + corresponding integer constant (which the C client expects.) If, + however, an unknown value is specified, it's passed on to the C client + (where it most surely will error out.) + + This also happens for `distribution`. + """ behaviors = behaviors.copy() if behaviors.get("hash", None) in hashers: behaviors["hash"] = hashers[behaviors["hash"]]