PVince81/pyocclient — pull request #59 by blizzz (2014-12-10 10:51:48+00:00)
Title: [WIP][don't merge yet] Python 3.4 compatibility

There is something left to do that I was not able to track down yet. I think i was close once, but missed the time to crunch on this :( A goal of course is to continue to support Python 2.7. The test against 2.7 run fine for me.

On 3.4 a test run reveals this:

```
# ./runtests.sh
....Assertion error caught with data set ['文件.txt', b'\xe4\xbd\xa0\xe5\xa5\xbd\xe4\xb8\x96\xe7\x95\x8c', '文件夹']
FAssertion error caught with data set ['test.txt', 'Hello world!', 'subdir']
F..........FF.FFF.F...F....E/usr/lib/python3.4/unittest/case.py:605: ResourceWarning: unclosed
outcome.errors.clear()
/usr/lib/python3.4/unittest/case.py:605: ResourceWarning: unclosed file <_io.BufferedReader name='/tmp/pyocclient_test1418208618/pyoctest.dat'>
outcome.errors.clear()
E/usr/lib/python3.4/unittest/case.py:605: ResourceWarning: unclosed
outcome.errors.clear()
/usr/lib/python3.4/unittest/case.py:605: ResourceWarning: unclosed file <_io.BufferedReader name='/tmp/pyocclient_test1418208619/pyoctest.dir//file2.dat'>
outcome.errors.clear()
E/usr/lib/python3.4/unittest/case.py:605: ResourceWarning: unclosed
outcome.errors.clear()
/usr/lib/python3.4/unittest/case.py:605: ResourceWarning: unclosed file <_io.BufferedReader name='/tmp/pyocclient_test1418208620/pyoctest.dat'>
outcome.errors.clear()
.E/usr/lib/python3.4/unittest/case.py:605: ResourceWarning: unclosed
outcome.errors.clear()
/usr/lib/python3.4/unittest/case.py:605: ResourceWarning: unclosed file <_io.BufferedReader name='/tmp/pyocclient_test1418208622/pyoctest.dat'>
outcome.errors.clear()
......
======================================================================
ERROR: test_upload_big_file (__main__.TestFileAccess)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/usr/local/lib/python3.4/dist-packages/unittest_data_provider/__init__.py", line 7, in repl
fn(self, *i)
File "owncloud/test/test.py", line 167, in test_upload_big_file
self.assertTrue(self.client.put_file(self.test_root + file_name, temp_file))
File "/root/pyocclient/owncloud/owncloud.py", line 326, in put_file
**kwargs
File "/root/pyocclient/owncloud/owncloud.py", line 440, in __put_file_chunked
headers = headers
File "/root/pyocclient/owncloud/owncloud.py", line 879, in __make_dav_request
**kwargs
File "/usr/local/lib/python3.4/dist-packages/requests/sessions.py", line 457, in request
resp = self.send(prep, **send_kwargs)
File "/usr/local/lib/python3.4/dist-packages/requests/sessions.py", line 569, in send
r = adapter.send(request, **kwargs)
File "/usr/local/lib/python3.4/dist-packages/requests/adapters.py", line 362, in send
timeout=timeout
File "/usr/local/lib/python3.4/dist-packages/requests/packages/urllib3/connectionpool.py", line 516, in urlopen
body=body, headers=headers)
File "/usr/local/lib/python3.4/dist-packages/requests/packages/urllib3/connectionpool.py", line 308, in _make_request
conn.request(method, url, **httplib_request_kw)
File "/usr/lib/python3.4/http/client.py", line 1090, in request
self._send_request(method, url, body, headers)
File "/usr/lib/python3.4/http/client.py", line 1123, in _send_request
self.putheader(hdr, value)
File "/usr/lib/python3.4/http/client.py", line 1069, in putheader
value = b'\r\n\t'.join(values)
TypeError: sequence item 0: expected bytes, bytearray, or an object with the buffer interface, float found

======================================================================
ERROR: test_upload_directory (__main__.TestFileAccess)
----------------------------------------------------------------------
Traceback (most recent call last):
File "owncloud/test/test.py", line 191, in test_upload_directory
self.assertTrue(self.client.put_directory(self.test_root + 'subdir', temp_dir))
File "/root/pyocclient/owncloud/owncloud.py", line 377, in put_directory
**kwargs
File "/root/pyocclient/owncloud/owncloud.py", line 326, in put_file
**kwargs
File "/root/pyocclient/owncloud/owncloud.py", line 440, in __put_file_chunked
headers = headers
File "/root/pyocclient/owncloud/owncloud.py", line 879, in __make_dav_request
**kwargs
File "/usr/local/lib/python3.4/dist-packages/requests/sessions.py", line 457, in request
resp = self.send(prep, **send_kwargs)
File "/usr/local/lib/python3.4/dist-packages/requests/sessions.py", line 569, in send
r = adapter.send(request, **kwargs)
File "/usr/local/lib/python3.4/dist-packages/requests/adapters.py", line 362, in send
timeout=timeout
File "/usr/local/lib/python3.4/dist-packages/requests/packages/urllib3/connectionpool.py", line 516, in urlopen
body=body, headers=headers)
File "/usr/local/lib/python3.4/dist-packages/requests/packages/urllib3/connectionpool.py", line 308, in _make_request
conn.request(method, url, **httplib_request_kw)
File "/usr/lib/python3.4/http/client.py", line 1090, in request
self._send_request(method, url, body, headers)
File "/usr/lib/python3.4/http/client.py", line 1123, in _send_request
self.putheader(hdr, value)
File "/usr/lib/python3.4/http/client.py", line 1069, in putheader
value = b'\r\n\t'.join(values)
TypeError: sequence item 0: expected bytes, bytearray, or an object with the buffer interface, float found

======================================================================
ERROR: test_upload_small_file (__main__.TestFileAccess)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/usr/local/lib/python3.4/dist-packages/unittest_data_provider/__init__.py", line 7, in repl
fn(self, *i)
File "owncloud/test/test.py", line 143, in test_upload_small_file
self.assertTrue(self.client.put_file(self.test_root + file_name, temp_file))
File "/root/pyocclient/owncloud/owncloud.py", line 326, in put_file
**kwargs
File "/root/pyocclient/owncloud/owncloud.py", line 440, in __put_file_chunked
headers = headers
File "/root/pyocclient/owncloud/owncloud.py", line 879, in __make_dav_request
**kwargs
File "/usr/local/lib/python3.4/dist-packages/requests/sessions.py", line 457, in request
resp = self.send(prep, **send_kwargs)
File "/usr/local/lib/python3.4/dist-packages/requests/sessions.py", line 569, in send
r = adapter.send(request, **kwargs)
File "/usr/local/lib/python3.4/dist-packages/requests/adapters.py", line 362, in send
timeout=timeout
File "/usr/local/lib/python3.4/dist-packages/requests/packages/urllib3/connectionpool.py", line 516, in urlopen
body=body, headers=headers)
File "/usr/local/lib/python3.4/dist-packages/requests/packages/urllib3/connectionpool.py", line 308, in _make_request
conn.request(method, url, **httplib_request_kw)
File "/usr/lib/python3.4/http/client.py", line 1090, in request
self._send_request(method, url, body, headers)
File "/usr/lib/python3.4/http/client.py", line 1123, in _send_request
self.putheader(hdr, value)
File "/usr/lib/python3.4/http/client.py", line 1069, in putheader
value = b'\r\n\t'.join(values)
TypeError: sequence item 0: expected bytes, bytearray, or an object with the buffer interface, float found

======================================================================
ERROR: test_upload_two_chunks (__main__.TestFileAccess)
Test chunked upload with two chunks
----------------------------------------------------------------------
Traceback (most recent call last):
File "owncloud/test/test.py", line 154, in test_upload_two_chunks
self.assertTrue(self.client.put_file(self.test_root + 'chunk_test.dat', temp_file))
File "/root/pyocclient/owncloud/owncloud.py", line 326, in put_file
**kwargs
File "/root/pyocclient/owncloud/owncloud.py", line 440, in __put_file_chunked
headers = headers
File "/root/pyocclient/owncloud/owncloud.py", line 879, in __make_dav_request
**kwargs
File "/usr/local/lib/python3.4/dist-packages/requests/sessions.py", line 457, in request
resp = self.send(prep, **send_kwargs)
File "/usr/local/lib/python3.4/dist-packages/requests/sessions.py", line 569, in send
r = adapter.send(request, **kwargs)
File "/usr/local/lib/python3.4/dist-packages/requests/adapters.py", line 362, in send
timeout=timeout
File "/usr/local/lib/python3.4/dist-packages/requests/packages/urllib3/connectionpool.py", line 516, in urlopen
body=body, headers=headers)
File "/usr/local/lib/python3.4/dist-packages/requests/packages/urllib3/connectionpool.py", line 308, in _make_request
conn.request(method, url, **httplib_request_kw)
File "/usr/lib/python3.4/http/client.py", line 1090, in request
self._send_request(method, url, body, headers)
File "/usr/lib/python3.4/http/client.py", line 1123, in _send_request
self.putheader(hdr, value)
File "/usr/lib/python3.4/http/client.py", line 1069, in putheader
value = b'\r\n\t'.join(values)
TypeError: sequence item 0: expected bytes, bytearray, or an object with the buffer interface, float found

======================================================================
FAIL: test_download_file (__main__.TestFileAccess)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/usr/local/lib/python3.4/dist-packages/unittest_data_provider/__init__.py", line 7, in repl
fn(self, *i)
File "owncloud/test/test.py", line 213, in test_download_file
self.assertEqual(s, content)
AssertionError: '你好世界' != b'\xe4\xbd\xa0\xe5\xa5\xbd\xe4\xb8\x96\xe7\x95\x8c'

======================================================================
FAIL: test_get_file_contents (__main__.TestFileAccess)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/usr/local/lib/python3.4/dist-packages/unittest_data_provider/__init__.py", line 7, in repl
fn(self, *i)
File "owncloud/test/test.py", line 80, in test_get_file_contents
self.assertEqual(self.client.get_file_contents(self.test_root + subdir + '/' + file_name), content)
AssertionError: b'Hello world!' != 'Hello world!'

======================================================================
FAIL: test_move_and_rename (__main__.TestFileAccess)
Test rename into subdir
----------------------------------------------------------------------
Traceback (most recent call last):
File "owncloud/test/test.py", line 303, in test_move_and_rename
'first file'
AssertionError: b'first file' != 'first file'

======================================================================
FAIL: test_move_rename_in_place (__main__.TestFileAccess)
Test rename in place
----------------------------------------------------------------------
Traceback (most recent call last):
File "owncloud/test/test.py", line 276, in test_move_rename_in_place
'to rename'
AssertionError: b'to rename' != 'to rename'

======================================================================
FAIL: test_move_to_dir (__main__.TestFileAccess)
Test move into directory
----------------------------------------------------------------------
Traceback (most recent call last):
File "owncloud/test/test.py", line 331, in test_move_to_dir
'z file'
AssertionError: b'z file' != 'z file'

======================================================================
FAIL: test_move_to_non_existing_dir (__main__.TestFileAccess)
Test error when moving to non existing dir
----------------------------------------------------------------------
Traceback (most recent call last):
File "owncloud/test/test.py", line 430, in test_move_to_non_existing_dir
'x'
AssertionError: b'x' != 'x'

======================================================================
FAIL: test_move_unicode (__main__.TestFileAccess)
Test move unicode to dir
----------------------------------------------------------------------
Traceback (most recent call last):
File "owncloud/test/test.py", line 407, in test_move_unicode
'2'
AssertionError: b'2' != '2'

======================================================================
FAIL: test_rename_unicode (__main__.TestFileAccess)
Test rename unicode
----------------------------------------------------------------------
Traceback (most recent call last):
File "owncloud/test/test.py", line 381, in test_rename_unicode
'1'
AssertionError: b'1' != '1'

======================================================================
FAIL: test_update_share_password (__main__.TestFileAccess)
Test updating a share parameters - password
----------------------------------------------------------------------
Traceback (most recent call last):
File "owncloud/test/test.py", line 601, in test_update_share_password
self.assertTrue('share_with_displayname' in share_info)
AssertionError: False is not true

----------------------------------------------------------------------
Ran 43 tests in 76.586s

FAILED (failures=9, errors=4)

```