blind review on list-operations added by 2to3:
[nepi.git] / src / nepi / resources / planetlab / plcapi.py
index 6adfdc9..6188967 100644 (file)
@@ -3,9 +3,8 @@
 #    Copyright (C) 2013 INRIA
 #
 #    This program is free software: you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation, either version 3 of the License, or
-#    (at your option) any later version.
+#    it under the terms of the GNU General Public License version 2 as
+#    published by the Free Software Foundation;
 #
 #    This program is distributed in the hope that it will be useful,
 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -23,11 +22,11 @@ import socket
 import os
 import time
 import threading
-import xmlrpclib
+import xmlrpc.client
 
 def _retry(fn):
     def rv(*p, **kw):
-        for x in xrange(5):
+        for x in range(5):
             try:
                 return fn(*p, **kw)
             except (socket.error, IOError, OSError):
@@ -157,15 +156,15 @@ class PLCAPI(object):
         self._url = urlpattern % {'hostname':hostname}
 
         if (proxy is not None):
-            import urllib2
-            class HTTPSProxyTransport(xmlrpclib.Transport):
+            import urllib.request, urllib.error, urllib.parse
+            class HTTPSProxyTransport(xmlrpc.client.Transport):
                 def __init__(self, proxy, use_datetime=0):
-                    opener = urllib2.build_opener(urllib2.ProxyHandler({"https" : proxy}))
-                    xmlrpclib.Transport.__init__(self, use_datetime)
+                    opener = urllib.request.build_opener(urllib.request.ProxyHandler({"https" : proxy}))
+                    xmlrpc.client.Transport.__init__(self, use_datetime)
                     self.opener = opener
 
                 def request(self, host, handler, request_body, verbose=0):
-                    req = urllib2.Request('https://%s%s' % (host, handler), request_body)
+                    req = urllib.request.Request('https://%s%s' % (host, handler), request_body)
                     req.add_header('User-agent', self.user_agent)
                     self.verbose = verbose
                     return self.parse_response(self.opener.open(req))
@@ -183,7 +182,7 @@ class PLCAPI(object):
     @property
     def api(self):
         # Cannot reuse same proxy in all threads, py2.7 is not threadsafe
-        return xmlrpclib.ServerProxy(
+        return xmlrpc.client.ServerProxy(
             self._url ,
             transport = self._proxy_transport(),
             allow_none = True)
@@ -213,7 +212,7 @@ class PLCAPI(object):
         try:
             # test authorization
             network_types = _retry(self.mcapi.GetNetworkTypes)(self.auth)
-        except (xmlrpclib.ProtocolError, xmlrpclib.Fault),e:
+        except (xmlrpc.client.ProtocolError, xmlrpc.client.Fault) as e:
             warnings.warn(str(e))
         
         return True
@@ -284,8 +283,8 @@ class PLCAPI(object):
                 * nodefamily : string, the nodefamily this node should be based upon
                 * plain : boolean, use plain bootstrapfs image if set (for tests)  
         """
-        if not isinstance(node, (str, int, long)):
-            raise ValueError, "Node must be either a non-unicode string or an int"
+        if not isinstance(node, (str, int)):
+            raise ValueError("Node must be either a non-unicode string or an int")
         return _retry(self.mcapi.GetNodeFlavour)(self.auth, node)
     
     def get_nodes(self, node_id_or_name = None, fields = None, **kw):
@@ -344,7 +343,7 @@ class PLCAPI(object):
                                     filters = filters, peer=None, **kw)
                          )
                     else:
-                        peer_filter = map(name_to_id, peer)
+                        peer_filter = [name_to_id(x) for x in peer]
 
                 elif peer is None or peer == self._local_peer:
                     peer_filter = None
@@ -433,7 +432,7 @@ class PLCAPI(object):
         return _retry(self.mcapi.DeleteSliceFromNodes)(self.auth, slice_id_or_name, node_id_or_hostname)
 
     def start_multicall(self):
-        self.threadlocal.mc = xmlrpclib.MultiCall(self.mcapi)
+        self.threadlocal.mc = xmlrpc.client.MultiCall(self.mcapi)
     
     def finish_multicall(self):
         mc = self.threadlocal.mc