MCPcopy
hub / github.com/django/django / TruncateCharsHTMLParser

Class TruncateCharsHTMLParser

django/utils/text.py:157–175  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

155
156
157class TruncateCharsHTMLParser(TruncateHTMLParser):
158 def __init__(self, *, length, replacement, convert_charrefs=True):
159 self.length = length
160 self.processed_chars = 0
161 super().__init__(
162 length=calculate_truncate_chars_length(length, replacement),
163 replacement=replacement,
164 convert_charrefs=convert_charrefs,
165 )
166
167 def process(self, data):
168 self.processed_chars += len(data)
169 if (self.processed_chars == self.length) and (
170 sum(len(p) for p in self.output) + len(data) == len(self.rawdata)
171 ):
172 self.output.append(data)
173 raise self.TruncationCompleted
174 output = escape("".join(data[: self.remaining]))
175 return data, output
176
177
178class TruncateWordsHTMLParser(TruncateHTMLParser):

Callers 1

charsMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected