libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject svn commit: r1209919 - in /libcloud/branches/py3k: libcloud/common/base.py libcloud/compute/base.py libcloud/compute/drivers/ec2.py libcloud/py3.py libcloud/utils.py test/__init__.py test/compute/test_ec2.py
Date Sat, 03 Dec 2011 14:45:19 GMT
Author: tomaz
Date: Sat Dec  3 14:45:19 2011
New Revision: 1209919

URL: http://svn.apache.org/viewvc?rev=1209919&view=rev
Log:
More progress on py3k.

Modified:
    libcloud/branches/py3k/libcloud/common/base.py
    libcloud/branches/py3k/libcloud/compute/base.py
    libcloud/branches/py3k/libcloud/compute/drivers/ec2.py
    libcloud/branches/py3k/libcloud/py3.py
    libcloud/branches/py3k/libcloud/utils.py
    libcloud/branches/py3k/test/__init__.py
    libcloud/branches/py3k/test/compute/test_ec2.py

Modified: libcloud/branches/py3k/libcloud/common/base.py
URL: http://svn.apache.org/viewvc/libcloud/branches/py3k/libcloud/common/base.py?rev=1209919&r1=1209918&r2=1209919&view=diff
==============================================================================
--- libcloud/branches/py3k/libcloud/common/base.py (original)
+++ libcloud/branches/py3k/libcloud/common/base.py Sat Dec  3 14:45:19 2011
@@ -13,7 +13,6 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-import urllib
 import ssl
 import time
 
@@ -27,6 +26,7 @@ except:
 
 import libcloud
 
+from libcloud.py3 import urllib
 from libcloud.py3 import httplib
 from libcloud.py3 import urlparse
 from libcloud.py3 import StringIO

Modified: libcloud/branches/py3k/libcloud/compute/base.py
URL: http://svn.apache.org/viewvc/libcloud/branches/py3k/libcloud/compute/base.py?rev=1209919&r1=1209918&r2=1209919&view=diff
==============================================================================
--- libcloud/branches/py3k/libcloud/compute/base.py (original)
+++ libcloud/branches/py3k/libcloud/compute/base.py Sat Dec  3 14:45:19 2011
@@ -23,6 +23,8 @@ import os
 import socket
 import struct
 
+from libcloud.py3 import b
+
 import libcloud.compute.ssh
 from libcloud.pricing import get_size_price
 from libcloud.compute.types import NodeState, DeploymentError
@@ -161,7 +163,7 @@ class Node(object):
         Note, for example, that this example will always produce the
         same UUID!
         """
-        return hashlib.sha1("%s:%d" % (self.id, self.driver.type)).hexdigest()
+        return hashlib.sha1(b("%s:%d" % (self.id, self.driver.type))).hexdigest()
 
     def reboot(self):
         """Reboot this node

Modified: libcloud/branches/py3k/libcloud/compute/drivers/ec2.py
URL: http://svn.apache.org/viewvc/libcloud/branches/py3k/libcloud/compute/drivers/ec2.py?rev=1209919&r1=1209918&r2=1209919&view=diff
==============================================================================
--- libcloud/branches/py3k/libcloud/compute/drivers/ec2.py (original)
+++ libcloud/branches/py3k/libcloud/compute/drivers/ec2.py Sat Dec  3 14:45:19 2011
@@ -18,16 +18,19 @@ Amazon EC2 driver
 """
 from __future__ import with_statement
 
+import sys
 import base64
 import hmac
 import os
 import time
-import urllib
 import copy
 
 from hashlib import sha256
 from xml.etree import ElementTree as ET
 
+from libcloud.py3 import urllib
+from libcloud.py3 import b
+
 from libcloud.utils import fixxpath, findtext, findattr, findall
 from libcloud.common.base import ConnectionUserAndKey
 from libcloud.common.aws import AWSBaseResponse
@@ -226,7 +229,7 @@ class EC2Connection(ConnectionUserAndKey
                        HTTPRequestURI + "\n" +
                        CanonicalizedQueryString <from the preceding step>
         """
-        keys = params.keys()
+        keys = list(params.keys())
         keys.sort()
         pairs = []
         for key in keys:
