Commit 11ed30ea authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki Committed by Jérome Perrin

patch: update memcache_client patch based on python-memcached-1.58.

parent 19f24458
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Code based on python-memcached-1.53 # Code based on python-memcached-1.58
try: try:
from memcache import _Host, Client, _Error from memcache import _Host, Client, _Error
except ImportError: except ImportError:
...@@ -15,9 +15,11 @@ else: ...@@ -15,9 +15,11 @@ else:
pass pass
Client.MemcachedConnectionError = _ConnectionDeadError Client.MemcachedConnectionError = _ConnectionDeadError
import six
import socket import socket
def _get(self, cmd, key): def _get(self, cmd, key):
if getattr(self, 'do_check_key', True): key = self._encode_key(key)
if self.do_check_key:
self.check_key(key) self.check_key(key)
server, key = self._get_server(key) server, key = self._get_server(key)
if not server: if not server:
...@@ -29,25 +31,22 @@ else: ...@@ -29,25 +31,22 @@ else:
self._statlog(cmd) self._statlog(cmd)
try: try:
server.send_cmd("%s %s" % (cmd, key)) cmd_bytes = cmd.encode('utf-8') if six.PY3 else cmd
fullcmd = b''.join((cmd_bytes, b' ', key))
server.send_cmd(fullcmd)
rkey = flags = rlen = cas_id = None rkey = flags = rlen = cas_id = None
if cmd == 'gets': if cmd == 'gets':
try: rkey, flags, rlen, cas_id, = self._expect_cas_value(
rkey, flags, rlen, cas_id, = self._expect_cas_value(server, server, raise_exception=True
raise_exception=True) )
except TypeError:
# BBB
rkey, flags, rlen, cas_id, = self._expect_cas_value(server)
if rkey and self.cache_cas: if rkey and self.cache_cas:
self.cas_ids[rkey] = cas_id self.cas_ids[rkey] = cas_id
else: else:
try: rkey, flags, rlen, = self._expectvalue(
rkey, flags, rlen, = self._expectvalue(server, server, raise_exception=True
raise_exception=True) )
except TypeError:
# BBB
rkey, flags, rlen, = self._expectvalue(server)
if not rkey: if not rkey:
# (patch) # (patch)
# return None # return None
...@@ -55,13 +54,10 @@ else: ...@@ -55,13 +54,10 @@ else:
try: try:
value = self._recv_value(server, flags, rlen) value = self._recv_value(server, flags, rlen)
finally: finally:
try: server.expect(b"END", raise_exception=True)
server.expect("END", raise_exception=True)
except TypeError:
# BBB
server.expect("END")
except (_Error, socket.error) as msg: except (_Error, socket.error) as msg:
if isinstance(msg, tuple): msg = msg[1] if isinstance(msg, tuple):
msg = msg[1]
server.mark_dead(msg) server.mark_dead(msg)
# (patch) # (patch)
# return None # return None
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment