55Cross-compatible functions for Python 2 and 3.
66
77Key items to import for 2/3 compatible code:
8- * iterators: range(), map(), zip(), filter(), reduce()
8+ * iterators: reduce()
99* lists: lrange(), lmap(), lzip(), lfilter()
1010* unicode: u() [no unicode builtin in Python 3]
1111* longs: long (int in Python 3)
@@ -107,19 +107,11 @@ def get_range_parameters(data):
107107 return data .start , data .stop , data .step
108108
109109 # have to explicitly put builtins into the namespace
110- range = range
111- map = map
112- zip = zip
113- filter = filter
114110 intern = sys .intern
115111 reduce = functools .reduce
116112 long = int
117113 unichr = chr
118114
119- # This was introduced in Python 3.3, but we don't support
120- # Python 3.x < 3.5, so checking PY3 is safe.
121- FileNotFoundError = FileNotFoundError
122-
123115 # list-producing versions of the major Python iterating functions
124116 def lrange (* args , ** kwargs ):
125117 return list (range (* args , ** kwargs ))
@@ -148,8 +140,6 @@ def lfilter(*args, **kwargs):
148140 # Python 2
149141 _name_re = re .compile (r"[a-zA-Z_][a-zA-Z0-9_]*$" )
150142
151- FileNotFoundError = IOError
152-
153143 def isidentifier (s , dotted = False ):
154144 return bool (_name_re .match (s ))
155145
@@ -181,11 +171,7 @@ def get_range_parameters(data):
181171 return start , stop , step
182172
183173 # import iterator versions of these functions
184- range = xrange
185174 intern = intern
186- zip = itertools .izip
187- filter = itertools .ifilter
188- map = itertools .imap
189175 reduce = reduce
190176 long = long
191177 unichr = unichr
@@ -217,7 +203,6 @@ def iterkeys(obj, **kw):
217203 def itervalues (obj , ** kw ):
218204 return obj .itervalues (** kw )
219205
220- next = lambda it : it .next ()
221206else :
222207 def iteritems (obj , ** kw ):
223208 return iter (obj .items (** kw ))
@@ -228,8 +213,6 @@ def iterkeys(obj, **kw):
228213 def itervalues (obj , ** kw ):
229214 return iter (obj .values (** kw ))
230215
231- next = next
232-
233216
234217def bind_method (cls , name , func ):
235218 """Bind a method to class, python 2 and python 3 compatible.
@@ -315,9 +298,6 @@ def set_function_name(f, name, cls):
315298 name = name )
316299 f .__module__ = cls .__module__
317300 return f
318-
319- ResourceWarning = ResourceWarning
320-
321301else :
322302 string_types = basestring ,
323303 integer_types = (int , long )
@@ -373,9 +353,6 @@ def set_function_name(f, name, cls):
373353 f .__name__ = name
374354 return f
375355
376- class ResourceWarning (Warning ):
377- pass
378-
379356string_and_binary_types = string_types + (binary_type ,)
380357
381358
0 commit comments