Skip to content

python 2.7 Unicode compatible, with test#107

Closed
niconoe wants to merge 14 commits intolinsomniac:masterfrom
niconoe:separate_commits
Closed

python 2.7 Unicode compatible, with test#107
niconoe wants to merge 14 commits intolinsomniac:masterfrom
niconoe:separate_commits

Conversation

@niconoe
Copy link
Copy Markdown
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
Copy Markdown

@dzhuang
Copy link
Copy Markdown

dzhuang commented Dec 14, 2016

Thanks, but why it failed checks?

Comment thread memcache.py Outdated


# vim: ts=4 sw=4 et :
# vim: ts=4 sw=4 et : No newline at end of file
Copy link
Copy Markdown

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
Copy Markdown
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
Copy Markdown
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.

Comment thread memcache.py Outdated


# vim: ts=4 sw=4 et :
# vim: ts=4 sw=4 et : No newline at end of file
Copy link
Copy Markdown
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

Comment thread tests/test_memcache.py Outdated
@@ -1,3 +1,5 @@
# -*- coding: utf-8 -*-

Copy link
Copy Markdown
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

Comment thread memcache.py Outdated
val = buf.decode('utf8')
else:
# Bare bytes
val = buf
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

deindent this line

Comment thread tests/test_memcache.py Outdated
def test_unicode_value(self):
key = 'key'
value = six.u('Iñtërnâtiônàlizætiøn2')

Copy link
Copy Markdown
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
Copy Markdown
Collaborator

Does it also fix #80?

Comment thread tests/test_memcache.py Outdated

def test_binary_string(self):
# Binary strings should be cacheable
from zlib import compress, decompress
Copy link
Copy Markdown
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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

+1

Comment thread tests/test_memcache.py Outdated
self.assertEqual(value, cached_value)

def test_binary_string(self):
# Binary strings should be cacheable
Copy link
Copy Markdown
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.

Comment thread tests/test_memcache.py Outdated
self.assertEqual(compressed_value, compressed_result)
self.assertEqual(value, decompress(compressed_result).decode())

# Test set_many
Copy link
Copy Markdown
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). ;-)

Comment thread tests/test_memcache.py
self.assertEqual(value, decompress(compressed_result).decode())

# Test add
self.mc.add('binary1-add', compressed_value)
Copy link
Copy Markdown
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
Copy Markdown
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.

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

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
Copy Markdown
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.

Comment thread memcache.py Outdated
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor Author

niconoe commented Jul 18, 2017

@timgraham like this?

@timgraham
Copy link
Copy Markdown
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