MCPcopy Index your code
hub / github.com/python/cpython / TextRepr

Class TextRepr

Lib/pydoc.py:1193–1223  ·  view source on GitHub ↗

Class for safely making a text representation of a Python object.

Source from the content-addressed store, hash-verified

1191# -------------------------------------------- text documentation generator
1192
1193class 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
1225class TextDoc(Doc):
1226 """Formatter class for text documentation."""

Callers 1

TextDocClass · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…