MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / feed

Method feed

tools/python-3.11.9-amd64/Lib/email/header.py:438–473  ·  view source on GitHub ↗
(self, fws, string, charset)

Source from the content-addressed store, hash-verified

436 self._current_line.push(' ', '')
437
438 def feed(self, fws, string, charset):
439 # If the charset has no header encoding (i.e. it is an ASCII encoding)
440 # then we must split the header at the "highest level syntactic break"
441 # possible. Note that we don't have a lot of smarts about field
442 # syntax; we just try to break on semi-colons, then commas, then
443 # whitespace. Eventually, this should be pluggable.
444 if charset.header_encoding is None:
445 self._ascii_split(fws, string, self._splitchars)
446 return
447 # Otherwise, we're doing either a Base64 or a quoted-printable
448 # encoding which means we don't need to split the line on syntactic
449 # breaks. We can basically just find enough characters to fit on the
450 # current line, minus the RFC 2047 chrome. What makes this trickier
451 # though is that we have to split at octet boundaries, not character
452 # boundaries but it's only safe to split at character boundaries so at
453 # best we can only get close.
454 encoded_lines = charset.header_encode_lines(string, self._maxlengths())
455 # The first element extends the current line, but if it's None then
456 # nothing more fit on the current line so start a new line.
457 try:
458 first_line = encoded_lines.pop(0)
459 except IndexError:
460 # There are no encoded lines, so we're done.
461 return
462 if first_line is not None:
463 self._append_chunk(fws, first_line)
464 try:
465 last_line = encoded_lines.pop()
466 except IndexError:
467 # There was only one line.
468 return
469 self.newline()
470 self._current_line.push(self._continuation_ws, last_line)
471 # Everything else are full lines in themselves.
472 for line in encoded_lines:
473 self._lines.append(self._continuation_ws + line)
474
475 def _maxlengths(self):
476 # The first line's length.

Callers 1

encodeMethod · 0.45

Calls 8

_ascii_splitMethod · 0.95
_maxlengthsMethod · 0.95
_append_chunkMethod · 0.95
newlineMethod · 0.95
header_encode_linesMethod · 0.80
popMethod · 0.45
pushMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected