-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathemail.util.html
More file actions
403 lines (365 loc) · 33.4 KB
/
email.util.html
File metadata and controls
403 lines (365 loc) · 33.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="zh_TW">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>20.1.14. email.utils: Miscellaneous utilities — Python 3.7.0 說明文件</title>
<link rel="stylesheet" href="../_static/pydoctheme.css" type="text/css" />
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
<script type="text/javascript" src="../_static/jquery.js"></script>
<script type="text/javascript" src="../_static/underscore.js"></script>
<script type="text/javascript" src="../_static/doctools.js"></script>
<script type="text/javascript" src="../_static/translations.js"></script>
<script type="text/javascript" src="../_static/sidebar.js"></script>
<link rel="search" type="application/opensearchdescription+xml"
title="在 Python 3.7.0 說明文件 中搜尋"
href="../_static/opensearch.xml"/>
<link rel="author" title="關於這些文件" href="../about.html" />
<link rel="index" title="索引" href="../genindex.html" />
<link rel="search" title="搜尋" href="../search.html" />
<link rel="copyright" title="Copyright" href="../copyright.html" />
<link rel="next" title="20.1.15. email.iterators: Iterators" href="email.iterators.html" />
<link rel="prev" title="20.1.13. email.encoders: Encoders" href="email.encoders.html" />
<link rel="shortcut icon" type="image/png" href="../_static/py.png" />
<link rel="canonical" href="https://docs.python.org/3/library/email.util.html" />
<script type="text/javascript" src="../_static/copybutton.js"></script>
<script type="text/javascript" src="../_static/switchers.js"></script>
</head><body>
<div class="related" role="navigation" aria-label="related navigation">
<h3>瀏覽</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
accesskey="I">索引</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python 模組索引"
>模組</a> |</li>
<li class="right" >
<a href="email.iterators.html" title="20.1.15. email.iterators: Iterators"
accesskey="N">下一頁</a> |</li>
<li class="right" >
<a href="email.encoders.html" title="20.1.13. email.encoders: Encoders"
accesskey="P">上一頁</a> |</li>
<li><img src="../_static/py.png" alt=""
style="vertical-align: middle; margin-top: -1px"/></li>
<li><a href="https://www.python.org/">Python</a> »</li>
<li>
<span class="language_switcher_placeholder">zh_TW</span>
<span class="version_switcher_placeholder">3.7.0</span>
<a href="../index.html">Documentation </a> »
</li>
<li class="nav-item nav-item-1"><a href="index.html" >Python 標準函式庫 (Standard Library)</a> »</li>
<li class="nav-item nav-item-2"><a href="netdata.html" >20. Internet Data Handling</a> »</li>
<li class="nav-item nav-item-3"><a href="email.html" accesskey="U">20.1. <code class="docutils literal notranslate"><span class="pre">email</span></code> — An email and MIME handling package</a> »</li>
<li class="right">
<div class="inline-search" style="display: none" role="search">
<form class="inline-search" action="../search.html" method="get">
<input placeholder="Quick search" type="text" name="q" />
<input type="submit" value="Go" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
<script type="text/javascript">$('.inline-search').show(0);</script>
|
</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<div class="section" id="module-email.utils">
<span id="email-utils-miscellaneous-utilities"></span><h1>20.1.14. <a class="reference internal" href="#module-email.utils" title="email.utils: Miscellaneous email package utilities."><code class="xref py py-mod docutils literal notranslate"><span class="pre">email.utils</span></code></a>: Miscellaneous utilities<a class="headerlink" href="#module-email.utils" title="本標題的永久連結">¶</a></h1>
<p><strong>Source code:</strong> <a class="reference external" href="https://github.com/python/cpython/tree/3.7/Lib/email/utils.py">Lib/email/utils.py</a></p>
<hr class="docutils" />
<p>There are a couple of useful utilities provided in the <a class="reference internal" href="#module-email.utils" title="email.utils: Miscellaneous email package utilities."><code class="xref py py-mod docutils literal notranslate"><span class="pre">email.utils</span></code></a>
module:</p>
<dl class="function">
<dt id="email.utils.localtime">
<code class="descclassname">email.utils.</code><code class="descname">localtime</code><span class="sig-paren">(</span><em>dt=None</em><span class="sig-paren">)</span><a class="headerlink" href="#email.utils.localtime" title="本定義的永久連結">¶</a></dt>
<dd><p>Return local time as an aware datetime object. If called without
arguments, return current time. Otherwise <em>dt</em> argument should be a
<a class="reference internal" href="datetime.html#datetime.datetime" title="datetime.datetime"><code class="xref py py-class docutils literal notranslate"><span class="pre">datetime</span></code></a> instance, and it is converted to the local time
zone according to the system time zone database. If <em>dt</em> is naive (that
is, <code class="docutils literal notranslate"><span class="pre">dt.tzinfo</span></code> is <code class="docutils literal notranslate"><span class="pre">None</span></code>), it is assumed to be in local time. In this
case, a positive or zero value for <em>isdst</em> causes <code class="docutils literal notranslate"><span class="pre">localtime</span></code> to presume
initially that summer time (for example, Daylight Saving Time) is or is not
(respectively) in effect for the specified time. A negative value for
<em>isdst</em> causes the <code class="docutils literal notranslate"><span class="pre">localtime</span></code> to attempt to divine whether summer time
is in effect for the specified time.</p>
<div class="versionadded">
<p><span class="versionmodified">3.3 版新加入.</span></p>
</div>
</dd></dl>
<dl class="function">
<dt id="email.utils.make_msgid">
<code class="descclassname">email.utils.</code><code class="descname">make_msgid</code><span class="sig-paren">(</span><em>idstring=None</em>, <em>domain=None</em><span class="sig-paren">)</span><a class="headerlink" href="#email.utils.make_msgid" title="本定義的永久連結">¶</a></dt>
<dd><p>Returns a string suitable for an <span class="target" id="index-0"></span><a class="rfc reference external" href="https://tools.ietf.org/html/rfc2822.html"><strong>RFC 2822</strong></a>-compliant
<em class="mailheader">Message-ID</em> header. Optional <em>idstring</em> if given, is a string
used to strengthen the uniqueness of the message id. Optional <em>domain</em> if
given provides the portion of the msgid after the 『@』. The default is the
local hostname. It is not normally necessary to override this default, but
may be useful certain cases, such as a constructing distributed system that
uses a consistent domain name across multiple hosts.</p>
<div class="versionchanged">
<p><span class="versionmodified">3.2 版更變: </span>Added the <em>domain</em> keyword.</p>
</div>
</dd></dl>
<p>The remaining functions are part of the legacy (<code class="docutils literal notranslate"><span class="pre">Compat32</span></code>) email API. There
is no need to directly use these with the new API, since the parsing and
formatting they provide is done automatically by the header parsing machinery
of the new API.</p>
<dl class="function">
<dt id="email.utils.quote">
<code class="descclassname">email.utils.</code><code class="descname">quote</code><span class="sig-paren">(</span><em>str</em><span class="sig-paren">)</span><a class="headerlink" href="#email.utils.quote" title="本定義的永久連結">¶</a></dt>
<dd><p>Return a new string with backslashes in <em>str</em> replaced by two backslashes, and
double quotes replaced by backslash-double quote.</p>
</dd></dl>
<dl class="function">
<dt id="email.utils.unquote">
<code class="descclassname">email.utils.</code><code class="descname">unquote</code><span class="sig-paren">(</span><em>str</em><span class="sig-paren">)</span><a class="headerlink" href="#email.utils.unquote" title="本定義的永久連結">¶</a></dt>
<dd><p>Return a new string which is an <em>unquoted</em> version of <em>str</em>. If <em>str</em> ends and
begins with double quotes, they are stripped off. Likewise if <em>str</em> ends and
begins with angle brackets, they are stripped off.</p>
</dd></dl>
<dl class="function">
<dt id="email.utils.parseaddr">
<code class="descclassname">email.utils.</code><code class="descname">parseaddr</code><span class="sig-paren">(</span><em>address</em><span class="sig-paren">)</span><a class="headerlink" href="#email.utils.parseaddr" title="本定義的永久連結">¶</a></dt>
<dd><p>Parse address – which should be the value of some address-containing field such
as <em class="mailheader">To</em> or <em class="mailheader">Cc</em> – into its constituent <em>realname</em> and
<em>email address</em> parts. Returns a tuple of that information, unless the parse
fails, in which case a 2-tuple of <code class="docutils literal notranslate"><span class="pre">('',</span> <span class="pre">'')</span></code> is returned.</p>
</dd></dl>
<dl class="function">
<dt id="email.utils.formataddr">
<code class="descclassname">email.utils.</code><code class="descname">formataddr</code><span class="sig-paren">(</span><em>pair</em>, <em>charset='utf-8'</em><span class="sig-paren">)</span><a class="headerlink" href="#email.utils.formataddr" title="本定義的永久連結">¶</a></dt>
<dd><p>The inverse of <a class="reference internal" href="#email.utils.parseaddr" title="email.utils.parseaddr"><code class="xref py py-meth docutils literal notranslate"><span class="pre">parseaddr()</span></code></a>, this takes a 2-tuple of the form <code class="docutils literal notranslate"><span class="pre">(realname,</span>
<span class="pre">email_address)</span></code> and returns the string value suitable for a <em class="mailheader">To</em> or
<em class="mailheader">Cc</em> header. If the first element of <em>pair</em> is false, then the
second element is returned unmodified.</p>
<p>Optional <em>charset</em> is the character set that will be used in the <span class="target" id="index-1"></span><a class="rfc reference external" href="https://tools.ietf.org/html/rfc2047.html"><strong>RFC 2047</strong></a>
encoding of the <code class="docutils literal notranslate"><span class="pre">realname</span></code> if the <code class="docutils literal notranslate"><span class="pre">realname</span></code> contains non-ASCII
characters. Can be an instance of <a class="reference internal" href="stdtypes.html#str" title="str"><code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code></a> or a
<a class="reference internal" href="email.charset.html#email.charset.Charset" title="email.charset.Charset"><code class="xref py py-class docutils literal notranslate"><span class="pre">Charset</span></code></a>. Defaults to <code class="docutils literal notranslate"><span class="pre">utf-8</span></code>.</p>
<div class="versionchanged">
<p><span class="versionmodified">3.3 版更變: </span>Added the <em>charset</em> option.</p>
</div>
</dd></dl>
<dl class="function">
<dt id="email.utils.getaddresses">
<code class="descclassname">email.utils.</code><code class="descname">getaddresses</code><span class="sig-paren">(</span><em>fieldvalues</em><span class="sig-paren">)</span><a class="headerlink" href="#email.utils.getaddresses" title="本定義的永久連結">¶</a></dt>
<dd><p>This method returns a list of 2-tuples of the form returned by <code class="docutils literal notranslate"><span class="pre">parseaddr()</span></code>.
<em>fieldvalues</em> is a sequence of header field values as might be returned by
<a class="reference internal" href="email.compat32-message.html#email.message.Message.get_all" title="email.message.Message.get_all"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Message.get_all</span></code></a>. Here’s a simple
example that gets all the recipients of a message:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">email.utils</span> <span class="k">import</span> <span class="n">getaddresses</span>
<span class="n">tos</span> <span class="o">=</span> <span class="n">msg</span><span class="o">.</span><span class="n">get_all</span><span class="p">(</span><span class="s1">'to'</span><span class="p">,</span> <span class="p">[])</span>
<span class="n">ccs</span> <span class="o">=</span> <span class="n">msg</span><span class="o">.</span><span class="n">get_all</span><span class="p">(</span><span class="s1">'cc'</span><span class="p">,</span> <span class="p">[])</span>
<span class="n">resent_tos</span> <span class="o">=</span> <span class="n">msg</span><span class="o">.</span><span class="n">get_all</span><span class="p">(</span><span class="s1">'resent-to'</span><span class="p">,</span> <span class="p">[])</span>
<span class="n">resent_ccs</span> <span class="o">=</span> <span class="n">msg</span><span class="o">.</span><span class="n">get_all</span><span class="p">(</span><span class="s1">'resent-cc'</span><span class="p">,</span> <span class="p">[])</span>
<span class="n">all_recipients</span> <span class="o">=</span> <span class="n">getaddresses</span><span class="p">(</span><span class="n">tos</span> <span class="o">+</span> <span class="n">ccs</span> <span class="o">+</span> <span class="n">resent_tos</span> <span class="o">+</span> <span class="n">resent_ccs</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>
<dl class="function">
<dt id="email.utils.parsedate">
<code class="descclassname">email.utils.</code><code class="descname">parsedate</code><span class="sig-paren">(</span><em>date</em><span class="sig-paren">)</span><a class="headerlink" href="#email.utils.parsedate" title="本定義的永久連結">¶</a></dt>
<dd><p>Attempts to parse a date according to the rules in <span class="target" id="index-2"></span><a class="rfc reference external" href="https://tools.ietf.org/html/rfc2822.html"><strong>RFC 2822</strong></a>. however, some
mailers don’t follow that format as specified, so <a class="reference internal" href="#email.utils.parsedate" title="email.utils.parsedate"><code class="xref py py-func docutils literal notranslate"><span class="pre">parsedate()</span></code></a> tries to
guess correctly in such cases. <em>date</em> is a string containing an <span class="target" id="index-3"></span><a class="rfc reference external" href="https://tools.ietf.org/html/rfc2822.html"><strong>RFC 2822</strong></a>
date, such as <code class="docutils literal notranslate"><span class="pre">"Mon,</span> <span class="pre">20</span> <span class="pre">Nov</span> <span class="pre">1995</span> <span class="pre">19:12:08</span> <span class="pre">-0500"</span></code>. If it succeeds in parsing
the date, <a class="reference internal" href="#email.utils.parsedate" title="email.utils.parsedate"><code class="xref py py-func docutils literal notranslate"><span class="pre">parsedate()</span></code></a> returns a 9-tuple that can be passed directly to
<a class="reference internal" href="time.html#time.mktime" title="time.mktime"><code class="xref py py-func docutils literal notranslate"><span class="pre">time.mktime()</span></code></a>; otherwise <code class="docutils literal notranslate"><span class="pre">None</span></code> will be returned. Note that indexes 6,
7, and 8 of the result tuple are not usable.</p>
</dd></dl>
<dl class="function">
<dt id="email.utils.parsedate_tz">
<code class="descclassname">email.utils.</code><code class="descname">parsedate_tz</code><span class="sig-paren">(</span><em>date</em><span class="sig-paren">)</span><a class="headerlink" href="#email.utils.parsedate_tz" title="本定義的永久連結">¶</a></dt>
<dd><p>Performs the same function as <a class="reference internal" href="#email.utils.parsedate" title="email.utils.parsedate"><code class="xref py py-func docutils literal notranslate"><span class="pre">parsedate()</span></code></a>, but returns either <code class="docutils literal notranslate"><span class="pre">None</span></code> or
a 10-tuple; the first 9 elements make up a tuple that can be passed directly to
<a class="reference internal" href="time.html#time.mktime" title="time.mktime"><code class="xref py py-func docutils literal notranslate"><span class="pre">time.mktime()</span></code></a>, and the tenth is the offset of the date’s timezone from UTC
(which is the official term for Greenwich Mean Time) <a class="footnote-reference" href="#id2" id="id1">[1]</a>. If the input string
has no timezone, the last element of the tuple returned is <code class="docutils literal notranslate"><span class="pre">None</span></code>. Note that
indexes 6, 7, and 8 of the result tuple are not usable.</p>
</dd></dl>
<dl class="function">
<dt id="email.utils.parsedate_to_datetime">
<code class="descclassname">email.utils.</code><code class="descname">parsedate_to_datetime</code><span class="sig-paren">(</span><em>date</em><span class="sig-paren">)</span><a class="headerlink" href="#email.utils.parsedate_to_datetime" title="本定義的永久連結">¶</a></dt>
<dd><p>The inverse of <a class="reference internal" href="#email.utils.format_datetime" title="email.utils.format_datetime"><code class="xref py py-func docutils literal notranslate"><span class="pre">format_datetime()</span></code></a>. Performs the same function as
<a class="reference internal" href="#email.utils.parsedate" title="email.utils.parsedate"><code class="xref py py-func docutils literal notranslate"><span class="pre">parsedate()</span></code></a>, but on success returns a <a class="reference internal" href="datetime.html#datetime.datetime" title="datetime.datetime"><code class="xref py py-mod docutils literal notranslate"><span class="pre">datetime</span></code></a>. If
the input date has a timezone of <code class="docutils literal notranslate"><span class="pre">-0000</span></code>, the <code class="docutils literal notranslate"><span class="pre">datetime</span></code> will be a naive
<code class="docutils literal notranslate"><span class="pre">datetime</span></code>, and if the date is conforming to the RFCs it will represent a
time in UTC but with no indication of the actual source timezone of the
message the date comes from. If the input date has any other valid timezone
offset, the <code class="docutils literal notranslate"><span class="pre">datetime</span></code> will be an aware <code class="docutils literal notranslate"><span class="pre">datetime</span></code> with the
corresponding a <a class="reference internal" href="datetime.html#datetime.timezone" title="datetime.timezone"><code class="xref py py-class docutils literal notranslate"><span class="pre">timezone</span></code></a> <a class="reference internal" href="datetime.html#datetime.tzinfo" title="datetime.tzinfo"><code class="xref py py-class docutils literal notranslate"><span class="pre">tzinfo</span></code></a>.</p>
<div class="versionadded">
<p><span class="versionmodified">3.3 版新加入.</span></p>
</div>
</dd></dl>
<dl class="function">
<dt id="email.utils.mktime_tz">
<code class="descclassname">email.utils.</code><code class="descname">mktime_tz</code><span class="sig-paren">(</span><em>tuple</em><span class="sig-paren">)</span><a class="headerlink" href="#email.utils.mktime_tz" title="本定義的永久連結">¶</a></dt>
<dd><p>Turn a 10-tuple as returned by <a class="reference internal" href="#email.utils.parsedate_tz" title="email.utils.parsedate_tz"><code class="xref py py-func docutils literal notranslate"><span class="pre">parsedate_tz()</span></code></a> into a UTC
timestamp (seconds since the Epoch). If the timezone item in the
tuple is <code class="docutils literal notranslate"><span class="pre">None</span></code>, assume local time.</p>
</dd></dl>
<dl class="function">
<dt id="email.utils.formatdate">
<code class="descclassname">email.utils.</code><code class="descname">formatdate</code><span class="sig-paren">(</span><em>timeval=None</em>, <em>localtime=False</em>, <em>usegmt=False</em><span class="sig-paren">)</span><a class="headerlink" href="#email.utils.formatdate" title="本定義的永久連結">¶</a></dt>
<dd><p>Returns a date string as per <span class="target" id="index-4"></span><a class="rfc reference external" href="https://tools.ietf.org/html/rfc2822.html"><strong>RFC 2822</strong></a>, e.g.:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">Fri</span><span class="p">,</span> <span class="mi">09</span> <span class="n">Nov</span> <span class="mi">2001</span> <span class="mi">01</span><span class="p">:</span><span class="mi">08</span><span class="p">:</span><span class="mi">47</span> <span class="o">-</span><span class="mi">0000</span>
</pre></div>
</div>
<p>Optional <em>timeval</em> if given is a floating point time value as accepted by
<a class="reference internal" href="time.html#time.gmtime" title="time.gmtime"><code class="xref py py-func docutils literal notranslate"><span class="pre">time.gmtime()</span></code></a> and <a class="reference internal" href="time.html#time.localtime" title="time.localtime"><code class="xref py py-func docutils literal notranslate"><span class="pre">time.localtime()</span></code></a>, otherwise the current time is
used.</p>
<p>Optional <em>localtime</em> is a flag that when <code class="docutils literal notranslate"><span class="pre">True</span></code>, interprets <em>timeval</em>, and
returns a date relative to the local timezone instead of UTC, properly taking
daylight savings time into account. The default is <code class="docutils literal notranslate"><span class="pre">False</span></code> meaning UTC is
used.</p>
<p>Optional <em>usegmt</em> is a flag that when <code class="docutils literal notranslate"><span class="pre">True</span></code>, outputs a date string with the
timezone as an ascii string <code class="docutils literal notranslate"><span class="pre">GMT</span></code>, rather than a numeric <code class="docutils literal notranslate"><span class="pre">-0000</span></code>. This is
needed for some protocols (such as HTTP). This only applies when <em>localtime</em> is
<code class="docutils literal notranslate"><span class="pre">False</span></code>. The default is <code class="docutils literal notranslate"><span class="pre">False</span></code>.</p>
</dd></dl>
<dl class="function">
<dt id="email.utils.format_datetime">
<code class="descclassname">email.utils.</code><code class="descname">format_datetime</code><span class="sig-paren">(</span><em>dt</em>, <em>usegmt=False</em><span class="sig-paren">)</span><a class="headerlink" href="#email.utils.format_datetime" title="本定義的永久連結">¶</a></dt>
<dd><p>Like <code class="docutils literal notranslate"><span class="pre">formatdate</span></code>, but the input is a <a class="reference internal" href="datetime.html#module-datetime" title="datetime: Basic date and time types."><code class="xref py py-mod docutils literal notranslate"><span class="pre">datetime</span></code></a> instance. If it is
a naive datetime, it is assumed to be 「UTC with no information about the
source timezone」, and the conventional <code class="docutils literal notranslate"><span class="pre">-0000</span></code> is used for the timezone.
If it is an aware <code class="docutils literal notranslate"><span class="pre">datetime</span></code>, then the numeric timezone offset is used.
If it is an aware timezone with offset zero, then <em>usegmt</em> may be set to
<code class="docutils literal notranslate"><span class="pre">True</span></code>, in which case the string <code class="docutils literal notranslate"><span class="pre">GMT</span></code> is used instead of the numeric
timezone offset. This provides a way to generate standards conformant HTTP
date headers.</p>
<div class="versionadded">
<p><span class="versionmodified">3.3 版新加入.</span></p>
</div>
</dd></dl>
<dl class="function">
<dt id="email.utils.decode_rfc2231">
<code class="descclassname">email.utils.</code><code class="descname">decode_rfc2231</code><span class="sig-paren">(</span><em>s</em><span class="sig-paren">)</span><a class="headerlink" href="#email.utils.decode_rfc2231" title="本定義的永久連結">¶</a></dt>
<dd><p>Decode the string <em>s</em> according to <span class="target" id="index-5"></span><a class="rfc reference external" href="https://tools.ietf.org/html/rfc2231.html"><strong>RFC 2231</strong></a>.</p>
</dd></dl>
<dl class="function">
<dt id="email.utils.encode_rfc2231">
<code class="descclassname">email.utils.</code><code class="descname">encode_rfc2231</code><span class="sig-paren">(</span><em>s</em>, <em>charset=None</em>, <em>language=None</em><span class="sig-paren">)</span><a class="headerlink" href="#email.utils.encode_rfc2231" title="本定義的永久連結">¶</a></dt>
<dd><p>Encode the string <em>s</em> according to <span class="target" id="index-6"></span><a class="rfc reference external" href="https://tools.ietf.org/html/rfc2231.html"><strong>RFC 2231</strong></a>. Optional <em>charset</em> and
<em>language</em>, if given is the character set name and language name to use. If
neither is given, <em>s</em> is returned as-is. If <em>charset</em> is given but <em>language</em>
is not, the string is encoded using the empty string for <em>language</em>.</p>
</dd></dl>
<dl class="function">
<dt id="email.utils.collapse_rfc2231_value">
<code class="descclassname">email.utils.</code><code class="descname">collapse_rfc2231_value</code><span class="sig-paren">(</span><em>value</em>, <em>errors='replace'</em>, <em>fallback_charset='us-ascii'</em><span class="sig-paren">)</span><a class="headerlink" href="#email.utils.collapse_rfc2231_value" title="本定義的永久連結">¶</a></dt>
<dd><p>When a header parameter is encoded in <span class="target" id="index-7"></span><a class="rfc reference external" href="https://tools.ietf.org/html/rfc2231.html"><strong>RFC 2231</strong></a> format,
<a class="reference internal" href="email.compat32-message.html#email.message.Message.get_param" title="email.message.Message.get_param"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Message.get_param</span></code></a> may return a
3-tuple containing the character set,
language, and value. <a class="reference internal" href="#email.utils.collapse_rfc2231_value" title="email.utils.collapse_rfc2231_value"><code class="xref py py-func docutils literal notranslate"><span class="pre">collapse_rfc2231_value()</span></code></a> turns this into a unicode
string. Optional <em>errors</em> is passed to the <em>errors</em> argument of <a class="reference internal" href="stdtypes.html#str" title="str"><code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code></a>’s
<a class="reference internal" href="stdtypes.html#str.encode" title="str.encode"><code class="xref py py-func docutils literal notranslate"><span class="pre">encode()</span></code></a> method; it defaults to <code class="docutils literal notranslate"><span class="pre">'replace'</span></code>. Optional
<em>fallback_charset</em> specifies the character set to use if the one in the
<span class="target" id="index-8"></span><a class="rfc reference external" href="https://tools.ietf.org/html/rfc2231.html"><strong>RFC 2231</strong></a> header is not known by Python; it defaults to <code class="docutils literal notranslate"><span class="pre">'us-ascii'</span></code>.</p>
<p>For convenience, if the <em>value</em> passed to <a class="reference internal" href="#email.utils.collapse_rfc2231_value" title="email.utils.collapse_rfc2231_value"><code class="xref py py-func docutils literal notranslate"><span class="pre">collapse_rfc2231_value()</span></code></a> is not
a tuple, it should be a string and it is returned unquoted.</p>
</dd></dl>
<dl class="function">
<dt id="email.utils.decode_params">
<code class="descclassname">email.utils.</code><code class="descname">decode_params</code><span class="sig-paren">(</span><em>params</em><span class="sig-paren">)</span><a class="headerlink" href="#email.utils.decode_params" title="本定義的永久連結">¶</a></dt>
<dd><p>Decode parameters list according to <span class="target" id="index-9"></span><a class="rfc reference external" href="https://tools.ietf.org/html/rfc2231.html"><strong>RFC 2231</strong></a>. <em>params</em> is a sequence of
2-tuples containing elements of the form <code class="docutils literal notranslate"><span class="pre">(content-type,</span> <span class="pre">string-value)</span></code>.</p>
</dd></dl>
<p class="rubric">註解</p>
<table class="docutils footnote" frame="void" id="id2" rules="none">
<colgroup><col class="label" /><col /></colgroup>
<tbody valign="top">
<tr><td class="label"><a class="fn-backref" href="#id1">[1]</a></td><td>Note that the sign of the timezone offset is the opposite of the sign of the
<code class="docutils literal notranslate"><span class="pre">time.timezone</span></code> variable for the same timezone; the latter variable follows
the POSIX standard while this module follows <span class="target" id="index-10"></span><a class="rfc reference external" href="https://tools.ietf.org/html/rfc2822.html"><strong>RFC 2822</strong></a>.</td></tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<h4>上個主題</h4>
<p class="topless"><a href="email.encoders.html"
title="上一章">20.1.13. <code class="docutils literal notranslate"><span class="pre">email.encoders</span></code>: Encoders</a></p>
<h4>下個主題</h4>
<p class="topless"><a href="email.iterators.html"
title="下一章">20.1.15. <code class="docutils literal notranslate"><span class="pre">email.iterators</span></code>: Iterators</a></p>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="../bugs.html">Report a Bug</a></li>
<li>
<a href="https://github.com/python/cpython/blob/3.7/Doc/library/email.util.rst"
rel="nofollow">Show Source
</a>
</li>
</ul>
</div>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>瀏覽</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
>索引</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python 模組索引"
>模組</a> |</li>
<li class="right" >
<a href="email.iterators.html" title="20.1.15. email.iterators: Iterators"
>下一頁</a> |</li>
<li class="right" >
<a href="email.encoders.html" title="20.1.13. email.encoders: Encoders"
>上一頁</a> |</li>
<li><img src="../_static/py.png" alt=""
style="vertical-align: middle; margin-top: -1px"/></li>
<li><a href="https://www.python.org/">Python</a> »</li>
<li>
<span class="language_switcher_placeholder">zh_TW</span>
<span class="version_switcher_placeholder">3.7.0</span>
<a href="../index.html">Documentation </a> »
</li>
<li class="nav-item nav-item-1"><a href="index.html" >Python 標準函式庫 (Standard Library)</a> »</li>
<li class="nav-item nav-item-2"><a href="netdata.html" >20. Internet Data Handling</a> »</li>
<li class="nav-item nav-item-3"><a href="email.html" >20.1. <code class="docutils literal notranslate"><span class="pre">email</span></code> — An email and MIME handling package</a> »</li>
<li class="right">
<div class="inline-search" style="display: none" role="search">
<form class="inline-search" action="../search.html" method="get">
<input placeholder="Quick search" type="text" name="q" />
<input type="submit" value="Go" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
<script type="text/javascript">$('.inline-search').show(0);</script>
|
</li>
</ul>
</div>
<div class="footer">
© <a href="../copyright.html">Copyright</a> 2001-2018, Python Software Foundation.
<br />
The Python Software Foundation is a non-profit corporation.
<a href="https://www.python.org/psf/donations/">Please donate.</a>
<br />
Last updated on 8月 22, 2018.
<a href="../bugs.html">Found a bug</a>?
<br />
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.7.7.
</div>
</body>
</html>