Permalink
Browse files

adding support for sasl

  • Loading branch information...
1 parent ef7055a commit ec45a179577299cab5d1632628afb18710e38bb9 @craigkerstiens craigkerstiens committed with Jeff Balogh Nov 14, 2011
Showing with 14 additions and 4 deletions.
  1. +14 −4 django_pylibmc/memcached.py
@@ -37,10 +37,14 @@
class PyLibMCCache(BaseMemcachedCache):
- def __init__(self, server, params):
+ def __init__(self, server, params, username=None, password=None):
+ import os
self._local = local()
self.binary = int(params.get('BINARY', False))
- super(PyLibMCCache, self).__init__(server, params, library=pylibmc,
+ self._username = os.environ.get('MEMCACHE_USERNAME', username)
+ self._password = os.environ.get('MEMCACHE_PASSWORD', password)
+ self._server = os.environ.get('MEMCACHE_SERVERS', server)
+ super(PyLibMCCache, self).__init__(self._server, params, library=pylibmc,
value_not_found_exception=pylibmc.NotFound)
@property
@@ -51,8 +55,14 @@ def _cache(self):
client = getattr(self._local, 'client', None)
if client:
return client
-
- client = self._lib.Client(self._servers, binary=self.binary)
+
+ if (self._username != None and self._password != None):
+ client = self._lib.Client(self._servers,
+ binary=self.binary,
+ username=self._username,
+ password=self._password)
+ else:
+ client = self._lib.Client(self._servers, binary=self.binary)
if self._options:
client.behaviors = self._options

0 comments on commit ec45a17

Please sign in to comment.