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

Class HTMLRepr

Lib/pydoc.py:557–597  ·  view source on GitHub ↗

Class for safely making an HTML representation of a Python object.

Source from the content-addressed store, hash-verified

555# -------------------------------------------- HTML documentation generator
556
557class HTMLRepr(Repr):
558 """Class for safely making an HTML representation of a Python object."""
559 def __init__(self):
560 Repr.__init__(self)
561 self.maxlist = self.maxtuple = 20
562 self.maxdict = 10
563 self.maxstring = self.maxother = 100
564
565 def escape(self, text):
566 return replace(text, '&', '&amp;', '<', '&lt;', '>', '&gt;')
567
568 def repr(self, object):
569 return Repr.repr(self, object)
570
571 def repr1(self, x, level):
572 if hasattr(type(x), '__name__'):
573 methodname = 'repr_' + '_'.join(type(x).__name__.split())
574 if hasattr(self, methodname):
575 return getattr(self, methodname)(x, level)
576 return self.escape(cram(stripid(repr(x)), self.maxother))
577
578 def repr_string(self, x, level):
579 test = cram(x, self.maxstring)
580 testrepr = repr(test)
581 if '\\' in test and '\\' not in replace(testrepr, r'\\', ''):
582 # Backslashes are only literal in the string and are never
583 # needed to make any special characters, so show a raw string.
584 return 'r' + testrepr[0] + self.escape(test) + testrepr[0]
585 return re.sub(r'((\\[\\abfnrtv\'"]|\\[0-9]..|\\x..|\\u....)+)&#x27;,
586 r'<span class="repr">\1</span>',
587 self.escape(testrepr))
588
589 repr_str = repr_string
590
591 def repr_instance(self, x, level):
592 try:
593 return self.escape(cram(stripid(repr(x)), self.maxstring))
594 except:
595 return self.escape('<%s instance>' % x.__class__.__name__)
596
597 repr_unicode = repr_string
598
599class HTMLDoc(Doc):
600 """Formatter class for HTML documentation."""

Callers 1

HTMLDocClass · 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…