aboutsummaryrefslogtreecommitdiffstats
path: root/setuptools/tests/py26compat.py
blob: 24e6dbe293f1d981ef99bf11c7d27622925a663a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import sys
import unittest
import tarfile

try:
	# provide skipIf for Python 2.4-2.6
	skipIf = unittest.skipIf
except AttributeError:
	def skipIf(condition, reason):
		def skipper(func):
			def skip(*args, **kwargs):
				return
			if condition:
				return skip
			return func
		return skipper

def _tarfile_open_ex(*args, **kwargs):
	"""
	Extend result with an __exit__ to close the file.
	"""
	res = tarfile.open(*args, **kwargs)
	res.__exit__ = lambda self: self.close()
	return res

tarfile_open = _tarfile_open_ex if sys.version_info < (2,7) else  tarfile.open