@@ -243,7 +246,7 @@ class EC2Connection(ConnectionUserAndKey
         string_to_sign = '\n'.join(('GET', hostname, path, qs))
 
         b64_hmac = base64.b64encode(
-            hmac.new(secret_key, string_to_sign, digestmod=sha256).digest()
+            hmac.new(b(secret_key), b(string_to_sign), digestmod=sha256).digest()
         )
         return b64_hmac
 
@@ -484,7 +487,7 @@ class EC2NodeDriver(NodeDriver):
 
     def _get_sizes(self, include_cluser_instances=False):
         sizes = []
-        for key, values in self._instance_types.iteritems():
+        for key, values in self._instance_types.items():
             if not include_cluser_instances and\
                key in CLUSTER_INSTANCES_IDS:
                 continue
@@ -627,7 +630,8 @@ class EC2NodeDriver(NodeDriver):
             results.append(
                 self.connection.request(self.path, params=params.copy()).object
             )
-        except Exception, e:
+        except Exception:
+            e = sys.exc_info()[1]
             if e.args[0].find("InvalidPermission.Duplicate") == -1:
                 raise e
         params['IpProtocol'] = 'udp'
@@ -636,7 +640,8 @@ class EC2NodeDriver(NodeDriver):
             results.append(
                 self.connection.request(self.path, params=params.copy()).object
             )
-        except Exception, e:
+        except Exception:
+            e = sys.exc_info()[1]
             if e.args[0].find("InvalidPermission.Duplicate") == -1:
                 raise e
 
@@ -646,7 +651,9 @@ class EC2NodeDriver(NodeDriver):
             results.append(
                 self.connection.request(self.path, params=params.copy()).object
             )
-        except Exception, e:
+        except Exception:
+            e = sys.exc_info()[1]
+
             if e.args[0].find("InvalidPermission.Duplicate") == -1:
                 raise e
         return results

Modified: libcloud/branches/py3k/libcloud/py3.py
URL: http://svn.apache.org/viewvc/libcloud/branches/py3k/libcloud/py3.py?rev=1209919&r1=1209918&r2=1209919&view=diff
==============================================================================
--- libcloud/branches/py3k/libcloud/py3.py (original)
+++ libcloud/branches/py3k/libcloud/py3.py Sat Dec  3 14:45:19 2011
@@ -26,11 +26,42 @@ if sys.version_info >= (3, 0):
     from io import StringIO
     import urllib as urllib2
     import urllib.parse as urlparse
+
+    import urllib
+    urllib.quote = urlparse.quote
+    urllib.urlencode = urlparse.urlencode
+
+    # Taken from django.utils.py3
+    bytes = __builtins__['bytes']
+    def b(s):
+        if isinstance(s, str):
+            return s.encode("ascii")
+        elif isinstance(s, bytes):
+            return s
+        else:
+            raise TypeError("Invalid argument %r for b()" % (s,))
+    def byte(n):
+        # assume n is a Latin-1 string of length 1
+        return ord(n)
+    u = str
+    next = __builtins__['next']
+    def dictvalues(d):
+        return list(d.values())
 else:
     import httplib
     from StringIO import StringIO
     import urllib2
     import urlparse
 
+    # Taken from django.utils.py3
+    b = bytes = str
+    def byte(n):
+        return n
+    u = unicode
+    def next(i):
+        return i.next()
+    def dictvalues(d):
+        return d.values()
+
 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=1209919&r1=1209918&r2=1209919&view=diff
==============================================================================
--- libcloud/branches/py3k/libcloud/utils.py (original)
+++ libcloud/branches/py3k/libcloud/utils.py Sat Dec  3 14:45:19 2011
@@ -18,7 +18,8 @@ import mimetypes
 import warnings
 
 from libcloud.py3 import httplib
-from libcloud.py3 import PY25, PY3
+from libcloud.py3 import next
+from libcloud.py3 import PY3
 
 SHOW_DEPRECATION_WARNING = True
 SHOW_IN_DEVELOPMENT_WARNING = True
@@ -50,13 +51,8 @@ def read_in_chunks(iterator, chunk_size=
         get_data = iterator.read
         args = (chunk_size, )
     else:
-        # TODO move in a common place
-        if PY25:
-            get_data = iterator.next
-            args = ()
-        else:
-            get_data = next
-            args = (iterator, )
+        get_data = next
+        args = (iterator, )
 
     data = ''
     empty = False
@@ -97,16 +93,8 @@ 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(get_data(*args))
+        chunk = str(next(iterator))
     except StopIteration:
         chunk = ''
 
@@ -114,7 +102,7 @@ def exhaust_iterator(iterator):
         data += chunk
 
         try:
-            chunk = str(get_data(*args))
+            chunk = str(next(iterator))
         except StopIteration:
             chunk = ''
 

Modified: libcloud/branches/py3k/test/__init__.py
URL: http://svn.apache.org/viewvc/libcloud/branches/py3k/test/__init__.py?rev=1209919&r1=1209918&r2=1209919&view=diff
==============================================================================
--- libcloud/branches/py3k/test/__init__.py (original)
+++ libcloud/branches/py3k/test/__init__.py Sat Dec  3 14:45:19 2011
@@ -20,7 +20,7 @@ from cgi import parse_qs
 
 from libcloud.py3 import httplib
 from libcloud.py3 import StringIO
-from libcloud.py3 import urllib2
+from libcloud.py3 import urlparse
 
 XML_HEADERS = {'content-type': 'application/xml'}
 

Modified: libcloud/branches/py3k/test/compute/test_ec2.py
URL: http://svn.apache.org/viewvc/libcloud/branches/py3k/test/compute/test_ec2.py?rev=1209919&r1=1209918&r2=1209919&view=diff
==============================================================================
--- libcloud/branches/py3k/test/compute/test_ec2.py (original)
+++ libcloud/branches/py3k/test/compute/test_ec2.py Sat Dec  3 14:45:19 2011
@@ -14,7 +14,8 @@
 # limitations under the License.
 import sys
 import unittest
-import httplib
+
+from libcloud.py3 import httplib
 
 from libcloud.compute.drivers.ec2 import EC2NodeDriver, EC2APSENodeDriver
 from libcloud.compute.drivers.ec2 import NimbusNodeDriver, EucNodeDriver
@@ -78,7 +79,8 @@ class EC2Tests(LibcloudTestCase, TestCas
             self.driver.create_node(name='foo', image=image, size=size,
                     ex_mincount='2', ex_maxcount='2',
                     ex_clienttoken=token)
-        except IdempotentParamError, e:
+        except IdempotentParamError:
+            e = sys.exc_info()[1]
             idem_error = e
         self.assertTrue(idem_error is not None)
 



Mime
View raw message