libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From je...@apache.org
Subject svn commit: r1054879 - /incubator/libcloud/trunk/libcloud/drivers/linode.py
Date Tue, 04 Jan 2011 03:17:01 GMT
Author: jerry
Date: Tue Jan  4 03:16:58 2011
New Revision: 1054879

URL: http://svn.apache.org/viewvc?rev=1054879&view=rev
Log:
Provide pre-2.6 izip_longest backport in Linode driver

Modified:
    incubator/libcloud/trunk/libcloud/drivers/linode.py

Modified: incubator/libcloud/trunk/libcloud/drivers/linode.py
URL: http://svn.apache.org/viewvc/incubator/libcloud/trunk/libcloud/drivers/linode.py?rev=1054879&r1=1054878&r2=1054879&view=diff
==============================================================================
--- incubator/libcloud/trunk/libcloud/drivers/linode.py (original)
+++ incubator/libcloud/trunk/libcloud/drivers/linode.py Tue Jan  4 03:16:58 2011
@@ -578,7 +578,8 @@ class LinodeNodeDriver(NodeDriver):
         # Avoid batch limitation
         ip_answers = []
         args = [iter(batch)] * 25
-        for twenty_five in itertools.izip_longest(*args):
+        izip_longest = getattr(itertools, 'izip_longest', _izip_longest)
+        for twenty_five in izip_longest(*args):
             twenty_five = [q for q in twenty_five if q]
             params = { "api_action": "batch",
                 "api_requestArray": json.dumps(twenty_five) }
@@ -597,3 +598,19 @@ class LinodeNodeDriver(NodeDriver):
         return nodes.values()
 
     features = {"create_node": ["ssh_key", "password"]}
+
+def _izip_longest(*args, **kwds):
+    """Taken from Python docs
+
+    http://docs.python.org/library/itertools.html#itertools.izip
+    """
+    fillvalue = kwds.get('fillvalue')
+    def sentinel(counter = ([fillvalue]*(len(args)-1)).pop):
+        yield counter() # yields the fillvalue, or raises IndexError
+    fillers = itertools.repeat(fillvalue)
+    iters = [itertools.chain(it, sentinel(), fillers) for it in args]
+    try:
+        for tup in itertools.izip(*iters):
+            yield tup
+    except IndexError:
+        pass



Mime
View raw message