2to3 -f has_key
[sfa.git] / wsdl / sfa2wsdl.py
index 0cfc8f1..2eb9463 100755 (executable)
@@ -9,16 +9,17 @@ import os, sys
 import time
 import pdb
 import xml.dom.minidom
-#import xml.dom.ext
 import apistub
 import inspect
 
 from types import *
 from optparse import OptionParser
 
-from sfa.storage.parameter import Parameter,Mixed
+from sfa.storage.parameter import Parameter, Mixed
 
-import globals
+from sfa.util.py23 import StringType
+
+plc_ns="http://www.planet-lab.org/sfa"
 
 class SoapError(Exception):
      def __init__(self, value):
@@ -163,11 +164,11 @@ class WSDLGen:
             return "xsd:boolean"
         elif arg_type == FloatType:
             return "xsd:double"
-        elif arg_type in StringTypes:
+        elif issubclass(arg_type, StringType):
             return "xsd:string"
         else:
            pdb.set_trace()
-           raise SoapError, "Cannot handle %s objects" % arg_type
+           raise SoapError("Cannot handle %s objects" % arg_type)
 
     def param_type(self, arg):
         return (self.name_complex_type(arg))
@@ -189,7 +190,7 @@ class WSDLGen:
             in_el.setAttribute("name", method + "_in")
 
             for service_name in function.interfaces:
-                if (self.services.has_key(service_name)):
+                if (service_name in self.services):
                     if (not method in self.services[service_name]):
                         self.services[service_name].append(method)
                 else:
@@ -273,7 +274,7 @@ class WSDLGen:
                         servport_el.setAttribute("binding", "tns:" + name + "_binding")
 
                         soapaddress = servport_el.appendChild(self.wsdl.createElement("soap:address"))
-                        soapaddress.setAttribute("location", "%s/%s" % (globals.plc_ns,service))
+                        soapaddress.setAttribute("location", "%s/%s" % (plc_ns,service))
 
 
     def compute_wsdl_definitions(self):
@@ -289,7 +290,7 @@ class WSDLGen:
             xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
             xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
             xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"/>
-            """ % (self.interface_name(),globals.plc_ns,globals.plc_ns,globals.plc_ns)
+            """ % (self.interface_name(),plc_ns,plc_ns,plc_ns)
             
         self.wsdl = xml.dom.minidom.parseString(wsdl_text_header)
         
@@ -310,7 +311,7 @@ class WSDLGen:
             <types>
                 <xsd:schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="%s/schema"/>
             </types>
-        </wsdl:definitions> """ % (self.interface_name(),globals.plc_ns, globals.plc_ns, globals.plc_ns, globals.plc_ns)
+        </wsdl:definitions> """ % (self.interface_name(),plc_ns, plc_ns, plc_ns, plc_ns)
         self.types = xml.dom.minidom.parseString(wsdl_text_header)
         
 
@@ -327,10 +328,9 @@ class WSDLGen:
 
     def pretty_print(self):
         if (self.wsdl):
-            #xml.dom.ext.PrettyPrint(self.wsdl)
-            xml.dom.minidom.Document.toprettyxml(self.wsdl)
+             print xml.dom.minidom.Document.toprettyxml(self.wsdl)
         else:
-            raise Exception("Empty WSDL")
+             raise Exception("Empty WSDL")
 
 def main():
     parser = OptionParser()