linsomniac/python-memcached — pull request #26 by cabrera (2014-01-15 22:10:29+00:00)
Title: Python 3.3 Fixes

Here's the commit log:

```
memcache: get closer to py33 compat, style fixes

The following changes were systematically applied throughtout:

* print 'thing' -> print('thing')
* except Exception, msg -> except Exception as msg:
* pep8 fixes:
* lines too long (>79 characters)
* imports out of order
* importing functions from a module: zlib, threading
* comparison to None, e.g., x == None vs. x is None
* spaces between/after/before operators
* dict.iterkeys -> six.iterkeys(dict)

The following are BREAKING changes:

* zlib is required now
* minimum Python version is 2.6 (io module, exception syntax)
```

### Breaking Changes

* Python 2.6+, 3.3+ required
* zlib required

### Additional Notes

Currently a WIP. Python 2.7 doctests fail with:

```
alejandro@rainbow-generator:~/Development/python-memcached:[py33_fixes]$ python memcache.py
Testing docstrings...
Running tests:
Testing set/get {'a_string': some random string} ...
OK
Testing set/get {'an_integer': 42 ()} ...
OK
Testing set/get {'long': 1073741824 ()} ...
OK
Testing delete ...
OK
Checking results of delete ...
OK
Testing get_multi ...
{'an_integer': 42, 'a_string': 'some random string'}
Testing get(unknown value) ...
None ()
Testing set/get {'foostruct': A FooStruct ()} ...
Traceback (most recent call last):
File "memcache.py", line 1386, in
test_setget("foostruct", f)
File "memcache.py", line 1342, in test_setget
mc.set(key, val)
File "memcache.py", line 607, in set
return self._set("set", key, val, time, min_compress_len)
File "memcache.py", line 885, in _set
return _unsafe_set()
File "memcache.py", line 858, in _unsafe_set
store_info = self._val_to_store_info(val, min_compress_len)
File "memcache.py", line 826, in _val_to_store_info
pickler.dump(val)
File "/usr/local/lib/python2.7/pickle.py", line 224, in dump
self.save(obj)
File "/usr/local/lib/python2.7/pickle.py", line 331, in save
self.save_reduce(obj=obj, *rv)
File "/usr/local/lib/python2.7/pickle.py", line 400, in save_reduce
save(func)
File "/usr/local/lib/python2.7/pickle.py", line 286, in save
f(self, obj) # Call unbound method with explicit self
File "/usr/local/lib/python2.7/pickle.py", line 767, in save_global
write(GLOBAL + module + '\n' + name + '\n')
TypeError: unicode argument expected, got 'str'
```

Python 3.3. unit tests fail with:

```
alejandro@rainbow-generator:~/Development/python-memcached:[py33_fixes]$ tox -e py33
py33 develop-inst-nodeps: /home/alejandro/Development/python-memcached
py33 runtests: commands[0] | nosetests
E
======================================================================
ERROR: test_Socket_Disconnect (test_setmulti.test_Memcached_Set_Multi)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/alejandro/Development/python-memcached/tests/test_setmulti.py", line 60, in test_Socket_Disconnect
bad_keys = client.set_multi(mapping)
File "/home/alejandro/Development/python-memcached/memcache.py", line 746, in set_multi
six.iterkeys(mapping), key_prefix)
File "/home/alejandro/Development/python-memcached/memcache.py", line 670, in _map_and_prefix_keys
server, key = self._get_server(key_prefix + str_orig_key)
File "/home/alejandro/Development/python-memcached/memcache.py", line 359, in _get_server
serverhash = serverHashFunction(key)
File "/home/alejandro/Development/python-memcached/memcache.py", line 64, in cmemcache_hash
return ((((binascii.crc32(key) & 0xffffffff) >> 16) & 0x7fff) or 1)
TypeError: 'str' does not support the buffer interface

----------------------------------------------------------------------
Ran 1 test in 0.010s

FAILED (errors=1)
ERROR: InvocationError: '/home/alejandro/Development/python-memcached/.tox/py33/bin/nosetests'
__________________________________________________________________________ summary ___________________________________________________________________________
ERROR: py33: commands failed
```