Kaydet (Commit) 48ed4a1d authored tarafından Sebastian Vetter's avatar Sebastian Vetter

Add python 3 support

üst b7e1ac70
build
dist
*.egg-info
*.egg/
*.pyc
*.swp
.tox
import json
import logging
import re
import six
import shlex
from StringIO import StringIO
if six.PY3:
from io import StringIO
else:
from StringIO import StringIO
import requests
from requests.exceptions import HTTPError
......@@ -43,7 +48,7 @@ class Client(requests.Session):
def _container_config(self, image, command, hostname=None, user=None,
detach=False, stdin_open=False, tty=False, mem_limit=0, ports=None,
environment=None, dns=None, volumes=None, volumes_from=None):
if isinstance(command, basestring):
if isinstance(command, six.string_types):
command = shlex.split(command)
return {
'Hostname': hostname,
......@@ -68,7 +73,7 @@ class Client(requests.Session):
# so we do this disgusting thing here.
data2 = {}
if data is not None:
for k, v in data.iteritems():
for k, v in six.iteritems(data):
if v is not None:
data2[k] = v
......@@ -180,7 +185,7 @@ class Client(requests.Session):
'repo': repository,
'tag': tag
}
if type(src) == str or type(src) == unicode:
if isinstance(src, six.string_types):
params['fromSrc'] = src
return self._result(self.post(u, None, params=params))
......
......@@ -11,7 +11,7 @@ setup(
version='0.0.5',
description="Python client for Docker.",
packages=['docker'],
install_requires=['requests'] + test_requirements,
install_requires=['requests', 'six'] + test_requirements,
zip_safe=False,
classifiers=['Development Status :: 3 - Alpha',
'Environment :: Other Environment',
......
import six
import unittest
import time
import docker
......@@ -66,7 +66,7 @@ class TestImages(BaseTestCase):
class TestImageIds(BaseTestCase):
def runTest(self):
res1 = self.client.images(quiet=True)
self.assertEqual(type(res1[0]), unicode)
self.assertEqual(type(res1[0]), six.text_type)
class TestListContainers(BaseTestCase):
def runTest(self):
......@@ -230,7 +230,7 @@ class TestPull(BaseTestCase):
self.assertIn('Images', info)
img_count = info['Images']
res = self.client.pull('joffrey/test001')
self.assertEqual(type(res), unicode)
self.assertEqual(type(res), six.text_type)
self.assertEqual(img_count + 2, self.client.info()['Images'])
img_info = self.client.inspect_image('joffrey/test001')
self.assertIn('id', img_info)
......@@ -297,4 +297,4 @@ class TestRunShlex(BaseTestCase):
if __name__ == '__main__':
unittest.main()
\ No newline at end of file
unittest.main()
[tox]
envlist = py26, py27, py32, py33
[testenv]
commands =
{envpython} setup.py install
{envpython} tests/test.py
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment