Commits

Anonymous committed 796e5b4

make python 3 compatible

Comments (0)

Files changed (15)

 # Copyright 2013 Sergey Bozhenkov, boz at ipp.mpg.de
 # Licensed under GPLv3 or later, see the COPYING file.
 
-from client import Client
+from .client import Client
     Top level access to SOAP service.
 """
 
-import xmlnamespace
-import wsdl
+from . import xmlnamespace
+from . import wsdl
 
 def str_for_containers(self):
     """
         types = {}
         for k, v in self._types.items():
             short_name = xmlnamespace.get_local_name(k)
-            if types.has_key(short_name):
+            if short_name in types:
                 counter = 1
                 while True:
                     new_name = "%s_%d" %(short_name, counter)
                     counter += 1
-                    if not(types.has_key(new_name)):
+                    if not new_name in types:
                         short_name = new_name
                         break
             types[short_name] = v
-        types["_container"] = types.keys()
+        types["_container"] = list(types)
         types["__str__"] = str_for_containers
         types["__repr__"] = str_for_containers
         self.types = type('TypesDispatcher', (), types)()
                 attr_name : hot to attach service, i.e. self.service_1
                 methods : dict of service methods
             """
-            methods["_container"] = methods.keys()
+            methods["_container"] = list(methods)
             methods["__str__"] = str_for_containers
             methods["__repr__"] = str_for_containers
             setattr(self, attr_name,
                     type('ServiceDispatcher', (), methods)())
             self.names.append("%s %s" %(attr_name, name))
 
-        if len(self._services.keys()) == 1:
-            create(self._services.keys()[0], "service",
-                   self._services.items()[0][1])
+        if len(self._services) == 1:
+            l = list(self._services)
+            create(l[0], "service", self._services[l[0]])
         else:
             counter = 1
             for k, v in self._services.items():
 """
    Python class for input/output messages.
 """
-import xmlnamespace
-import xmltypes
+from . import xmlnamespace
+from . import xmltypes
 import xml.etree.cElementTree as etree
 
 class Message(object):
             for child in getattr(p, "_children", []):
                 opt = ''
                 array = ''
-                if child['max']>1:
-                     # 'unbounded'>1
+                if child['max'].__class__.__name__ != "int" or child['max']>1:
                      array = '[]'
                 if child['min']==0:
                     opt = '| None'
             for child in getattr(p, "_children", []):
                 opt = ''
                 array = ''
-                if child['max']>1:
-                     # 'unbounded'>1
+                if child['max'].__class__.__name__ != "int" or child['max']>1:
                      array = '[]'
                 if child['min']==0:
                     opt = '| None'
             child = p._children[0]
             opt = ''
             array = ''
-            if child['max']>1:
-                 # 'unbounded'>1
+            if child['max'].__class__.__name__ != "int" or child['max']>1:
                  array = '[]'
             if child['min']==0:
                 opt = '| None'
 """
     SOAP operation class.
 """
-import xmlnamespace
-import xmlparser
-from urllib2 import urlopen, Request, HTTPError
+from . import xmlnamespace
+from . import xmlparser
+import sys
+if sys.version_info.major < 3:
+    from urllib2 import urlopen, Request, HTTPError
+else:
+    from urllib.request import urlopen, Request, HTTPError
 import xml.etree.cElementTree as etree
 
 #some standard stuff
                 return None
             else:
                 raise RuntimeError("Bad HTTP status code: %d" %response.code)
-        except HTTPError, e:
+        except HTTPError as e:
             if e.code == 500:
                 #read http error body and make xml from it
                 try:
 """
     Conversion of WSDL documents into Python.
 """
-import xmlnamespace
-import xmlparser
-import xmlschema
-import xmltypes
-import message
-import method
+from . import xmlnamespace
+from . import xmlparser
+from . import xmlschema
+from . import xmltypes
+from . import message
+from . import method
 import xml.etree.cElementTree as etree
 
 class WSDLParser(object):
                     part_type = y.get("type", None)
                 if part_type is None:
                     raise ValueError("Could not find part type in:\n %s"\
-                                     %(etree.tostring(x)))
+                                     %(etree.tostring(x).decode()))
                 cls = None
-                if types.has_key(part_type):
+                if part_type in types:
                     cls = types[part_type]
-                elif xmltypes.primmap.has_key(part_type):
+                elif part_type in xmltypes.primmap:
                     cls = xmltypes.primmap[part_type]
                 else:
                     raise ValueError("Type %s not found for message:\n%s"\
-                                    %(part_type, etree.tostring(x)))
+                                    %(part_type, etree.tostring(x).decode()))
                 parts.append([part_name, cls])
             messages[message_name] = message.Message(message_name,
                                                      parts)
                 xin = xop.findall('./{%s}input' %xmlnamespace.NS_WSDL)
                 if not(xin):
                     raise ValueError("No input message in operation: \n%s"\
-                                     %(etree.tostring(xop)))
+                                     %(etree.tostring(xop).decode()))
                 in_name = xin[0].get("message", "")
-                if not(messages.has_key(in_name)):
+                if not in_name in messages:
                     raise ValueError("Message %s not found." %in_name)
                 in_cl = messages[in_name]
                 out_cl = None
                 xout = xop.findall('./{%s}output' %xmlnamespace.NS_WSDL)
                 if xout:
                     out_name = xout[0].get("message", "")
-                    if not(messages.has_key(out_name)):
+                    if not out_name in messages:
                         raise ValueError("Message %s not found." %in_name)
                     out_cl = messages[out_name]
 
             b_type = xb.get("type", None)
             if b_type is None:
                 raise ValueError("No type in binding %s"\
-                                    %(etree.tostring(xb)))
-            if not(operations.has_key(b_type)):
+                                    %(etree.tostring(xb).decode()))
+            if not b_type in operations:
                 raise ValueError("Binding type %s no in operations" %b_type)
             xb_soap = xb.findall("./{%s}binding" %xmlnamespace.NS_SOAP)
             if not(xb_soap):
             xops = xb.findall("./{%s}operation" %xmlnamespace.NS_WSDL)
             for xop in xops:
                 op_name = xop.get("name", "")
-                if not(ops.has_key(op_name)):
+                if not op_name in ops:
                     raise ValueError("operation %s no in operations"\
                                     %op_name)
                 soap_op = xop.find("./{%s}operation" %xmlnamespace.NS_SOAP)
                     xop_in_body = xop_in.find("./{%s}body" %xmlnamespace.NS_SOAP)
                     if xop_in_body is None:
                         raise ValueError("No body found for %s"\
-                                    %(etree.tostring(xop)))
+                                    %(etree.tostring(xop).decode()))
                     if xop_in_body.get("use") != "literal":
                         all_literal = False
                     parts = xop_in_body.get("parts")
                     xop_out_body = xop_out.find("./{%s}body" %xmlnamespace.NS_SOAP)
                     if xop_out_body is None:
                         raise ValueError("No body found for %s"\
-                                    %(etree.tostring(xop)))
+                                    %(etree.tostring(xop).decode()))
                     if xop_out_body.get("use") != "literal":
                         all_literal = False
                     parts = xop_out_body.get("parts")
                 if not(xaddr):
                     continue # no soap 11
                 loc = xaddr[0].get("location", "")
-                if bindings.has_key(b):
+                if b in bindings:
                     for k,v in bindings[b].items():
                         v.location = loc
                     services[s_name] = bindings[b]
     Help functions for dealing with xml.
 """
 import xml.etree.cElementTree as etree
