From 8d2080d043629702a5a79b968e778bcf991dfd73 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Thu, 12 Jan 1995 12:29:17 +0000 Subject: [PATCH] use getattr() instead of eval(), fix string representations --- Lib/repr.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Lib/repr.py b/Lib/repr.py index 2f4a0bfeb31..f8ef71d6813 100644 --- a/Lib/repr.py +++ b/Lib/repr.py @@ -18,16 +18,15 @@ def repr1(self, x, level): if ' ' in typename: parts = string.split(typename) typename = string.joinfields(parts, '_') - try: - f = eval('self.repr_' + typename) - except AttributeError: + if hasattr(self, 'repr_' + typename): + return getattr(self, 'repr_' + typename)(x, level) + else: s = `x` if len(s) > self.maxother: i = max(0, (self.maxother-3)/2) j = max(0, self.maxother-3-i) s = s[:i] + '...' + s[len(s)-j:] return s - return f(x, level) def repr_tuple(self, x, level): n = len(x) if n == 0: return '()' @@ -68,6 +67,7 @@ def repr_string(self, x, level): if len(s) > self.maxstring: i = max(0, (self.maxstring-3)/2) j = max(0, self.maxstring-3-i) + s = `x[:i] + x[len(x)-j:]` s = s[:i] + '...' + s[len(s)-j:] return s def repr_long_int(self, x, level):