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

Class Header

tools/python-3.11.9-amd64/Lib/email/header.py:175–405  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

173
174
175class Header:
176 def __init__(self, s=None, charset=None,
177 maxlinelen=None, header_name=None,
178 continuation_ws=' ', errors='strict'):
179 """Create a MIME-compliant header that can contain many character sets.
180
181 Optional s is the initial header value. If None, the initial header
182 value is not set. You can later append to the header with .append()
183 method calls. s may be a byte string or a Unicode string, but see the
184 .append() documentation for semantics.
185
186 Optional charset serves two purposes: it has the same meaning as the
187 charset argument to the .append() method. It also sets the default
188 character set for all subsequent .append() calls that omit the charset
189 argument. If charset is not provided in the constructor, the us-ascii
190 charset is used both as s's initial charset and as the default for
191 subsequent .append() calls.
192
193 The maximum line length can be specified explicitly via maxlinelen. For
194 splitting the first line to a shorter value (to account for the field
195 header which isn't included in s, e.g. `Subject') pass in the name of
196 the field in header_name. The default maxlinelen is 78 as recommended
197 by RFC 2822.
198
199 continuation_ws must be RFC 2822 compliant folding whitespace (usually
200 either a space or a hard tab) which will be prepended to continuation
201 lines.
202
203 errors is passed through to the .append() call.
204 """
205 if charset is None:
206 charset = USASCII
207 elif not isinstance(charset, Charset):
208 charset = Charset(charset)
209 self._charset = charset
210 self._continuation_ws = continuation_ws
211 self._chunks = []
212 if s is not None:
213 self.append(s, charset, errors)
214 if maxlinelen is None:
215 maxlinelen = MAXLINELEN
216 self._maxlinelen = maxlinelen
217 if header_name is None:
218 self._headerlen = 0
219 else:
220 # Take the separating colon and space into account.
221 self._headerlen = len(header_name) + 2
222
223 def __str__(self):
224 """Return the string value of the header."""
225 self._normalize()
226 uchunks = []
227 lastcs = None
228 lastspace = None
229 for string, charset in self._chunks:
230 # We must preserve spaces between encoded and non-encoded word
231 # boundaries, which means for us we need to add a space when we go
232 # from a charset to None/us-ascii, or from None/us-ascii to a

Callers 1

make_headerFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected