Skip to content

Commit

Permalink
Add python 3 support
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Vetter committed Jul 5, 2013
1 parent b7e1ac7 commit 48ed4a1
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 9 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
build
dist
*.egg-info
*.egg/
*.pyc
*.swp

.tox
13 changes: 9 additions & 4 deletions docker/client.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
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
Expand Down Expand Up @@ -43,7 +48,7 @@ def _result(self, response, json=False):
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,
Expand All @@ -68,7 +73,7 @@ def post_json(self, url, data, **kwargs):
# 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

Expand Down Expand Up @@ -180,7 +185,7 @@ def import_image(self, src, repository=None, tag=None):
'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))

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
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',
Expand Down
8 changes: 4 additions & 4 deletions tests/test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import six
import unittest
import time

import docker

Expand Down Expand Up @@ -66,7 +66,7 @@ def runTest(self):
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):
Expand Down Expand Up @@ -230,7 +230,7 @@ def runTest(self):
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)
Expand Down Expand Up @@ -297,4 +297,4 @@ def runTest(self):


if __name__ == '__main__':
unittest.main()
unittest.main()
6 changes: 6 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[tox]
envlist = py26, py27, py32, py33
[testenv]
commands =
{envpython} setup.py install
{envpython} tests/test.py

0 comments on commit 48ed4a1

Please sign in to comment.