(HTML|Text)Repr.repr1: Guard against objects whos types have no __name__

attribute. Patch and bug report from Geoff Talvola. Closes patch #672855.
This commit is contained in:
Skip Montanaro 2003-06-27 15:45:41 +00:00
parent 896e5164bb
commit 0fe8fce7e3
1 changed files with 10 additions and 10 deletions

View File

@ -312,11 +312,11 @@ class HTMLRepr(Repr):
return Repr.repr(self, object) return Repr.repr(self, object)
def repr1(self, x, level): def repr1(self, x, level):
methodname = 'repr_' + join(split(type(x).__name__), '_') if hasattr(type(x), '__name__'):
if hasattr(self, methodname): methodname = 'repr_' + join(split(type(x).__name__), '_')
return getattr(self, methodname)(x, level) if hasattr(self, methodname):
else: return getattr(self, methodname)(x, level)
return self.escape(cram(stripid(repr(x)), self.maxother)) return self.escape(cram(stripid(repr(x)), self.maxother))
def repr_string(self, x, level): def repr_string(self, x, level):
test = cram(x, self.maxstring) test = cram(x, self.maxstring)
@ -874,11 +874,11 @@ class TextRepr(Repr):
self.maxstring = self.maxother = 100 self.maxstring = self.maxother = 100
def repr1(self, x, level): def repr1(self, x, level):
methodname = 'repr_' + join(split(type(x).__name__), '_') if hasattr(type(x), '__name__'):
if hasattr(self, methodname): methodname = 'repr_' + join(split(type(x).__name__), '_')
return getattr(self, methodname)(x, level) if hasattr(self, methodname):
else: return getattr(self, methodname)(x, level)
return cram(stripid(repr(x)), self.maxother) return cram(stripid(repr(x)), self.maxother)
def repr_string(self, x, level): def repr_string(self, x, level):
test = cram(x, self.maxstring) test = cram(x, self.maxstring)