Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

python-memcached in 1.58 encoded question #104

Closed
sherwinl1u opened this issue Nov 3, 2016 · 3 comments
Closed

python-memcached in 1.58 encoded question #104

sherwinl1u opened this issue Nov 3, 2016 · 3 comments

Comments

@sherwinl1u
Copy link

sherwinl1u commented Nov 3, 2016

By reading the code in memcache.py, I found a encoded question.
In set() founction, It encode to utf8, if the value is six.text_type
def _val_to_store_info(self, val, min_compress_len):
flags = 0
if isinstance(val, six.binary_type):
pass
elif isinstance(val, six.text_type):
val = val.encode('utf-8')
......

but , In get() function, It decoder to unicoder ,only if the six.PY3 is true
def _recv_value(self, server, flags, rlen):
rlen += 2 # include \r\n
buf = server.recv(rlen)
if len(buf) != rlen:
raise _Error("received %d bytes when expecting %d"
% (len(buf), rlen))

    if len(buf) == rlen:
        buf = buf[:-2]  # strip \r\n

    if flags & Client._FLAG_COMPRESSED:
        buf = self.decompressor(buf)
        flags &= ~Client._FLAG_COMPRESSED

    if flags == 0:
        # Bare string
        if six.PY3:
            val = buf.decode('utf8')
        else:
            val = buf
    elif flags & Client._FLAG_INTEGER:
        val = int(buf)
   ......

I think we should fix it like this in set() function

def _val_to_store_info(self, val, min_compress_len):
flags = 0
if isinstance(val, six.binary_type):
pass
elif isinstance(val, six.text_type) and six.PY3:
val = val.encode('utf-8')
......

@timgraham
Copy link
Collaborator

Is it #79 or #80?

@dsully
Copy link

dsully commented Dec 21, 2016

Fix is in #74 - but still not merge-able. There are no versions of python-memcached that work with Python 3 storing bytes.

@timgraham
Copy link
Collaborator

Fixed in e1f72da, hopefully.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants