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

Method __init__

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

Create a MIME-compliant header that can contain many character sets. Optional s is the initial header value. If None, the initial header value is not set. You can later append to the header with .append() method calls. s may be a byte string or a Unicode string, but s

(self, s=None, charset=None,
                 maxlinelen=None, header_name=None,
                 continuation_ws=' ', errors='strict')

Source from the content-addressed store, hash-verified

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."""

Callers 1

__init__Method · 0.45

Calls 2

appendMethod · 0.95
CharsetClass · 0.85

Tested by

no test coverage detected