Author: tomaz
Date: Sat Dec 3 14:19:43 2011
New Revision: 1209915
URL: http://svn.apache.org/viewvc?rev=1209915&view=rev
Log:
Start working on Python 3 compatibility.
Added:
libcloud/branches/py3k/libcloud/py3.py
Modified:
libcloud/branches/py3k/ (props changed)
libcloud/branches/py3k/libcloud/common/base.py
libcloud/branches/py3k/libcloud/compute/base.py
libcloud/branches/py3k/libcloud/compute/ssh.py
libcloud/branches/py3k/libcloud/httplib_ssl.py
libcloud/branches/py3k/libcloud/utils.py
libcloud/branches/py3k/setup.py
libcloud/branches/py3k/test/__init__.py
libcloud/branches/py3k/test/test_response_classes.py
libcloud/branches/py3k/test/test_utils.py
libcloud/branches/py3k/tox.ini
Propchange: libcloud/branches/py3k/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Sat Dec 3 14:19:43 2011
@@ -5,3 +5,4 @@ project.log
tailor.state
tailor.state.old
tailor.state.journal
+__pycache__
Modified: libcloud/branches/py3k/libcloud/common/base.py
URL:
http://svn.apache.org/viewvc/libcloud/branches/py3k/libcloud/common/base.py?rev=1209915&r1=1209914&r2=1209915&view=diff
==============================================================================
--- libcloud/branches/py3k/libcloud/common/base.py (original)
+++ libcloud/branches/py3k/libcloud/common/base.py Sat Dec 3 14:19:43 2011
@@ -13,15 +13,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-import httplib
import urllib
-import StringIO
import ssl
import time
from xml.etree import ElementTree as ET
from pipes import quote as pquote
-import urlparse
try:
import simplejson as json
@@ -29,10 +26,15 @@ except:
import json
import libcloud
+
+from libcloud.py3 import httplib
+from libcloud.py3 import urlparse
+from libcloud.py3 import StringIO
from libcloud.common.types import LibcloudError, MalformedResponseError
from libcloud.httplib_ssl import LibcloudHTTPSConnection
-from httplib import HTTPConnection as LibcloudHTTPConnection
+
+LibcloudHTTPConnection = httplib.HTTPConnection
class Response(object):
"""
@@ -483,8 +485,10 @@ class Connection(object):
else:
self.connection.request(method=method, url=url, body=data,
headers=headers)
- except ssl.SSLError, e:
- raise ssl.SSLError(str(e))
+ #except ssl.SSLError, e:
+ except ssl.SSLError:
+ raise ssl.SSLError()
+ #raise ssl.SSLError(str(e))
if raw:
response = self.rawResponseCls(connection=self)
Modified: libcloud/branches/py3k/libcloud/compute/base.py
URL:
http://svn.apache.org/viewvc/libcloud/branches/py3k/libcloud/compute/base.py?rev=1209915&r1=1209914&r2=1209915&view=diff
==============================================================================
--- libcloud/branches/py3k/libcloud/compute/base.py (original)
+++ libcloud/branches/py3k/libcloud/compute/base.py Sat Dec 3 14:19:43 2011
@@ -560,8 +560,10 @@ class NodeDriver(BaseDriver):
node=node,
ssh_client=ssh_client,
max_tries=3)
- except Exception, e:
- raise DeploymentError(node, e)
+ except Exception:
+ #except Exception, e:
+ #raise DeploymentError(node, e)
+ raise DeploymentError(node, None)
return node
def _wait_until_running(self, node, wait_period=3, timeout=600):
Modified: libcloud/branches/py3k/libcloud/compute/ssh.py
URL:
http://svn.apache.org/viewvc/libcloud/branches/py3k/libcloud/compute/ssh.py?rev=1209915&r1=1209914&r2=1209915&view=diff
==============================================================================
--- libcloud/branches/py3k/libcloud/compute/ssh.py (original)
+++ libcloud/branches/py3k/libcloud/compute/ssh.py Sat Dec 3 14:19:43 2011
@@ -66,8 +66,8 @@ class BaseSSHClient(object):
@return: C{bool}
"""
- raise NotImplementedError, \
- 'connect not implemented for this ssh client'
+ raise NotImplementedError(
+ 'connect not implemented for this ssh client')
def put(self, path, contents=None, chmod=None):
"""
@@ -82,8 +82,8 @@ class BaseSSHClient(object):
@type chmod: C{int}
@keyword chmod: chmod file to this after creation.
"""
- raise NotImplementedError, \
- 'put not implemented for this ssh client'
+ raise NotImplementedError(
+ 'put not implemented for this ssh client')
def delete(self, path):
"""
@@ -92,8 +92,8 @@ class BaseSSHClient(object):
@type path: C{str}
@keyword path: File path on the remote node.
"""
- raise NotImplementedError, \
- 'delete not implemented for this ssh client'
+ raise NotImplementedError(
+ 'delete not implemented for this ssh client')
def run(self, cmd):
"""
@@ -104,15 +104,15 @@ class BaseSSHClient(object):
@return C{list} of [stdout, stderr, exit_status]
"""
- raise NotImplementedError, \
- 'run not implemented for this ssh client'
+ raise NotImplementedError(
+ 'run not implemented for this ssh client')
def close(self):
"""
Shutdown connection to the remote node.
"""
- raise NotImplementedError, \
- 'close not implemented for this ssh client'
+ raise NotImplementedError(
+ 'close not implemented for this ssh client')
class ParamikoSSHClient(BaseSSHClient):
"""
Modified: libcloud/branches/py3k/libcloud/httplib_ssl.py
URL:
http://svn.apache.org/viewvc/libcloud/branches/py3k/libcloud/httplib_ssl.py?rev=1209915&r1=1209914&r2=1209915&view=diff
==============================================================================
--- libcloud/branches/py3k/libcloud/httplib_ssl.py (original)
+++ libcloud/branches/py3k/libcloud/httplib_ssl.py Sat Dec 3 14:19:43 2011
@@ -16,7 +16,6 @@
Subclass for httplib.HTTPSConnection with optional certificate name
verification, depending on libcloud.security settings.
"""
-import httplib
import os
import re
import socket
@@ -24,6 +23,7 @@ import ssl
import warnings
import libcloud.security
+from libcloud.py3 import httplib
class LibcloudHTTPSConnection(httplib.HTTPSConnection):
"""LibcloudHTTPSConnection
Added: libcloud/branches/py3k/libcloud/py3.py
URL:
http://svn.apache.org/viewvc/libcloud/branches/py3k/libcloud/py3.py?rev=1209915&view=auto
==============================================================================
--- libcloud/branches/py3k/libcloud/py3.py (added)
+++ libcloud/branches/py3k/libcloud/py3.py Sat Dec 3 14:19:43 2011
@@ -0,0 +1,36 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Libcloud Python 2.x and 3.x compatibility layer
+
+import sys
+
+PY3 = False
+PY25 = False
+
+if sys.version_info >= (3, 0):
+ PY3 = True
+ import http.client as httplib
+ from io import StringIO
+ import urllib as urllib2
+ import urllib.parse as urlparse
+else:
+ import httplib
+ from StringIO import StringIO
+ import urllib2
+ import urlparse
+
+if sys.version_info >= (2, 5) and sys.version_info <= (2, 6):
+ PY25 = True
Modified: libcloud/branches/py3k/libcloud/utils.py
URL:
http://svn.apache.org/viewvc/libcloud/branches/py3k/libcloud/utils.py?rev=1209915&r1=1209914&r2=1209915&view=diff
==============================================================================
--- libcloud/branches/py3k/libcloud/utils.py (original)
+++ libcloud/branches/py3k/libcloud/utils.py Sat Dec 3 14:19:43 2011
@@ -16,13 +16,18 @@
import os
import mimetypes
import warnings
-from httplib import HTTPResponse
+
+from libcloud.py3 import httplib
+from libcloud.py3 import PY25, PY3
SHOW_DEPRECATION_WARNING = True
SHOW_IN_DEVELOPMENT_WARNING = True
OLD_API_REMOVE_VERSION = '0.7.0'
CHUNK_SIZE = 8096
+if PY3:
+ from io import FileIO as file
+
def read_in_chunks(iterator, chunk_size=None, fill_size=False):
"""
@@ -41,12 +46,17 @@ def read_in_chunks(iterator, chunk_size=
"""
chunk_size = chunk_size or CHUNK_SIZE
- if isinstance(iterator, (file, HTTPResponse)):
+ if isinstance(iterator, (file, httplib.HTTPResponse)):
get_data = iterator.read
args = (chunk_size, )
else:
- get_data = iterator.next
- args = ()
+ # TODO move in a common place
+ if PY25:
+ get_data = iterator.next
+ args = ()
+ else:
+ get_data = next
+ args = (iterator, )
data = ''
empty = False
@@ -87,8 +97,16 @@ def exhaust_iterator(iterator):
"""
data = ''
+ # TODO move in a common place
+ if PY25:
+ get_data = iterator.next
+ args = ()
+ else:
+ get_data = next
+ args = (iterator,)
+
try:
- chunk = str(iterator.next())
+ chunk = str(get_data(*args))
except StopIteration:
chunk = ''
@@ -96,7 +114,7 @@ def exhaust_iterator(iterator):
data += chunk
try:
- chunk = str(iterator.next())
+ chunk = str(get_data(*args))
except StopIteration:
chunk = ''
Modified: libcloud/branches/py3k/setup.py
URL:
http://svn.apache.org/viewvc/libcloud/branches/py3k/setup.py?rev=1209915&r1=1209914&r2=1209915&view=diff
==============================================================================
--- libcloud/branches/py3k/setup.py (original)
+++ libcloud/branches/py3k/setup.py Sat Dec 3 14:19:43 2011
@@ -63,9 +63,9 @@ class TestCommand(Command):
import mock
mock
except ImportError:
- print 'Missing "mock" library. mock is library is needed ' + \
- 'to run the tests. You can install it using pip: ' + \
- 'pip install mock'
+ print('Missing "mock" library. mock is library is needed '
+ 'to run the tests. You can install it using pip: '
+ 'pip install mock')
sys.exit(1)
status = self._run_tests()
@@ -74,9 +74,9 @@ class TestCommand(Command):
def _run_tests(self):
secrets = pjoin(self._dir, 'test', 'secrets.py')
if not os.path.isfile(secrets):
- print "Missing %s" % (secrets)
- print "Maybe you forgot to copy it from -dist:"
- print " cp test/secrets.py-dist test/secrets.py"
+ print("Missing %s".format(secrets))
+ print("Maybe you forgot to copy it from -dist:")
+ print(" cp test/secrets.py-dist test/secrets.py")
sys.exit(1)
pre_python26 = (sys.version_info[0] == 2
@@ -97,7 +97,7 @@ class TestCommand(Command):
missing.append("ssl")
if missing:
- print "Missing dependencies: %s" % ", ".join(missing)
+ print("Missing dependencies: %s".format(", ".join(missing)))
sys.exit(1)
testfiles = []
@@ -131,8 +131,8 @@ class Pep8Command(Command):
import pep8
pep8
except ImportError:
- print 'Missing "pep8" library. You can install it using pip: ' + \
- 'pip install pep8'
+ print ('Missing "pep8" library. You can install it using pip: '
+ 'pip install pep8')
sys.exit(1)
cwd = os.getcwd()
Modified: libcloud/branches/py3k/test/__init__.py
URL:
http://svn.apache.org/viewvc/libcloud/branches/py3k/test/__init__.py?rev=1209915&r1=1209914&r2=1209915&view=diff
==============================================================================
--- libcloud/branches/py3k/test/__init__.py (original)
+++ libcloud/branches/py3k/test/__init__.py Sat Dec 3 14:19:43 2011
@@ -13,14 +13,15 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-import httplib
import random
import unittest
-from cStringIO import StringIO
-from urllib2 import urlparse
from cgi import parse_qs
+from libcloud.py3 import httplib
+from libcloud.py3 import StringIO
+from libcloud.py3 import urllib2
+
XML_HEADERS = {'content-type': 'application/xml'}
Modified: libcloud/branches/py3k/test/test_response_classes.py
URL:
http://svn.apache.org/viewvc/libcloud/branches/py3k/test/test_response_classes.py?rev=1209915&r1=1209914&r2=1209915&view=diff
==============================================================================
--- libcloud/branches/py3k/test/test_response_classes.py (original)
+++ libcloud/branches/py3k/test/test_response_classes.py Sat Dec 3 14:19:43
2011
@@ -15,10 +15,10 @@
import sys
import unittest
-import httplib
from mock import Mock
+from libcloud.py3 import httplib
from libcloud.common.base import XmlResponse, JsonResponse
from libcloud.common.types import MalformedResponseError
Modified: libcloud/branches/py3k/test/test_utils.py
URL:
http://svn.apache.org/viewvc/libcloud/branches/py3k/test/test_utils.py?rev=1209915&r1=1209914&r2=1209915&view=diff
==============================================================================
--- libcloud/branches/py3k/test/test_utils.py (original)
+++ libcloud/branches/py3k/test/test_utils.py Sat Dec 3 14:19:43 2011
@@ -18,17 +18,21 @@ import sys
import unittest
import warnings
import os.path
-from StringIO import StringIO
# In Python > 2.7 DeprecationWarnings are disabled by default
warnings.simplefilter('default')
import libcloud.utils
+from libcloud.py3 import StringIO
+from libcloud.py3 import PY3
from libcloud.compute.types import Provider
from libcloud.compute.providers import DRIVERS
WARNINGS_BUFFER = []
+if PY3:
+ from io import FileIO as file
+
def show_warning(msg, cat, fname, lno, line=None):
WARNINGS_BUFFER.append((msg, cat, fname, lno))
Modified: libcloud/branches/py3k/tox.ini
URL:
http://svn.apache.org/viewvc/libcloud/branches/py3k/tox.ini?rev=1209915&r1=1209914&r2=1209915&view=diff
==============================================================================
--- libcloud/branches/py3k/tox.ini (original)
+++ libcloud/branches/py3k/tox.ini Sat Dec 3 14:19:43 2011
@@ -1,5 +1,5 @@
[tox]
-envlist = py25,py26,py27,pypy
+envlist = py25,py26,py27,pypy,py3
[testenv]
deps = mock
@@ -9,3 +9,6 @@ commands = python setup.py test
deps = mock
ssl
simplejson
+
+[testenv:py3]
+deps = mock