From a4e7e2cd75f6ebcdf2c3ab62250d22fda1853ace Mon Sep 17 00:00:00 2001 From: lericson Date: Wed, 25 Nov 2009 12:00:04 +0100 Subject: [PATCH] Fix weird with Client.behaviors.update. This would manifest itself in pylibmc setting seemingly random (but consistently so) values for the updated behaviors. Not sure how or why this works when the previous code didn't. --- pylibmc.py | 10 +++++----- tests.py | 10 ++++++++++ 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/pylibmc.py b/pylibmc.py index 3d98816..e5113cb 100644 --- a/pylibmc.py +++ b/pylibmc.py @@ -57,9 +57,9 @@ class BehaviorDict(dict): super(BehaviorDict, self).__setitem__(name, value) self.client.set_behaviors({name: value}) - def update(self, *args, **kwds): - super(BehaviorDict, self).update(*args, **kwds) - self.client.set_behaviors(self.copy()) + def update(self, d): + super(BehaviorDict, self).update(d) + self.client.set_behaviors(d.copy()) class Client(_pylibmc.client): def __init__(self, servers, binary=False): @@ -115,9 +115,9 @@ class Client(_pylibmc.client): This also happens for `distribution`. """ behaviors = behaviors.copy() - if behaviors.get("hash", None) in hashers: + if behaviors.get("hash") is not None: behaviors["hash"] = hashers[behaviors["hash"]] - if behaviors.get("distribution") in distributions: + if behaviors.get("distribution") is not None: behaviors["distribution"] = distributions[behaviors["distribution"]] return super(Client, self).set_behaviors(behaviors) diff --git a/tests.py b/tests.py index 0c38e41..0f11b70 100644 --- a/tests.py +++ b/tests.py @@ -1,9 +1,11 @@ """Tests. They want YOU!! + Basic functionality. >>> _pylibmc.__version__ == pylibmc.__version__ True >>> c = _pylibmc.client([test_server]) +>>> c.get("hello") >>> c.set("test_key", 123) True >>> c.get("test_key") @@ -177,6 +179,14 @@ Empty server lists are bad for your health. Traceback (most recent call last): ... MemcachedError: empty server list + +Python-wrapped behaviors dict +>>> pc = pylibmc.Client(["%s:%d" % test_server[1:]]) +>>> (pc.behaviors["hash"], pc.behaviors["distribution"]) +('default', 'modula') +>>> pc.behaviors.update({"hash": "fnv1a_32", "distribution": "consistent"}) +>>> (pc.behaviors["hash"], pc.behaviors["distribution"]) +('fnv1a_32', 'consistent') """ # Used to test pickling.