Mercurial > cpython-lru_cache-weakref
annotate Doc/lib/emailheaders.tex @ 25838:8540887bcec6 2.2
Backport of 2.183:
Fix memory leak in add_subclass() found by NealN with valgrind.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Fri, 18 Oct 2002 13:42:21 +0000 |
| parents | 14c4c833cda9 |
| children | e333d765f41e |
| rev | line source |
|---|---|
|
25558
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
1 \declaremodule{standard}{email.Header} |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
2 \modulesynopsis{Representing non-ASCII headers} |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
3 |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
4 \rfc{2822} is the base standard that describes the format of email |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
5 messages. It derives from the older \rfc{822} standard which came |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
6 into widespread use at a time when most email was composed of \ASCII{} |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
7 characters only. \rfc{2822} is a specification written assuming email |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
8 contains only 7-bit \ASCII{} characters. |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
9 |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
10 Of course, as email has been deployed worldwide, it has become |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
11 internationalized, such that language specific character sets can now |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
12 be used in email messages. The base standard still requires email |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
13 messages to be transfered using only 7-bit \ASCII{} characters, so a |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
14 slew of RFCs have been written describing how to encode email |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
15 containing non-\ASCII{} characters into \rfc{2822}-compliant format. |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
16 These RFCs include \rfc{2045}, \rfc{2046}, \rfc{2047}, and \rfc{2231}. |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
17 The \module{email} package supports these standards in its |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
18 \module{email.Header} and \module{email.Charset} modules. |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
19 |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
20 If you want to include non-\ASCII{} characters in your email headers, |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
21 say in the \mailheader{Subject} or \mailheader{To} fields, you should |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
22 use the \class{Header} class and assign the field in the |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
23 \class{Message} object to an instance of \class{Header} instead of |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
24 using a string for the header value. For example: |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
25 |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
26 \begin{verbatim} |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
27 >>> from email.Message import Message |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
28 >>> from email.Header import Header |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
29 >>> msg = Message() |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
30 >>> h = Header('p\xf6stal', 'iso-8859-1') |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
31 >>> msg['Subject'] = h |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
32 >>> print msg.as_string() |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
33 Subject: =?iso-8859-1?q?p=F6stal?= |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
34 |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
35 |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
36 \end{verbatim} |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
37 |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
38 Notice here how we wanted the \mailheader{Subject} field to contain a |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
39 non-\ASCII{} character? We did this by creating a \class{Header} |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
40 instance and passing in the character set that the byte string was |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
41 encoded in. When the subsequent \class{Message} instance was |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
42 flattened, the \mailheader{Subject} field was properly \rfc{2047} |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
43 encoded. MIME-aware mail readers would show this header using the |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
44 embedded ISO-8859-1 character. |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
45 |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
46 \versionadded{2.2.2} |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
47 |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
48 Here is the \class{Header} class description: |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
49 |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
50 \begin{classdesc}{Header}{\optional{s\optional{, charset\optional{, |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
51 maxlinelen\optional{, header_name\optional{, continuation_ws}}}}}} |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
52 Create a MIME-compliant header that can contain strings in different |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
53 character sets. |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
54 |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
55 Optional \var{s} is the initial header value. If \code{None} (the |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
56 default), the initial header value is not set. You can later append |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
57 to the header with \method{append()} method calls. \var{s} may be a |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
58 byte string or a Unicode string, but see the \method{append()} |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
59 documentation for semantics. |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
60 |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
61 Optional \var{charset} serves two purposes: it has the same meaning as |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
62 the \var{charset} argument to the \method{append()} method. It also |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
63 sets the default character set for all subsequent \method{append()} |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
64 calls that omit the \var{charset} argument. If \var{charset} is not |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
65 provided in the constructor (the default), the \code{us-ascii} |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
66 character set is used both as \var{s}'s initial charset and as the |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
67 default for subsequent \method{append()} calls. |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
68 |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
69 The maximum line length can be specified explicit via |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
70 \var{maxlinelen}. For splitting the first line to a shorter value (to |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
71 account for the field header which isn't included in \var{s}, |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
72 e.g. \mailheader{Subject}) pass in the name of the field in |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
73 \var{header_name}. The default \var{maxlinelen} is 76, and the |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
74 default value for \var{header_name} is \code{None}, meaning it is not |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
75 taken into account for the first line of a long, split header. |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
76 |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
77 Optional \var{continuation_ws} must be \rfc{2822}-compliant folding |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
78 whitespace, and is usually either a space or a hard tab character. |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
79 This character will be prepended to continuation lines. |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
80 \end{classdesc} |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
81 |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
82 \begin{methoddesc}[Header]{append}{s\optional{, charset}} |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
83 Append the string \var{s} to the MIME header. |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
84 |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
85 Optional \var{charset}, if given, should be a \class{Charset} instance |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
86 (see \refmodule{email.Charset}) or the name of a character set, which |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
87 will be converted to a \class{Charset} instance. A value of |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
88 \code{None} (the default) means that the \var{charset} given in the |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
89 constructor is used. |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
90 |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
91 \var{s} may be a byte string or a Unicode string. If it is a byte |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
92 string (i.e. \code{isinstance(s, str)} is true), then |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
93 \var{charset} is the encoding of that byte string, and a |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
94 \exception{UnicodeError} will be raised if the string cannot be |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
95 decoded with that character set. |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
96 |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
97 If \var{s} is a Unicode string, then \var{charset} is a hint |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
98 specifying the character set of the characters in the string. In this |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
99 case, when producing an \rfc{2822}-compliant header using \rfc{2047} |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
100 rules, the Unicode string will be encoded using the following charsets |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
101 in order: \code{us-ascii}, the \var{charset} hint, \code{utf-8}. The |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
102 first character set to not provoke a \exception{UnicodeError} is used. |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
103 \end{methoddesc} |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
104 |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
105 \begin{methoddesc}[Header]{encode}{} |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
106 Encode a message header into an RFC-compliant format, possibly |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
107 wrapping long lines and encapsulating non-\ASCII{} parts in base64 or |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
108 quoted-printable encodings. |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
109 \end{methoddesc} |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
110 |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
111 The \class{Header} class also provides a number of methods to support |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
112 standard operators and built-in functions. |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
113 |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
114 \begin{methoddesc}[Header]{__str__}{} |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
115 A synonym for \method{Header.encode()}. Useful for |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
116 \code{str(aHeader)}. |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
117 \end{methoddesc} |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
118 |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
119 \begin{methoddesc}[Header]{__unicode__}{} |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
120 A helper for the built-in \function{unicode()} function. Returns the |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
121 header as a Unicode string. |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
122 \end{methoddesc} |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
123 |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
124 \begin{methoddesc}[Header]{__eq__}{other} |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
125 This method allows you to compare two \class{Header} instances for equality. |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
126 \end{methoddesc} |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
127 |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
128 \begin{methoddesc}[Header]{__ne__}{other} |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
129 This method allows you to compare two \class{Header} instances for inequality. |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
130 \end{methoddesc} |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
131 |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
132 The \module{email.Header} module also provides the following |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
133 convenient functions. |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
134 |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
135 \begin{funcdesc}{decode_header}{header} |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
136 Decode a message header value without converting the character set. |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
137 The header value is in \var{header}. |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
138 |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
139 This function returns a list of \code{(decoded_string, charset)} pairs |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
140 containing each of the decoded parts of the header. \var{charset} is |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
141 \code{None} for non-encoded parts of the header, otherwise a lower |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
142 case string containing the name of the character set specified in the |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
143 encoded string. |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
144 |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
145 Here's an example: |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
146 |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
147 \begin{verbatim} |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
148 >>> from email.Header import decode_header |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
149 >>> decode_header('=?iso-8859-1?q?p=F6stal?=') |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
150 [('p\\xf6stal', 'iso-8859-1')] |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
151 \end{verbatim} |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
152 \end{funcdesc} |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
153 |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
154 \begin{funcdesc}{make_header}{decoded_seq\optional{, maxlinelen\optional{, |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
155 header_name\optional{, continuation_ws}}}} |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
156 Create a \class{Header} instance from a sequence of pairs as returned |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
157 by \function{decode_header()}. |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
158 |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
159 \function{decode_header()} takes a header value string and returns a |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
160 sequence of pairs of the format \code{(decoded_string, charset)} where |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
161 \var{charset} is the name of the character set. |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
162 |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
163 This function takes one of those sequence of pairs and returns a |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
164 \class{Header} instance. Optional \var{maxlinelen}, |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
165 \var{header_name}, and \var{continuation_ws} are as in the |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
166 \class{Header} constructor. |
|
14c4c833cda9
This commit was manufactured by cvs2svn to create branch
cvs2svn <tools@python.org>
parents:
diff
changeset
|
167 \end{funcdesc} |
