A version that actually works.
This commit is contained in:
		
							
								
								
									
										17
									
								
								testtools/_compat2x.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								testtools/_compat2x.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,17 @@
 | 
			
		||||
# Copyright (c) 2011 testtools developers. See LICENSE for details.
 | 
			
		||||
 | 
			
		||||
"""Compatibility helpers that are valid syntax in Python 2.x.
 | 
			
		||||
 | 
			
		||||
Only add things here if they *only* work in Python 2.x or are Python 2
 | 
			
		||||
alternatives to things that *only* work in Python 3.x.
 | 
			
		||||
"""
 | 
			
		||||
 | 
			
		||||
__all__ = [
 | 
			
		||||
    'reraise',
 | 
			
		||||
    ]
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def reraise(exc_class, exc_obj, exc_tb, _marker=object()):
 | 
			
		||||
    """Re-raise an exception received from sys.exc_info() or similar."""
 | 
			
		||||
    raise exc_class, exc_obj, exc_tb
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										17
									
								
								testtools/_compat3x.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								testtools/_compat3x.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,17 @@
 | 
			
		||||
# Copyright (c) 2011 testtools developers. See LICENSE for details.
 | 
			
		||||
 | 
			
		||||
"""Compatibility helpers that are valid syntax in Python 3.x.
 | 
			
		||||
 | 
			
		||||
Only add things here if they *only* work in Python 3.x or are Python 3
 | 
			
		||||
alternatives to things that *only* work in Python 2.x.
 | 
			
		||||
"""
 | 
			
		||||
 | 
			
		||||
__all__ = [
 | 
			
		||||
    'reraise',
 | 
			
		||||
    ]
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def reraise(exc_class, exc_obj, exc_tb, _marker=object()):
 | 
			
		||||
    """Re-raise an exception received from sys.exc_info() or similar."""
 | 
			
		||||
    raise exc_class(*exc_obj.args).with_traceback(exc_tb)
 | 
			
		||||
 | 
			
		||||
@@ -7,8 +7,14 @@ __all__ = [
 | 
			
		||||
    '_b',
 | 
			
		||||
    '_u',
 | 
			
		||||
    'advance_iterator',
 | 
			
		||||
    'all',
 | 
			
		||||
    'BytesIO',
 | 
			
		||||
    'classtypes',
 | 
			
		||||
    'isbaseexception',
 | 
			
		||||
    'istext',
 | 
			
		||||
    'str_is_unicode',
 | 
			
		||||
    'StringIO',
 | 
			
		||||
    'reraise',
 | 
			
		||||
    'unicode_output_stream',
 | 
			
		||||
    ]
 | 
			
		||||
 | 
			
		||||
@@ -25,6 +31,14 @@ from testtools.helpers import try_imports
 | 
			
		||||
BytesIO = try_imports(['StringIO.StringIO', 'io.BytesIO'])
 | 
			
		||||
StringIO = try_imports(['StringIO.StringIO', 'io.StringIO'])
 | 
			
		||||
 | 
			
		||||
try:
 | 
			
		||||
    from testtools import _compat2x as _compat
 | 
			
		||||
    _compat
 | 
			
		||||
except SyntaxError:
 | 
			
		||||
    from testtools import _compat3x as _compat
 | 
			
		||||
 | 
			
		||||
reraise = _compat.reraise
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
__u_doc = """A function version of the 'u' prefix.
 | 
			
		||||
 | 
			
		||||
@@ -284,10 +298,3 @@ def _format_exc_info(eclass, evalue, tb, limit=None):
 | 
			
		||||
    else:
 | 
			
		||||
        list.append("%s\n" % sclass)
 | 
			
		||||
    return list
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def reraise(exc_class, exc_obj, exc_tb, _marker=object()):
 | 
			
		||||
    """Re-raise an exception received from sys.exc_info() or similar."""
 | 
			
		||||
    if getattr(exc_class, 'with_traceback', _marker) is _marker:
 | 
			
		||||
        raise exc_class(exc_obj).with_traceback(exc_tb)
 | 
			
		||||
    raise exc_class, exc_obj, exc_tb
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user