def canonicalize_stderr(stderr):
 stderr = stderr.strip().split('\n')[(-1)]
 substitutions = [("NameError: global name '", "NameError: name '"), ("AttributeError: '(\\w+)' object attribute '(\\w+)' is read-only", 'AttributeError: \\2'), ('TypeError: object.__new__\\(\\) takes no parameters', 'TypeError: object() takes no parameters'), ('IndexError: list assignment index out of range', 'IndexError: list index out of range'), ("unqualified exec is not allowed in function '(\\w+)' it (.*)", "unqualified exec is not allowed in function '\\1' because it \\2")]
 for (pattern, subst_with) in substitutions:
  stderr = re.sub(pattern, subst_with, stderr)
 return stderr

def canonicalize_stderr ( stderr ) : stderr = stderr . strip ( ) . split ( '\n' ) [ ( - 1 ) ] substitutions = [ ( "NameError: global name '" , "NameError: name '" ) , ( "AttributeError: '(\\w+)' object attribute '(\\w+)' is read-only" , 'AttributeError: \\2' ) , ( 'TypeError: object.__new__\\(\\) takes no parameters' , 'TypeError: object() takes no parameters' ) , ( 'IndexError: list assignment index out of range' , 'IndexError: list index out of range' ) , ( "unqualified exec is not allowed in function '(\\w+)' it (.*)" , "unqualified exec is not allowed in function '\\1' because it \\2" ) ] for ( pattern , subst_with ) in substitutions : stderr = re . sub ( pattern , subst_with , stderr ) return stderr
for a while we were trying to maintain *exact* stderr compatibility with cpython .