MCPcopy Index your code
hub / github.com/RustPython/RustPython / TextRepr

Class TextRepr

Lib/pydoc.py:1238–1268  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

1236# -------------------------------------------- text documentation generator
1237
1238class TextRepr(Repr):
1239 """Class for safely making a text representation of a Python object."""
1240 def __init__(self):
1241 Repr.__init__(self)
1242 self.maxlist = self.maxtuple = 20
1243 self.maxdict = 10
1244 self.maxstring = self.maxother = 100
1245
1246 def repr1(self, x, level):
1247 if hasattr(type(x), '__name__'):
1248 methodname = 'repr_' + '_'.join(type(x).__name__.split())
1249 if hasattr(self, methodname):
1250 return getattr(self, methodname)(x, level)
1251 return cram(stripid(repr(x)), self.maxother)
1252
1253 def repr_string(self, x, level):
1254 test = cram(x, self.maxstring)
1255 testrepr = repr(test)
1256 if '\\' in test and '\\' not in replace(testrepr, r'\\', ''):
1257 # Backslashes are only literal in the string and are never
1258 # needed to make any special characters, so show a raw string.
1259 return 'r' + testrepr[0] + test + testrepr[0]
1260 return testrepr
1261
1262 repr_str = repr_string
1263
1264 def repr_instance(self, x, level):
1265 try:
1266 return cram(stripid(repr(x)), self.maxstring)
1267 except:
1268 return '<%s instance>' % x.__class__.__name__
1269
1270class TextDoc(Doc):
1271 """Formatter class for text documentation."""

Callers 1

TextDocClass · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected