MCPcopy Create free account
hub / github.com/kurtmckee/feedparser / _BaseHTMLProcessor

Class _BaseHTMLProcessor

feedparser/html.py:64–355  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

62
63
64class _BaseHTMLProcessor(sgmllib.SGMLParser, object):
65 special = re.compile("""[<>'"]""")
66 bare_ampersand = re.compile(r"&(?!#\d+;|#x[0-9a-fA-F]+;|\w+;)")
67 elements_no_end_tag = {
68 'area',
69 'base',
70 'basefont',
71 'br',
72 'col',
73 'command',
74 'embed',
75 'frame',
76 'hr',
77 'img',
78 'input',
79 'isindex',
80 'keygen',
81 'link',
82 'meta',
83 'param',
84 'source',
85 'track',
86 'wbr',
87 }
88
89 def __init__(self, encoding=None, _type='application/xhtml+xml'):
90 if encoding:
91 self.encoding = encoding
92 self._type = _type
93 self.pieces = []
94 super(_BaseHTMLProcessor, self).__init__()
95
96 def reset(self):
97 self.pieces = []
98 super(_BaseHTMLProcessor, self).reset()
99
100 def _shorttag_replace(self, match):
101 """
102 :type match: Match[str]
103 :rtype: str
104 """
105
106 tag = match.group(1)
107 if tag in self.elements_no_end_tag:
108 return '<' + tag + ' />'
109 else:
110 return '<' + tag + '></' + tag + '>'
111
112 # By declaring these methods and overriding their compiled code
113 # with the code from sgmllib, the original code will execute in
114 # feedparser's scope instead of sgmllib's. This means that the
115 # `tagfind` and `charref` regular expressions will be found as
116 # they're declared above, not as they're declared in sgmllib.
117 def goahead(self, i):
118 raise NotImplementedError
119
120 # Replace goahead with SGMLParser's goahead() code object.
121 try:

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…