-import urllib2
+import sys
+if sys.version_info.major < 3:
+    from urllib2 import urlopen, HTTPError
+else:
+    from urllib.request import urlopen, HTTPError
 
 default_attr = ["type", "base", "element", "message", "binding", "ref"]
 
             if root is None:
                 root = element
             #check that this element has an attribute of interest
-            for a in element.attrib.keys():
+            for a in element.attrib:
                 if a in attr:
                     #check the attribute value is qualified
                     vlist =  element.attrib[a].split(":")
     # parse it into xml
     try:
         # opens http://, https://, file://
-        page_handler = urllib2.urlopen(url)
-    except (urllib2.HTTPError, ValueError):
+        page_handler = urlopen(url)
+    except (HTTPError, ValueError):
         try:
             # url is something /path/to/file, use open directly
             page_handler = open(url, 'r')
                 # wsdl_url 'directory' + filename
                 orig_url = url
                 url = wsdl_url.rsplit('/', 1)[0] + '/' + url
-                page_handler = urllib2.urlopen(url)
-            except (urllib2.HTTPError, ValueError):
+                page_handler = urlopen(url)
+            except (HTTPError, ValueError):
                 raise ValueError("Can not found '%s'." % orig_url)
 
     root = parse_qualified(page_handler, attr=attr)
 """
     Conversion of XML Schema types into Python classes.
 """
-import xmlnamespace
-import xmltypes
-import xmlparser
+from . import xmlnamespace
+from . import xmltypes
+from . import xmlparser
 import xml.etree.cElementTree as etree
 
 class XMLSchemaParser(object):
             if name is not None:
                 name = "{%s}%s" %(self.tns, name)
                 el.set("qualified", self.qualified)
-                if not(types.has_key(name)):
+                if not name in types:
                     types[name] = el
 
         #go over all children and append their types
             out : dictionary name -> Python class
         """
         types = {} 
-        for k in xtypes.keys():
+        for k in xtypes:
             #if the class was already created as a parent of another class, do nothing
-            if types.has_key(k):
+            if k in types:
                 continue
             x = xtypes[k]
             XMLSchemaParser.create_type(k, x, xtypes, types)
         """
         if name is None:
             return
-        elif xmltypes.primmap.has_key(name):
+        elif name in xmltypes.primmap:
             cl = xmltypes.primmap[name]
-        elif types.has_key(name):
+        elif name in types:
             cl = types[name]
