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 2.7 Unicode compatible, with test #107

Closed
wants to merge 14 commits into from
Closed

python 2.7 Unicode compatible, with test #107

wants to merge 14 commits into from

Conversation

niconoe
Copy link
Contributor

@niconoe niconoe commented Dec 14, 2016

To make life of the maintainer easier, I just grouped in this PR the fix for #79 by @dzhuang with the regression test by @tiumgraham.

@adamchainz
Copy link

@dzhuang
Copy link

dzhuang commented Dec 14, 2016

Thanks, but why it failed checks?

memcache.py Outdated
@@ -1523,4 +1528,4 @@ def _doctest():
sys.exit(1)


# vim: ts=4 sw=4 et :
# vim: ts=4 sw=4 et :

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is missing a new line which makes it an invalid file in POSIX, that's why it failed travis on python 2.6

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch, I was confused!

Copy link
Collaborator

@timgraham timgraham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A single squashed commit should be fine. For the commit message, I'd suggested:

Fix #79: Fix storing non-ASCII values on Python 2 and binary values on Python 3.

memcache.py Outdated
@@ -1523,4 +1528,4 @@ def _doctest():
sys.exit(1)


# vim: ts=4 sw=4 et :
# vim: ts=4 sw=4 et :
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

revert the newline removal

@@ -1,3 +1,5 @@
# -*- coding: utf-8 -*-

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no blank line needed

memcache.py Outdated
if six.PY3:
val = buf.decode('utf8')
else:
# Bare bytes
val = buf
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deindent this line

def test_unicode_value(self):
key = 'key'
value = six.u('Iñtërnâtiônàlizætiøn2')

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd omit the blank line.

@timgraham
Copy link
Collaborator

Does it also fix #80?


def test_binary_string(self):
# Binary strings should be cacheable
from zlib import compress, decompress
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd import zlib at the top of the file and use zlib.compress(), etc.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

self.assertEqual(value, cached_value)

def test_binary_string(self):
# Binary strings should be cacheable
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this isn't accomplishing much.

self.assertEqual(compressed_value, compressed_result)
self.assertEqual(value, decompress(compressed_result).decode())

# Test set_many
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comments don't seem to add value (reviewing my own code). ;-)

self.assertEqual(value, decompress(compressed_result).decode())

# Test add
self.mc.add('binary1-add', compressed_value)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that I see the fix, I wonder if the 3 variants are needed if they all use the same encoding process? For example, we don't have 3 variants for test_unicode_value.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't that more future-proof to ensure it works with the 3 methods. In that case, I'll complete test_unicode_value() instead.

memcache.py Outdated
# Bare bytes
val = buf
elif flags & Client._FLAG_TEXT:
val = buf.decode('utf8')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whilst you're at it you could make this utf-8 to be consistent with line 980

@timgraham
Copy link
Collaborator

It's unclear to me if any of the instance -> type changes are required and completely tested. That commit was separated nicely in #74 although since that PR doesn't have tests it's not clear what is fixing what.

memcache.py Outdated
@@ -243,9 +244,9 @@ def __init__(self, servers, debug=0, pickleProtocol=0,
def _encode_key(self, key):
if isinstance(key, tuple):
if isinstance(key[1], six.text_type):
return (key[0], key[1].encode('utf8'))
return (key[0], key[1].encode('utf-8'))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't make unrelated cleanups like that in a bug fix branch as it makes review more difficult, do it in a separate PR. (You've accidentally merged in the touch() fixes on this branch as well.

@timgraham
Copy link
Collaborator

@niconoe, do you have time to update this and remove the unrelated changes? I'd rebase the branch and make the fix a single squashed commit.

@niconoe
Copy link
Contributor Author

niconoe commented Jul 18, 2017

@timgraham like this?

@timgraham
Copy link
Collaborator

Updated and merged in #135, thanks!

@timgraham timgraham closed this Nov 14, 2017
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

Successfully merging this pull request may close these issues.

4 participants