-
Notifications
You must be signed in to change notification settings - Fork 201
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
Conversation
|
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 : |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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!
There was a problem hiding this 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 : |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revert the newline removal
tests/test_memcache.py
Outdated
@@ -1,3 +1,5 @@ | |||
# -*- coding: utf-8 -*- | |||
|
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
deindent this line
tests/test_memcache.py
Outdated
def test_unicode_value(self): | ||
key = 'key' | ||
value = six.u('Iñtërnâtiônàlizætiøn2') | ||
|
There was a problem hiding this comment.
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.
Does it also fix #80? |
tests/test_memcache.py
Outdated
|
||
def test_binary_string(self): | ||
# Binary strings should be cacheable | ||
from zlib import compress, decompress |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
tests/test_memcache.py
Outdated
self.assertEqual(value, cached_value) | ||
|
||
def test_binary_string(self): | ||
# Binary strings should be cacheable |
There was a problem hiding this comment.
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.
tests/test_memcache.py
Outdated
self.assertEqual(compressed_value, compressed_result) | ||
self.assertEqual(value, decompress(compressed_result).decode()) | ||
|
||
# Test set_many |
There was a problem hiding this comment.
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). ;-)
tests/test_memcache.py
Outdated
self.assertEqual(value, decompress(compressed_result).decode()) | ||
|
||
# Test add | ||
self.mc.add('binary1-add', compressed_value) |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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') |
There was a problem hiding this comment.
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
It's unclear to me if any of the |
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')) |
There was a problem hiding this comment.
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.
@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. |
@timgraham like this? |
Updated and merged in #135, thanks! |
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.