1616
1717from __future__ import unicode_literals
1818import logging
19- import os
20- import warnings
21- import urllib
22- import time
19+ import io
2320from lxml import etree
2421from lxml .builder import ElementMaker
25- import six
26- from six .moves .urllib .request import urlopen
2722
28- from neuxml .utils .compat import u
2923from neuxml .xmlmap .fields import Field
3024
3125
@@ -193,7 +187,7 @@ def __new__(cls, name, bases, defined_attrs):
193187 # collect self-referential NodeFields so that we can resolve
194188 # them once we've created the new class
195189 node_class = getattr (field , 'node_class' , None )
196- if isinstance (node_class , six . string_types ):
190+ if isinstance (node_class , str ):
197191 if node_class in ('self' , name ):
198192 recursive_fields .append (field )
199193 else :
@@ -235,8 +229,7 @@ def create_field(xmlobject):
235229 return create_field
236230
237231
238- @six .python_2_unicode_compatible
239- class XmlObject (six .with_metaclass (XmlObjectType , object )):
232+ class XmlObject (object , metaclass = XmlObjectType ):
240233
241234 """
242235 A Python object wrapped around an XML node.
@@ -324,15 +317,15 @@ def __init__(self, node=None, context=None, **kwargs):
324317
325318 # xpath has no notion of a default namespace - omit any namespace with no prefix
326319 self .context = {'namespaces' : dict ([(prefix , ns ) for prefix , ns
327- in six . iteritems ( nsmap ) if prefix ])}
320+ in nsmap . items ( ) if prefix ])}
328321
329322 if context is not None :
330323 self .context .update (context )
331324 if hasattr (self , 'ROOT_NAMESPACES' ):
332325 # also include any root namespaces to guarantee that expected prefixes are available
333326 self .context ['namespaces' ].update (self .ROOT_NAMESPACES )
334327
335- for field , value in six . iteritems ( kwargs ):
328+ for field , value in kwargs . items ( ):
336329 # TODO (maybe): handle setting/creating list fields
337330 setattr (self , field , value )
338331
@@ -373,8 +366,8 @@ def xsl_transform(self, filename=None, xsl=None, return_type=None, **params):
373366 return_type = XmlObject
374367
375368 # automatically encode any string params as XSLT string parameters
376- for key , val in six . iteritems ( params ):
377- if isinstance (val , six . string_types ):
369+ for key , val in params . items ( ):
370+ if isinstance (val , str ):
378371 params [key ] = etree .XSLT .strparam (val )
379372
380373 parser = _get_xmlparser ()
@@ -407,7 +400,7 @@ def xsl_transform(self, filename=None, xsl=None, return_type=None, **params):
407400 # empty xmlobject which will behave unexpectedly.
408401
409402 # text output does not include a root node, so check separately
410- if issubclass (return_type , six . string_types ):
403+ if issubclass (return_type , str ):
411404 if result is None :
412405 logger .warning ("XSL transform generated an empty result" )
413406 return
@@ -421,14 +414,14 @@ def xsl_transform(self, filename=None, xsl=None, return_type=None, **params):
421414 return return_type (result .getroot ())
422415
423416 def __str__ (self ):
424- if isinstance (self .node , six . string_types ):
417+ if isinstance (self .node , str ):
425418 return self .node
426419 return self .node .xpath ("normalize-space(.)" )
427420
428421 def __string__ (self ):
429- if isinstance (self .node , six . string_types ):
422+ if isinstance (self .node , str ):
430423 return self .node
431- return u (self ).encode ('ascii' , 'xmlcharrefreplace' )
424+ return str (self ).encode ('ascii' , 'xmlcharrefreplace' )
432425
433426 def __eq__ (self , other ):
434427 # consider two xmlobjects equal if they are pointing to the same xml node
@@ -471,7 +464,7 @@ def _serialize(self, node, stream=None, pretty=False, xml_declaration=False):
471464 # actual logic of xml serialization
472465 if stream is None :
473466 string_mode = True
474- stream = six .BytesIO ()
467+ stream = io .BytesIO ()
475468 else :
476469 string_mode = False
477470
0 commit comments