Permalink
Browse files

flake8ed

  • Loading branch information...
tarekziade committed Dec 10, 2012
1 parent 69fe0f7 commit 4e843abd6061291ffe85ef5ed8f91d15339da263
Showing with 15 additions and 11 deletions.
  1. +8 −6 memcachepool/cache.py
  2. +7 −5 memcachepool/pool.py
View
@@ -26,16 +26,17 @@ class UMemcacheCache(MemcachedCache):
def __init__(self, server, params):
import umemcache
- super(MemcachedCache, self).__init__(server, params,
- library=umemcache,
- value_not_found_exception=ValueError)
+ kls = super(MemcachedCache, self)
+ kls.__init__(server, params, library=umemcache,
+ value_not_found_exception=ValueError)
# see how to pass the pool value
self.maxsize = int(params.get('MAX_POOL_SIZE', 35))
self.blacklist_time = int(params.get('BLACKLIST_TIME', 60))
self.socktimeout = int(params.get('SOCKET_TIMEOUT', 4))
self.max_item_size = long(params.get('MAX_ITEM_SIZE',
DEFAULT_ITEM_SIZE))
- self._pool = ClientPool(self._get_client, maxsize=self.maxsize,wait_for_connection=self.socktimeout)
+ self._pool = ClientPool(self._get_client, maxsize=self.maxsize,
+ wait_for_connection=self.socktimeout)
self._blacklist = {}
# XXX using python-memcached style pickling
@@ -118,15 +119,16 @@ def _value_for_flag(self, value, flag):
return self.unserialize(value)
def add(self, key, value, timeout=0, version=None):
- flag = _flag_for_value(value)
+ flag = self._flag_for_value(value)
if flag == self._FLAG_SERIALIED:
value = self.serialize(value)
else:
value = '%d' % value
key = self.make_key(key, version=version)
with self._pool.reserve() as conn:
- return conn.add(key, value, self._get_memcache_timeout(timeout), flag)
+ return conn.add(key, value, self._get_memcache_timeout(timeout),
+ flag)
def get(self, key, default=None, version=None):
key = self.make_key(key, version=version)
View
@@ -11,12 +11,13 @@
class ClientPool(object):
- def __init__(self, factory, maxsize=None, timeout=60,wait_for_connection=None):
+ def __init__(self, factory, maxsize=None, timeout=60,
+ wait_for_connection=None):
self.factory = factory
self.maxsize = maxsize
self.timeout = timeout
self.clients = Queue.PriorityQueue(maxsize)
- self.wait_for_connection=wait_for_connection
+ self.wait_for_connection = wait_for_connection
# If there is a maxsize, prime the queue with empty slots.
if maxsize is not None:
for _ in xrange(maxsize):
@@ -37,7 +38,8 @@ def _checkout_connection(self):
# Loop until we get a non-stale connection, or we create a new one.
while True:
try:
- ts, client = self.clients.get(blocking,self.wait_for_connection)
+ ts, client = self.clients.get(blocking,
+ self.wait_for_connection)
except Queue.Empty:
if blocking:
#timeout
@@ -53,9 +55,9 @@ def _checkout_connection(self):
if client is None:
try:
return now, self.factory()
- except Exception,e:
+ except Exception, e:
if self.maxsize is not None:
- #return slot to queue
+ # return slot to queue
self.clients.put(EMPTY_SLOT)
raise e
# If the connection is not stale, go ahead and use it.

0 comments on commit 4e843ab

Please sign in to comment.