diff 2.00/compat.py @ 31:fe1463e7e24d

Clean up try-except clauses More try-except-else goodness (with the stress on else). Bug fix: compat.py now creates zip_longest in Python 2.5 instead of raising an exception.
author Oleg Oshmyan <chortos@inbox.lv>
date Thu, 25 Nov 2010 00:03:29 +0000
parents dc4be35d17e0
children 8fec38b0dd6e
line wrap: on
line diff
--- a/2.00/compat.py	Wed Nov 24 23:42:06 2010 +0000
+++ b/2.00/compat.py	Thu Nov 25 00:03:29 2010 +0000
@@ -121,23 +121,24 @@
 	# Python 3
 	from itertools import zip_longest
 except ImportError:
-	# Python 2.6/2.7
-	from itertools import izip_longest as zip_longest
-except ImportError:
-	# Python 2.5
-	from itertools import chain, repeat
-	# Adapted from the documentation of itertools.izip_longest
-	def zip_longest(*args, **kwargs):
-		fillvalue = kwargs.get('fillvalue')
-		def sentinel(counter=([fillvalue]*(len(args)-1)).pop):
-			yield counter()
-		fillers = repeat(fillvalue)
-		iters = [chain(it, sentinel(), fillers) for it in args]
-		try:
-			for tup in zip(*iters):
-				yield tup
-		except IndexError:
-			pass
+	try:
+		# Python 2.6/2.7
+		from itertools import izip_longest as zip_longest
+	except ImportError:
+		# Python 2.5
+		from itertools import chain, repeat
+		# Adapted from the documentation of itertools.izip_longest
+		def zip_longest(*args, **kwargs):
+			fillvalue = kwargs.get('fillvalue')
+			def sentinel(counter=([fillvalue]*(len(args)-1)).pop):
+				yield counter()
+			fillers = repeat(fillvalue)
+			iters = [chain(it, sentinel(), fillers) for it in args]
+			try:
+				for tup in zip(*iters):
+					yield tup
+			except IndexError:
+				pass
 
 # Automatically import * from this module into testconf.py's
 class CompatBuiltins(object):