Class for safely making a text representation of a Python object.
| 1191 | # -------------------------------------------- text documentation generator |
| 1192 | |
| 1193 | class TextRepr(Repr): |
| 1194 | """Class for safely making a text representation of a Python object.""" |
| 1195 | def __init__(self): |
| 1196 | Repr.__init__(self) |
| 1197 | self.maxlist = self.maxtuple = 20 |
| 1198 | self.maxdict = 10 |
| 1199 | self.maxstring = self.maxother = 100 |
| 1200 | |
| 1201 | def repr1(self, x, level): |
| 1202 | if hasattr(type(x), '__name__'): |
| 1203 | methodname = 'repr_' + '_'.join(type(x).__name__.split()) |
| 1204 | if hasattr(self, methodname): |
| 1205 | return getattr(self, methodname)(x, level) |
| 1206 | return cram(stripid(repr(x)), self.maxother) |
| 1207 | |
| 1208 | def repr_string(self, x, level): |
| 1209 | test = cram(x, self.maxstring) |
| 1210 | testrepr = repr(test) |
| 1211 | if '\\' in test and '\\' not in replace(testrepr, r'\\', ''): |
| 1212 | # Backslashes are only literal in the string and are never |
| 1213 | # needed to make any special characters, so show a raw string. |
| 1214 | return 'r' + testrepr[0] + test + testrepr[0] |
| 1215 | return testrepr |
| 1216 | |
| 1217 | repr_str = repr_string |
| 1218 | |
| 1219 | def repr_instance(self, x, level): |
| 1220 | try: |
| 1221 | return cram(stripid(repr(x)), self.maxstring) |
| 1222 | except: |
| 1223 | return '<%s instance>' % x.__class__.__name__ |
| 1224 | |
| 1225 | class TextDoc(Doc): |
| 1226 | """Formatter class for text documentation.""" |
no outgoing calls
no test coverage detected
searching dependent graphs…