Commits

Jason Pellerin committed aac2283

Moved etree import to compat module

Comments (0)

Files changed (8)

+try:
+    from xml.etree import cElementTree as etree
+except ImportError:
+    from xml.etree import ElementTree as etree
+
+ElementCls = type(etree.Element('x'))
+
 # TODO
 # - schema types can extend enums. How the heck can that work?
 
+from datetime import date, datetime, time
 from decimal import Decimal
 import itertools
-from xml.etree import ElementTree as etree
+import logging
+from threading import RLock
 from urllib2 import urlopen, Request, HTTPError
-from threading import RLock
-from datetime import date, datetime, time
+
 from dateutil.parser import parse as parse_date
-import logging
 
+from scio._etree import etree, ElementCls
 
 log = logging.getLogger(__name__)
 
         """
         newarg = []
         for a in arg:
-            if isinstance(a, etree._Element):
+            if isinstance(a, ElementCls):
                 val = cls.fromxml(a)
                 if val is not None:
                     newarg.append(val)
         # of scio classes to children via positional args
         if element is not None:
             content = None
-            if isinstance(element, etree._Element):
+            if isinstance(element, ElementCls):
                 attrs = set(attr.name for attr in self._attributes)
                 kids = set(child.name for child in self._children)
                 kids_subs = self._child_substitutions()
             e.attrib[self._type_attr] = self._type_value
         if isinstance(value, basestring):
             e.text = value
-        elif isinstance(value, etree._Element):
+        elif isinstance(value, ElementCls):
             e.append(value)
         for attr in self._attributes:
             at_val = getattr(self, attr.name, None)

tests/test_anytype.py

 import scio
+from scio._etree import etree
 import helpers
-from xml.etree import ElementTree as etree
+
 
 def test_deserialize_boyzoid_response():
     client = scio.Client(helpers.support('boyzoid.wsdl', 'r'))

tests/test_ebay.py

 import time
 
 def test_parse_shoppingservice():
-    client = scio.Client(helpers.support('shoppingservice.wsdl', 'r'))
+    scio.Client(helpers.support('shoppingservice.wsdl', 'r'))
 
 def test_parse_ebaysvc():
     st = time.time()
-    client = scio.Client(helpers.support('eBaySvc.wsdl', 'r'))
+    scio.Client(helpers.support('eBaySvc.wsdl', 'r'))
     taken = time.time() - st
     print "parsed 4.2mb wsdl in", taken
 test_parse_ebaysvc.slow = True

tests/test_internals.py

 import pickle
 from urllib2 import HTTPError
 
-from xml.etree import ElementTree as etree
 from nose.tools import raises, eq_
 
 import scio
+from scio._etree import etree
 import scio.client
 import helpers
 

tests/test_pickling.py

-from xml.etree import ElementTree as etree
 from cPickle import dumps, loads
 from nose.tools import eq_
 
 import scio
+from scio._etree import etree
 import helpers
 
 

tests/test_styles.py

+from nose.tools import eq_
+
 import scio
 import helpers
-from xml.etree import ElementTree as etree
-from nose.tools import eq_
+from scio._etree import etree
 
 
 def test_zfapi_is_document_literal_wrapper():

tests/test_types.py

+from nose.tools import assert_almost_equal
+
 import scio.client as sc
-from xml.etree import ElementTree as etree
-from nose.tools import assert_almost_equal
+from scio._etree import etree
 
 
 def test_datetime_from_string():