-        elif not(xtypes.has_key(name)):
+        elif not name in xtypes:
             raise ValueError(" Class %s not found in anywhere" %(name))
         else:
             XMLSchemaParser.create_type(name,
 """
     Python classes corresponding to XML schema.
 """
-import xmlnamespace
+from . import xmlnamespace
 from decimal import Decimal
 from datetime import date, datetime, time
 import xml.etree.cElementTree as etree
 import base64
+import sys
+if sys.version_info.major > 2:
+    unicode = str
 
 
 def get_local_type(xmltype):
             val = val_type(deep=deep)
         else:
             val = val_type()
-        if child['max'] > 1:
-            #'unbounded' > 1
+        if child['max'].__class__.__name__ != "int" or child['max']>1:
             val = [val,]
         setattr(self, child['name'], val)
 
     for child in self._children:
         child_name = child['name']
         array = ''
-        if child['max']>1:
-             # 'unbounded'>1
+        if child['max'].__class__.__name__ != "int" or child['max']>1:
              array = '[]'
         child_value = getattr(self, child_name, None)
         many = False
     """
     _namespace = ""
 
-
-    def check_constraints(self, n, min_occurs, max_occurs):
-        """
-            Performs constraints checking.
-
-            Parameters
-            ----------
-            n : int
-                Actual number of occurrences.
-            min_occurs : int
-                Minimal allowed number of occurrences.
-            max_occurs : int or 'unbounded'
-                Maximal allowed number of occurrences.
-
-           Raises
-           ------
-            ValueError
-                If constraints are not satisfied.
-        """
-        if n<min_occurs:
-            raise ValueError("Number of values n=%d is less than min_occurs=%d"\
-                                        %(n, min_occurs))
-        if n > max_occurs:
-            raise ValueError("Number of values n=%d is more than max_occurs n=%s"\
-                                        %(n, str(max_occurs)))
-
     def to_xml(self, parent, name):
         """
             Function to convert to xml from python representation.
 
             #do constraints checking
             n = 0 #number of values for constraints checking
-            if hasattr(val, "__iter__"):#isinstance(val, (list, tuple)):
+            if hasattr(val, "__iter__") and val.__class__.__name__ != "str":
                 n = len(val)
             elif val is not None:
                 n = 1
 
             if n < child["min"]:
                 raise ValueError("Number of values for %s is less than min_occurs: %s" %(name, str(val)))
-            if n > child["max"]:
+            if child["max"].__class__.__name__ == "int" and n > child["max"]:
                 raise ValueError("Number of values for %s is more than max_occurs: %s" %(name, str(val)))
 
             if n == 0:
                 if self._children[ind]['min'] != 0:
                     raise ValueError("Non-nillable %s element is nil." %name)
             else:
-                #unbounded is larger than 1
-                if self._children[ind]['max'] > 1:
+                if self._children[ind]['max'].__class__.__name__ != "int" or\
+                   self._children[ind]['max']>1:
                     current_value = getattr(self, name, None)
                     if current_value is None:
                         current_value = []
         root = etree.Element("root")
         self.to_xml(root, fullname)
         f = open(fname, "w")
-        f.write(etree.tostring(root[0]))
+        f.write(etree.tostring(root[0]).decode())
         f.close()
 
     @classmethod
                 Attributes of the new type.
         """
         #list of children, even if empty, must be always present
-        if not(attributes.has_key("_children")):
+        if not "_children" in attributes:
             attributes["_children"] = []
 
         #create dictionary for initializing class arguments
             bases = tuple(newBases)
 
         #propagate other non-reserved atributes
-        for k in attributes.keys():
+        for k in attributes:
             if k not in ("_children", "__init__", "__doc__",
                     "__ne__", "__eq__", "__str__", "__repr__"):
                 clsDict[k] = attributes[k]
 
     def from_xml(self, element):
         if element.text:
-            return element.text.encode('utf-8')
+            return element.text
         else:
             return None
 
     def from_xml(self, element):
         val = ""
         if element.text:
-            val = element.text.encode('utf-8')
+            val = element.text
         if val not in self._allowedValues:
             raise ValueError("Not allowed value for this enumeration: value = %s" %(val))
         return val
 from osa.wsdl import *
 from osa.method import *
 from osa.xmltypes import *
-import urllib2
+import sys
+if sys.version_info.major < 3:
+    from urllib2 import urlopen, HTTPError, URLError
+else:
+    from urllib.request import urlopen, HTTPError, URLError
+    basestring = str
 
 wsdl_url = 'http://lxpowerboz:88/services/python/HelloWorldService?wsdl'
 
     def tearDown(self):
         self.client = None
     def test_init(self):
-        self.assertEquals(self.client.names, ["service HelloWorldService",])
+        self.assertEqual(self.client.names, ["service HelloWorldService",])
         for t in ("Person", "Name", "echoString", "sayHello"):
             self.assertTrue(hasattr(self.client.types, t))
-            self.assertEquals(type(getattr(self.client.types, t)), ComplexTypeMeta)
+            self.assertEqual(type(getattr(self.client.types, t)), ComplexTypeMeta)
         for method in ("testMe", "giveMessage", "echoString", "sayHello", "faultyThing"):
             self.assertTrue(hasattr(self.client.service, method))
-            self.assertEquals(type(getattr(self.client.service, method)), Method)
+            self.assertEqual(type(getattr(self.client.service, method)), Method)
 
     def test_giveMessage(self):
         try:
-            urllib2.urlopen("http://lxpowerboz:88")
-        except urllib2.HTTPError:
+            urlopen("http://lxpowerboz:88")
+        except HTTPError:
             pass
-        except urllib2.URLError:
+        except URLError:
             return
         res = self.client.service.giveMessage()
-        self.assertTrue(isinstance(res, str))
+        self.assertTrue(isinstance(res, basestring))
 
     def test_echoString(self):
         try:
-            urllib2.urlopen("http://lxpowerboz:88")
-        except urllib2.HTTPError:
+            urlopen("http://lxpowerboz:88")
+        except HTTPError:
             pass
-        except urllib2.URLError:
+        except URLError:
             return
-        self.assertEquals('my message 1', self.client.service.echoString('my message 1'))
+        self.assertEqual('my message 1', self.client.service.echoString('my message 1'))
 
     def test_sayHello(self):
         try:
-            urllib2.urlopen("http://lxpowerboz:88")
-        except urllib2.HTTPError:
+            urlopen("http://lxpowerboz:88")
+        except HTTPError:
             pass
-        except urllib2.URLError:
+        except URLError:
             return
         n = self.client.types.Name()
         n.firstName = "first"
         p.age = 30
         p.weight = 80
         p.height = 175
-        self.assertEquals(['Hello, first\n']*5, self.client.service.sayHello(p, 5))
+        self.assertEqual(['Hello, first\n']*5, self.client.service.sayHello(p, 5))
 
     def test_faultyThing(self):
         try:
-            urllib2.urlopen("http://lxpowerboz:88")
-        except urllib2.HTTPError:
+            urlopen("http://lxpowerboz:88")
+        except HTTPError:
             pass
-        except urllib2.URLError:
+        except URLError:
             return
         try:
             self.client.service.faultyThing()

tests/test_message.py

         name.firstName = "bobo"
         name.lastName = "khnyk"
         message.to_xml(name, _body=root)
-        self.assertEquals(len(root), 1)
-        self.assertEquals(root[0].tag, "{vostok}Name")
-        self.assertEquals(len(root[0]), 2)
+        self.assertEqual(len(root), 1)
+        self.assertEqual(root[0].tag, "{vostok}Name")
+        self.assertEqual(len(root[0]), 2)
         #positional parameters
         root = etree.Element("root")
         message.to_xml("bobik", "sharikov", _body=root)
-        self.assertEquals(len(root), 1)
-        self.assertEquals(root[0].tag, "{vostok}Name")
-        self.assertEquals(len(root[0]), 2)
+        self.assertEqual(len(root), 1)
+        self.assertEqual(root[0].tag, "{vostok}Name")
+        self.assertEqual(len(root[0]), 2)
         #keyword parameters
         root = etree.Element("root")
         message.to_xml(lastName = "zaa", firstName="yoyo", _body=root)
-        self.assertEquals(len(root), 1)
-        self.assertEquals(root[0].tag, "{vostok}Name")
-        self.assertEquals(len(root[0]), 2)
+        self.assertEqual(len(root), 1)
+        self.assertEqual(root[0].tag, "{vostok}Name")
+        self.assertEqual(len(root[0]), 2)
 
     def test_fromxml(self):
         root = etree.Element("Name")
                                   ])
         message.use_parts = [message.parts[1]]
         res = message.from_xml(root)
-        self.assertEquals(res.__class__.__name__, "Name")
-        self.assertEquals(res.firstName, "kolo")
-        self.assertEquals(res.lastName, "bok")
+        self.assertEqual(res.__class__.__name__, "Name")
+        self.assertEqual(res.firstName, "kolo")
+        self.assertEqual(res.lastName, "bok")
 
 
 if __name__ == '__main__':
 class TestWSDL(unittest.TestCase):
     def test_reading(self):
         w = WSDLParser(wsdl_url)
-        self.assertEquals(w.wsdl_url, wsdl_url)
-        self.assertEquals(w.tns, "de.mpg.ipp.hgw.boz.gsoap.helloworld")
-        self.assertEquals(type(w.wsdl), type(etree.Element('root')))
+        self.assertEqual(w.wsdl_url, wsdl_url)
+        self.assertEqual(w.tns, "de.mpg.ipp.hgw.boz.gsoap.helloworld")
+        self.assertEqual(type(w.wsdl), type(etree.Element('root')))
 
     def test_get_types(self):
         w = WSDLParser(wsdl_url)
                  "faultyThingResponse", "sayHello",
                  "sayHelloResponse")
         for n in names:
-            self.assertTrue(msgs.has_key("{%s}%s" %(ns1, n)))
+            self.assertTrue("{%s}%s" %(ns1, n) in msgs)
             m = msgs["{%s}%s" %(ns1, n)]
             self.assertTrue(isinstance(m, Message))
-            self.assertEquals(m.name, "{%s}%s" %(ns1, n))
-            self.assertEquals(len(m.parts), 1)
-            self.assertEquals(len(m.parts[0]), 2)
-            self.assertEquals(m.parts[0][0], "parameters")
+            self.assertEqual(m.name, "{%s}%s" %(ns1, n))
+            self.assertEqual(len(m.parts), 1)
+            self.assertEqual(len(m.parts[0]), 2)
+            self.assertEqual(m.parts[0][0], "parameters")
 
     def test_get_operations(self):
         w = WSDLParser(wsdl_url)
         types = w.get_types()
         msgs = w.get_messages(types)
         ops = w.get_operations(msgs)
-        self.assertTrue(ops.has_key("{%s}HelloWorldServicePortType" %ns1))
+        self.assertTrue("{%s}HelloWorldServicePortType" %ns1 in ops)
         ops = ops["{%s}HelloWorldServicePortType" %ns1]
         names = ("testMe", "giveMessage", "echoString", "faultyThing", "sayHello")
         for n in names:
-            self.assertTrue(ops.has_key(n))
+            self.assertTrue(n in ops)
             op = ops[n]
             self.assertTrue(isinstance(op, Method))
             self.assertTrue(isinstance(op.input, Message))
         ops = w.get_operations(msgs)
         bs = w.get_bindings(ops)
         ops = ops["{%s}HelloWorldServicePortType" %ns1]
-        self.assertTrue(bs.has_key("{%s}HelloWorldService" %ns1))
+        self.assertTrue("{%s}HelloWorldService" %ns1 in bs)
         bs = bs["{%s}HelloWorldService" %ns1]
         names = ("testMe", "giveMessage", "echoString", "faultyThing", "sayHello")
         for n in names:
-            self.assertTrue(bs.has_key(n))
+            self.assertTrue(n in bs)
             b = bs[n]
             op = ops[n]
             self.assertTrue(b is op)
             self.assertTrue(b.input.use_parts is not None)
-            self.assertEquals(len(b.input.use_parts), 1)
-            self.assertEquals(b.input.use_parts[0][0], "parameters")
+            self.assertEqual(len(b.input.use_parts), 1)
+            self.assertEqual(b.input.use_parts[0][0], "parameters")
             if n != "testMe":
-                self.assertEquals(len(b.output.use_parts), 1)
-                self.assertEquals(b.output.use_parts[0][0], "parameters")
-            self.assertEquals(b.action, "")
+                self.assertEqual(len(b.output.use_parts), 1)
+                self.assertEqual(b.output.use_parts[0][0], "parameters")
+            self.assertEqual(b.action, "")
 
     def test_get_services(self):
         w = WSDLParser(wsdl_url)
         bs = w.get_bindings(ops)
         ss = w.get_services(bs)
         bs = bs["{%s}HelloWorldService" %ns1]
-        self.assertTrue(ss.has_key("HelloWorldService"))
+        self.assertTrue("HelloWorldService" in ss)
         ss = ss["HelloWorldService"]
         names = ("testMe", "giveMessage", "echoString", "faultyThing", "sayHello")
         for n in names:
-            self.assertTrue(ss.has_key(n))
+            self.assertTrue(n in ss)
             s = ss[n]
             b = bs[n]
             self.assertTrue(s is b)
-            self.assertEquals(s.location, "http://lxpowerboz:88/services/cpp/HelloWorldService")
+            self.assertEqual(s.location, "http://lxpowerboz:88/services/cpp/HelloWorldService")
 
 
 if __name__ == '__main__':

tests/test_xmlparser.py

 class TestXMLParser(unittest.TestCase):
     def test_ns_attr_parsing(self):
         root = parse_qualified_from_url("test.xml", attr=["a"])
-        self.assertEquals(root.get("bok"), "ns:round")
-        self.assertEquals(root[0].get("a"), "{39kingdom}angry")
+        self.assertEqual(root.get("bok"), "ns:round")
+        self.assertEqual(root[0].get("a"), "{39kingdom}angry")
 
 if __name__ == '__main__':
     unittest.main()

tests/test_xmlschema.py

         self.schema = None
     def test_get_list_of_types(self):
         res = self.schema.get_list_of_defined_types()
-        self.assertTrue(res.has_key("{vostok}Name"))
-        self.assertEquals(res["{vostok}Name"].tag, "{%s}complexType" %xmlnamespace.NS_XSD)
-        self.assertEquals(res["{vostok}Name"].get("name"), "Name")
-        self.assertTrue(res.has_key("{vostok}Person"))
-        self.assertEquals(res["{vostok}Person"].tag, "{%s}element" %xmlnamespace.NS_XSD)
-        self.assertEquals(res["{vostok}Person"].get("name"), "Person")
-        self.assertTrue(res.has_key("{vostok}Robot"))
-        self.assertEquals(res["{vostok}Robot"].tag, "{%s}element" %xmlnamespace.NS_XSD)
-        self.assertEquals(res["{vostok}Robot"].get("name"), "Robot")
-        self.assertTrue(res.has_key("{vostok}Counter"))
-        self.assertEquals(res["{vostok}Counter"].tag, "{%s}simpleType" %xmlnamespace.NS_XSD)
-        self.assertEquals(res["{vostok}Counter"].get("name"), "Counter")
-        self.assertTrue(res.has_key("{vostok}Profession"))
-        self.assertEquals(res["{vostok}Profession"].tag, "{%s}simpleType" %xmlnamespace.NS_XSD)
-        self.assertEquals(res["{vostok}Profession"].get("name"), "Profession")
-        self.assertTrue(res.has_key("{vostok}Shish"))
-        self.assertEquals(res["{vostok}Shish"].tag, "{%s}element" %xmlnamespace.NS_XSD)
-        self.assertEquals(res["{vostok}Shish"].get("name"), "Shish")
-        self.assertTrue(res.has_key("{zapad}Address"))
-        self.assertEquals(res["{zapad}Address"].tag, "{%s}complexType" %xmlnamespace.NS_XSD)
-        self.assertEquals(res["{zapad}Address"].get("name"), "Address")
-        self.assertTrue(res.has_key("{sever}Car"))
-        self.assertEquals(res["{sever}Car"].tag, "{%s}complexType" %xmlnamespace.NS_XSD)
-        self.assertEquals(res["{sever}Car"].get("name"), "Car")
+        self.assertTrue("{vostok}Name" in res)
+        self.assertEqual(res["{vostok}Name"].tag, "{%s}complexType" %xmlnamespace.NS_XSD)
+        self.assertEqual(res["{vostok}Name"].get("name"), "Name")
+        self.assertTrue("{vostok}Person" in res)
+        self.assertEqual(res["{vostok}Person"].tag, "{%s}element" %xmlnamespace.NS_XSD)
+        self.assertEqual(res["{vostok}Person"].get("name"), "Person")
+        self.assertTrue("{vostok}Robot" in res)
+        self.assertEqual(res["{vostok}Robot"].tag, "{%s}element" %xmlnamespace.NS_XSD)
+        self.assertEqual(res["{vostok}Robot"].get("name"), "Robot")
+        self.assertTrue("{vostok}Counter" in res)
+        self.assertEqual(res["{vostok}Counter"].tag, "{%s}simpleType" %xmlnamespace.NS_XSD)
+        self.assertEqual(res["{vostok}Counter"].get("name"), "Counter")
+        self.assertTrue("{vostok}Profession" in res)
+        self.assertEqual(res["{vostok}Profession"].tag, "{%s}simpleType" %xmlnamespace.NS_XSD)
+        self.assertEqual(res["{vostok}Profession"].get("name"), "Profession")
+        self.assertTrue("{vostok}Shish" in res)
+        self.assertEqual(res["{vostok}Shish"].tag, "{%s}element" %xmlnamespace.NS_XSD)
+        self.assertEqual(res["{vostok}Shish"].get("name"), "Shish")
+        self.assertTrue("{zapad}Address" in res)
+        self.assertEqual(res["{zapad}Address"].tag, "{%s}complexType" %xmlnamespace.NS_XSD)
+        self.assertEqual(res["{zapad}Address"].get("name"), "Address")
+        self.assertTrue("{sever}Car" in res)
+        self.assertEqual(res["{sever}Car"].tag, "{%s}complexType" %xmlnamespace.NS_XSD)
+        self.assertEqual(res["{sever}Car"].get("name"), "Car")
     def test_convert(self):
         xtypes = self.schema.get_list_of_defined_types()
         types = XMLSchemaParser.convert_xmltypes_to_python(xtypes)
         self.assertEqual(types["{vostok}Name"].__class__.__name__, "ComplexTypeMeta")
-        self.assertTrue(types.has_key("{vostok}Name"))
+        self.assertTrue("{vostok}Name" in types)
         self.assertTrue(hasattr(types["{vostok}Name"], "firstName"))
         self.assertTrue(hasattr(types["{vostok}Name"], "lastName"))
-        self.assertEquals(types["{vostok}Name"]._namespace, "vostok")
-        self.assertTrue(types.has_key("{vostok}Person"))
+        self.assertEqual(types["{vostok}Name"]._namespace, "vostok")
+        self.assertTrue("{vostok}Person" in types)
         self.assertEqual(types["{vostok}Person"].__class__.__name__, "ComplexTypeMeta")
         self.assertTrue(hasattr(types["{vostok}Person"], "age"))
         self.assertTrue(hasattr(types["{vostok}Person"], "weight"))
         self.assertTrue(hasattr(types["{vostok}Person"], "place"))
         self.assertTrue(hasattr(types["{vostok}Person"], "car"))
         self.assertTrue(hasattr(types["{vostok}Person"], "Comment"))
-        self.assertEquals(types["{vostok}Person"]._namespace, "vostok")
-        self.assertTrue(types.has_key("{vostok}Robot"))
+        self.assertEqual(types["{vostok}Person"]._namespace, "vostok")
+        self.assertTrue("{vostok}Robot" in types)
         self.assertEqual(types["{vostok}Robot"].__class__.__name__, "ComplexTypeMeta")
         self.assertTrue(hasattr(types["{vostok}Robot"], "age"))
         self.assertTrue(hasattr(types["{vostok}Robot"], "weight"))
         self.assertTrue(hasattr(types["{vostok}Robot"], "place"))
         self.assertTrue(hasattr(types["{vostok}Robot"], "car"))
         self.assertTrue(hasattr(types["{vostok}Robot"], "Comment"))
-        self.assertEquals(types["{vostok}Robot"]._namespace, "vostok")
-        self.assertTrue(types.has_key("{vostok}Counter"))
-        self.assertEquals(types["{vostok}Counter"].__base__.__name__, "XMLInteger")
+        self.assertEqual(types["{vostok}Robot"]._namespace, "vostok")
+        self.assertTrue("{vostok}Counter" in types)
+        self.assertEqual(types["{vostok}Counter"].__base__.__name__, "XMLInteger")
         self.assertTrue(isinstance(types["{vostok}Counter"](), int))
-        self.assertEquals(types["{vostok}Counter"]._namespace, "vostok")
-        self.assertTrue(types.has_key("{vostok}Profession"))
-        self.assertEquals(len(types["{vostok}Profession"]._allowedValues), 2)
+        self.assertEqual(types["{vostok}Counter"]._namespace, "vostok")
+        self.assertTrue("{vostok}Profession" in types)
+        self.assertEqual(len(types["{vostok}Profession"]._allowedValues), 2)
         self.assertTrue("cosmonaut" in types["{vostok}Profession"]._allowedValues)
         self.assertTrue("scientist" in types["{vostok}Profession"]._allowedValues)
-        self.assertEquals(types["{vostok}Profession"]._namespace, "vostok")
-        self.assertEquals(types["{vostok}Profession"].__base__.__name__, "XMLStringEnumeration")
-        self.assertTrue(types.has_key("{vostok}Shish"))
+        self.assertEqual(types["{vostok}Profession"]._namespace, "vostok")
+        self.assertEqual(types["{vostok}Profession"].__base__.__name__, "XMLStringEnumeration")
+        self.assertTrue("{vostok}Shish" in types)
         self.assertEqual(types["{vostok}Shish"].__class__.__name__, "ComplexTypeMeta")
         self.assertEqual(len(types["{vostok}Shish"]._children), 0)
-        self.assertTrue(types.has_key("{zapad}Address"))
+        self.assertTrue("{zapad}Address" in types)
         self.assertTrue(hasattr(types["{zapad}Address"], "city"))
         self.assertTrue(hasattr(types["{zapad}Address"], "country"))
-        self.assertEquals(types["{zapad}Address"]._namespace, "zapad")
+        self.assertEqual(types["{zapad}Address"]._namespace, "zapad")
         self.assertEqual(types["{zapad}Address"].__class__.__name__, "ComplexTypeMeta")
-        self.assertTrue(types.has_key("{sever}Car"))
+        self.assertTrue("{sever}Car" in types)
         self.assertTrue(hasattr(types["{sever}Car"], "model"))
         self.assertTrue(hasattr(types["{sever}Car"], "weight"))
-        self.assertEquals(types["{sever}Car"]._namespace, "sever")
+        self.assertEqual(types["{sever}Car"]._namespace, "sever")
         self.assertEqual(types["{sever}Car"].__class__.__name__, "ComplexTypeMeta")
 if __name__ == '__main__':
     unittest.main()

tests/test_xmltypes_complex.py

         element = etree.Element('test')
         a.to_xml( element, "{%s}%s" %(ns_test, "atach"))
         element = element[0]
-        self.assertEquals(5, len(element.getchildren()))
+        self.assertEqual(5, len(element.getchildren()))
 
         r = Address().from_xml(element)
 
-        self.assertEquals(a.street, r.street)
-        self.assertEquals(a.city, r.city)
-        self.assertEquals(a.zip, r.zip)
-        self.assertEquals(a.lattitude, r.lattitude)
-        self.assertEquals(a.longitude, r.longitude)
-        self.assertEquals(a.since, r.since)
+        self.assertEqual(a.street, r.street)
+        self.assertEqual(a.city, r.city)
+        self.assertEqual(a.zip, r.zip)
+        self.assertEqual(a.lattitude, r.lattitude)
+        self.assertEqual(a.longitude, r.longitude)
+        self.assertEqual(a.since, r.since)
 
     def test_nested_class(self):
         p = Person()
         p.to_xml(element, "{%s}%s" %(ns_test, "atach"))
         element = element[0]
 
-        self.assertEquals(None, p.name)
-        self.assertEquals(None, p.birthdate)
-        self.assertEquals(None, p.age)
-        self.assertEquals(None, p.addresses)
+        self.assertEqual(None, p.name)
+        self.assertEqual(None, p.birthdate)
+        self.assertEqual(None, p.age)
+        self.assertEqual(None, p.addresses)
 
     def test_complex_class(self):
         l = Level1()
         element = element[0]
         l1 = Level1().from_xml(element)
 
-        self.assertEquals(l1.level2.arg1, l.level2.arg1)
-        self.assertEquals(l1.level2.arg2, l.level2.arg2)
-        self.assertEquals(len(l1.level4), len(l.level4))
-        self.assertEquals(len(l1.level3), len(l.level3))
+        self.assertEqual(l1.level2.arg1, l.level2.arg1)
+        self.assertEqual(l1.level2.arg2, l.level2.arg2)
+        self.assertEqual(len(l1.level4), len(l.level4))
+        self.assertEqual(len(l1.level3), len(l.level3))
         for i in range(100):
-            self.assertEquals(l1.level3[i].arg1, l.level3[i].arg1)
+            self.assertEqual(l1.level3[i].arg1, l.level3[i].arg1)
         for i in range(4):
-            self.assertEquals(l1.level4[i].arg1, l.level4[i].arg1)
+            self.assertEqual(l1.level4[i].arg1, l.level4[i].arg1)
 
 
     def test_any(self):
         r = XMLAny().from_xml(element)
         self.assertTrue(isinstance(r, Address))
 
-        self.assertEquals(a.street, r.street)
-        self.assertEquals(a.city, r.city)
-        self.assertEquals(a.zip, r.zip)
-        self.assertEquals(a.lattitude, r.lattitude)
-        self.assertEquals(a.longitude, r.longitude)
-        self.assertEquals(a.since, r.since)
+        self.assertEqual(a.street, r.street)
+        self.assertEqual(a.city, r.city)
+        self.assertEqual(a.zip, r.zip)
+        self.assertEqual(a.lattitude, r.lattitude)
+        self.assertEqual(a.longitude, r.longitude)
+        self.assertEqual(a.since, r.since)
     def test_tofrom_file(self):
         fname = "out.xml"
         a = Address()
             pass
         a.to_file(fname)
         b = Address.from_file(fname)
-        self.assertEquals(b, a)
+        self.assertEqual(b, a)
         self.assertTrue(b is not a)
 
 if __name__ == '__main__':

tests/test_xmltypes_primitive.py

         s.to_xml(element, "{%s}%s" %(ns_test, "atach"))
         element=element[0]
 
-        self.assertEquals(element.text, 'value')
+        self.assertEqual(element.text, 'value')
         value = XMLString().from_xml(element)
-        self.assertEquals(value, 'value')
+        self.assertEqual(value, 'value')
     
     def test_stringenumeration(self):
         XMLStringEnumeration._allowedValues = ["me", "you"]
         s1 = XMLStringEnumeration("me")
-        self.assertEquals(s1.value, "me")
+        self.assertEqual(s1.value, "me")
         s2 = XMLStringEnumeration("he")
-        self.assertEquals(s2.value, "he")
+        self.assertEqual(s2.value, "he")
 
         #toxml
         element = etree.Element('test')
         s1.to_xml(element, "{%s}%s" %(ns_test, "atach"))
         element=element[0]
-        self.assertEquals(element.text, 'me')
+        self.assertEqual(element.text, 'me')
 
         element2 = etree.Element('test')
         self.assertRaises(ValueError, s2.to_xml, element2, "{%s}%s" %(ns_test, "atach"))
 
         #back
         value = XMLStringEnumeration().from_xml(element)
-        self.assertEquals(value, 'me')
+        self.assertEqual(value, 'me')
         element.text="he"
         self.assertRaises(ValueError, XMLStringEnumeration().from_xml, element)
 
         d.to_xml(element, "{%s}%s" %(ns_test, "atach"))
         element = element[0]
 
-        self.assertEquals(element.text, d.value.isoformat())
+        self.assertEqual(element.text, d.value.isoformat())
         dt = XMLDateTime().from_xml(element)
-        self.assertEquals(d.value, dt)
+        self.assertEqual(d.value, dt)
 
     def test_date(self):
         x = datetime.now()
         d.to_xml(element, "{%s}%s" %(ns_test, "atach"))
         element = element[0]
 
-        self.assertEquals(element.text, d.value.isoformat())
+        self.assertEqual(element.text, d.value.isoformat())
         dt = XMLDate().from_xml(element)
-        self.assertEquals(d.value, dt)
+        self.assertEqual(d.value, dt)
 
     def test_integer(self):
         integer = XMLInteger(12)
         integer.to_xml(element, "{%s}%s" %(ns_test, "atach"))
         element = element[0]
 
-        self.assertEquals(element.text, '12')
+        self.assertEqual(element.text, '12')
         value = XMLInteger().from_xml(element)
-        self.assertEquals(value, integer)
+        self.assertEqual(value, integer)
 
     def test_large_integer(self):
         integer = XMLInteger(128375873458473)
         integer.to_xml(element, "{%s}%s" %(ns_test, "atach"))
         element = element[0]
 
-        self.assertEquals(element.text, '128375873458473')
+        self.assertEqual(element.text, '128375873458473')
         value = XMLInteger().from_xml(element)
-        self.assertEquals(value, integer)
+        self.assertEqual(value, integer)
 
     def test_float(self):
         f = XMLDouble(1.0/3.0)
         f.to_xml(element, "{%s}%s" %(ns_test, "atach"))
         element = element[0]
 
-        self.assertEquals(element.text, repr(f))
+        self.assertEqual(element.text, repr(f))
 
         f2 = XMLDouble().from_xml(element)
-        self.assertEquals(f2, f)
+        self.assertEqual(f2, f)
 
     def test_unicode(self):
-        s = XMLString(u'\x34\x55\x65\x34')
-        self.assertEquals(4, len(s))
+        s = XMLString('\x34\x55\x65\x34')
+        self.assertEqual(4, len(s))
         element = etree.Element('test')
         s.to_xml(element, "{%s}%s" %(ns_test, "atach"))
         element = element[0]
         value = XMLString().from_xml(element)
-        self.assertEquals(value, s)
+        self.assertEqual(value, s)
 
     def test_boolean(self):
         b = etree.Element('test')
         XMLBoolean(True).to_xml(b, "{%s}%s" %(ns_test, "atach"))
         b = b[0]
-        self.assertEquals('true', b.text)
+        self.assertEqual('true', b.text)
 
         b = etree.Element('test')
         XMLBoolean(0).to_xml(b, "{%s}%s" %(ns_test, "atach"))
         b = b[0]
-        self.assertEquals('false', b.text)
+        self.assertEqual('false', b.text)
 
         b = etree.Element('test')
         XMLBoolean(1).to_xml(b, "{%s}%s" %(ns_test, "atach"))
         b = b[0]
-        self.assertEquals('true', b.text)
+        self.assertEqual('true', b.text)
 
         b = XMLBoolean().from_xml(b)
-        self.assertEquals(b, True)
+        self.assertEqual(b, True)
 
         b = etree.Element('test')
         XMLBoolean(False).to_xml(b, "{%s}%s" %(ns_test, "atach"))
         b = b[0]
-        self.assertEquals('false', b.text)
+        self.assertEqual('false', b.text)
 
         b = XMLBoolean().from_xml(b)
-        self.assertEquals(b, False)
+        self.assertEqual(b, False)
 
         b = etree.Element('test')
         b.text = ''
         b = XMLBoolean().from_xml(b)
-        self.assertEquals(b, None)
+        self.assertEqual(b, None)
 
     def test_any(self):
         #test any from_xml, the other way is
         #no type => xml
         inst = XMLAny()
         v = inst.from_xml(element)
-        self.assertEquals(type(v).__name__ , "Element")
+        self.assertEqual(type(v).__name__ , "Element")
 
         #float
         element.set("{%s}type" %xmlnamespace.NS_XSI, "{%s}float" %xmlnamespace.NS_XSD)
         v = inst.from_xml(element)
-        self.assertEquals(v.__class__.__name__, "float")
-        self.assertEquals(v, 10.0)
+        self.assertEqual(v.__class__.__name__, "float")
+        self.assertEqual(v, 10.0)
 
         #string
         element.set("{%s}type" %xmlnamespace.NS_XSI, "{%s}string" %xmlnamespace.NS_XSD)
         v = inst.from_xml(element)
-        self.assertEquals(v.__class__.__name__, "str")
-        self.assertEquals(v, "10.0")
+        self.assertEqual(v.__class__.__name__, "str")
+        self.assertEqual(v, "10.0")