Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes
test.test_xmlrpc.FailingMessageClass Class Reference
Inheritance diagram for test.test_xmlrpc.FailingMessageClass:
Inheritance graph
[legend]
Collaboration diagram for test.test_xmlrpc.FailingMessageClass:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def get
def getallmatchingheaders
def __str__
def as_string
def is_multipart
def set_unixfrom
def get_unixfrom
def attach
def get_payload
def set_payload
def set_charset
def get_charset
def __len__
def __getitem__
def __setitem__
def __delitem__
def __contains__
def __iter__
def keys
def values
def items
def get_all
def add_header
def replace_header
def get_content_type
def get_content_maintype
def get_content_subtype
def get_default_type
def set_default_type
def get_params
def get_param
def set_param
def del_param
def set_type
def get_filename
def get_boundary
def set_boundary
def get_content_charset
def get_charsets

Public Attributes

 preamble
 epilogue
 defects

Detailed Description

Definition at line 767 of file test_xmlrpc.py.


Member Function Documentation

def email.message.Message.__contains__ (   self,
  name 
) [inherited]

Definition at line 379 of file message.py.

00379 
00380     def __contains__(self, name):
00381         return name.lower() in [k.lower() for k, v in self._headers]

def email.message.Message.__delitem__ (   self,
  name 
) [inherited]
Delete all occurrences of a header, if present.

Does not raise an exception if the header is missing.

Definition at line 367 of file message.py.

00367 
00368     def __delitem__(self, name):
00369         """Delete all occurrences of a header, if present.
00370 
00371         Does not raise an exception if the header is missing.
00372         """
00373         name = name.lower()
00374         newheaders = []
00375         for k, v in self._headers:
00376             if k.lower() != name:
00377                 newheaders.append((k, v))
00378         self._headers = newheaders

def email.message.Message.__getitem__ (   self,
  name 
) [inherited]
Get a header value.

Return None if the header is missing instead of raising an exception.

Note that if the header appeared multiple times, exactly which
occurrence gets returned is undefined.  Use get_all() to get all
the values matching a header field name.

Definition at line 348 of file message.py.

00348 
00349     def __getitem__(self, name):
00350         """Get a header value.
00351 
00352         Return None if the header is missing instead of raising an exception.
00353 
00354         Note that if the header appeared multiple times, exactly which
00355         occurrence gets returned is undefined.  Use get_all() to get all
00356         the values matching a header field name.
00357         """
00358         return self.get(name)

Here is the call graph for this function:

Here is the caller graph for this function:

def email.message.Message.__iter__ (   self) [inherited]

Definition at line 382 of file message.py.

00382 
00383     def __iter__(self):
00384         for field, value in self._headers:
00385             yield field

def email.message.Message.__len__ (   self) [inherited]
Return the total number of headers, including duplicates.

Definition at line 344 of file message.py.

00344 
00345     def __len__(self):
00346         """Return the total number of headers, including duplicates."""
00347         return len(self._headers)

def email.message.Message.__setitem__ (   self,
  name,
  val 
) [inherited]
Set the value of a header.

Note: this does not overwrite an existing header with the same field
name.  Use __delitem__() first to delete any existing headers.

Definition at line 359 of file message.py.

00359 
00360     def __setitem__(self, name, val):
00361         """Set the value of a header.
00362 
00363         Note: this does not overwrite an existing header with the same field
00364         name.  Use __delitem__() first to delete any existing headers.
00365         """
00366         self._headers.append((name, val))

def email.message.Message.__str__ (   self) [inherited]
Return the entire formatted message as a string.
This includes the headers, body, and envelope header.

Definition at line 150 of file message.py.

00150 
00151     def __str__(self):
00152         """Return the entire formatted message as a string.
00153         This includes the headers, body, and envelope header.
00154         """
00155         return self.as_string()

Here is the call graph for this function:

def email.message.Message.add_header (   self,
  _name,
  _value,
  _params 
) [inherited]
Extended header setting.

name is the header field to add.  keyword arguments can be used to set
additional parameters for the header field, with underscores converted
to dashes.  Normally the parameter will be added as key="value" unless
value is None, in which case only the key will be added.  If a
parameter value contains non-ASCII characters it can be specified as a
three-tuple of (charset, language, value), in which case it will be
encoded according to RFC2231 rules.  Otherwise it will be encoded using
the utf-8 charset and a language of ''.

Examples:

msg.add_header('content-disposition', 'attachment', filename='bud.gif')
msg.add_header('content-disposition', 'attachment',
       filename=('utf-8', '', Fußballer.ppt'))
msg.add_header('content-disposition', 'attachment',
       filename='Fußballer.ppt'))

Definition at line 450 of file message.py.

00450 
00451     def add_header(self, _name, _value, **_params):
00452         """Extended header setting.
00453 
00454         name is the header field to add.  keyword arguments can be used to set
00455         additional parameters for the header field, with underscores converted
00456         to dashes.  Normally the parameter will be added as key="value" unless
00457         value is None, in which case only the key will be added.  If a
00458         parameter value contains non-ASCII characters it can be specified as a
00459         three-tuple of (charset, language, value), in which case it will be
00460         encoded according to RFC2231 rules.  Otherwise it will be encoded using
00461         the utf-8 charset and a language of ''.
00462 
00463         Examples:
00464 
00465         msg.add_header('content-disposition', 'attachment', filename='bud.gif')
00466         msg.add_header('content-disposition', 'attachment',
00467                        filename=('utf-8', '', Fußballer.ppt'))
00468         msg.add_header('content-disposition', 'attachment',
00469                        filename='Fußballer.ppt'))
00470         """
00471         parts = []
00472         for k, v in _params.items():
00473             if v is None:
00474                 parts.append(k.replace('_', '-'))
00475             else:
00476                 parts.append(_formatparam(k.replace('_', '-'), v))
00477         if _value is not None:
00478             parts.insert(0, _value)
00479         self._headers.append((_name, SEMISPACE.join(parts)))

Here is the caller graph for this function:

def email.message.Message.as_string (   self,
  unixfrom = False,
  maxheaderlen = 0 
) [inherited]
Return the entire formatted message as a string.
Optional `unixfrom' when True, means include the Unix From_ envelope
header.

This is a convenience method and may not generate the message exactly
as you intend.  For more flexibility, use the flatten() method of a
Generator instance.

Definition at line 156 of file message.py.

00156 
00157     def as_string(self, unixfrom=False, maxheaderlen=0):
00158         """Return the entire formatted message as a string.
00159         Optional `unixfrom' when True, means include the Unix From_ envelope
00160         header.
00161 
00162         This is a convenience method and may not generate the message exactly
00163         as you intend.  For more flexibility, use the flatten() method of a
00164         Generator instance.
00165         """
00166         from email.generator import Generator
00167         fp = StringIO()
00168         g = Generator(fp, mangle_from_=False, maxheaderlen=maxheaderlen)
00169         g.flatten(self, unixfrom=unixfrom)
00170         return fp.getvalue()

Here is the caller graph for this function:

def email.message.Message.attach (   self,
  payload 
) [inherited]
Add the given payload to the current payload.

The current payload will always be a list of objects after this method
is called.  If you want to set the payload to a scalar object, use
set_payload() instead.

Reimplemented in email.mime.nonmultipart.MIMENonMultipart.

Definition at line 187 of file message.py.

00187 
00188     def attach(self, payload):
00189         """Add the given payload to the current payload.
00190 
00191         The current payload will always be a list of objects after this method
00192         is called.  If you want to set the payload to a scalar object, use
00193         set_payload() instead.
00194         """
00195         if self._payload is None:
00196             self._payload = [payload]
00197         else:
00198             self._payload.append(payload)

def email.message.Message.del_param (   self,
  param,
  header = 'content-type',
  requote = True 
) [inherited]
Remove the given parameter completely from the Content-Type header.

The header will be re-written in place without the parameter or its
value. All values will be quoted as necessary unless requote is
False.  Optional header specifies an alternative to the Content-Type
header.

Definition at line 686 of file message.py.

00686 
00687     def del_param(self, param, header='content-type', requote=True):
00688         """Remove the given parameter completely from the Content-Type header.
00689 
00690         The header will be re-written in place without the parameter or its
00691         value. All values will be quoted as necessary unless requote is
00692         False.  Optional header specifies an alternative to the Content-Type
00693         header.
00694         """
00695         if header not in self:
00696             return
00697         new_ctype = ''
00698         for p, v in self.get_params(header=header, unquote=requote):
00699             if p.lower() != param.lower():
00700                 if not new_ctype:
00701                     new_ctype = _formatparam(p, v, requote)
00702                 else:
00703                     new_ctype = SEMISPACE.join([new_ctype,
00704                                                 _formatparam(p, v, requote)])
00705         if new_ctype != self.get(header):
00706             del self[header]
00707             self[header] = new_ctype

Here is the call graph for this function:

Here is the caller graph for this function:

def test.test_xmlrpc.FailingMessageClass.get (   self,
  name,
  failobj = None 
)
Get a header value.

Like __getitem__() but return failobj instead of None when the field
is missing.

Reimplemented from email.message.Message.

Definition at line 768 of file test_xmlrpc.py.

00768 
00769     def get(self, key, failobj=None):
00770         key = key.lower()
00771         if key == 'content-length':
00772             return 'I am broken'
00773         return super().get(key, failobj)
00774 
00775 
@unittest.skipUnless(threading, 'Threading required for this test.')

Here is the caller graph for this function:

def email.message.Message.get_all (   self,
  name,
  failobj = None 
) [inherited]
Return a list of all the values for the named field.

These will be sorted in the order they appeared in the original
message, and may contain duplicates.  Any fields deleted and
re-inserted are always appended to the header list.

If no such fields exist, failobj is returned (defaults to None).

Definition at line 432 of file message.py.

00432 
00433     def get_all(self, name, failobj=None):
00434         """Return a list of all the values for the named field.
00435 
00436         These will be sorted in the order they appeared in the original
00437         message, and may contain duplicates.  Any fields deleted and
00438         re-inserted are always appended to the header list.
00439 
00440         If no such fields exist, failobj is returned (defaults to None).
00441         """
00442         values = []
00443         name = name.lower()
00444         for k, v in self._headers:
00445             if k.lower() == name:
00446                 values.append(_sanitize_header(k, v))
00447         if not values:
00448             return failobj
00449         return values

def email.message.Message.get_boundary (   self,
  failobj = None 
) [inherited]
Return the boundary associated with the payload if present.

The boundary is extracted from the Content-Type header's `boundary'
parameter, and it is unquoted.

Definition at line 756 of file message.py.

00756 
00757     def get_boundary(self, failobj=None):
00758         """Return the boundary associated with the payload if present.
00759 
00760         The boundary is extracted from the Content-Type header's `boundary'
00761         parameter, and it is unquoted.
00762         """
00763         missing = object()
00764         boundary = self.get_param('boundary', missing)
00765         if boundary is missing:
00766             return failobj
00767         # RFC 2046 says that boundaries may begin but not end in w/s
00768         return utils.collapse_rfc2231_value(boundary).rstrip()

Here is the call graph for this function:

def email.message.Message.get_charset (   self) [inherited]
Return the Charset instance associated with the message's payload.

Definition at line 336 of file message.py.

00336 
00337     def get_charset(self):
00338         """Return the Charset instance associated with the message's payload.
00339         """
00340         return self._charset

def email.message.Message.get_charsets (   self,
  failobj = None 
) [inherited]
Return a list containing the charset(s) used in this message.

The returned list of items describes the Content-Type headers'
charset parameter for this message and all the subparts in its
payload.

Each item will either be a string (the value of the charset parameter
in the Content-Type header of that part) or the value of the
'failobj' parameter (defaults to None), if the part does not have a
main MIME type of "text", or the charset is not defined.

The list will contain one string for each part of the message, plus
one for the container message (i.e. self), so that a non-multipart
message will still return a list of length 1.

Definition at line 844 of file message.py.

00844 
00845     def get_charsets(self, failobj=None):
00846         """Return a list containing the charset(s) used in this message.
00847 
00848         The returned list of items describes the Content-Type headers'
00849         charset parameter for this message and all the subparts in its
00850         payload.
00851 
00852         Each item will either be a string (the value of the charset parameter
00853         in the Content-Type header of that part) or the value of the
00854         'failobj' parameter (defaults to None), if the part does not have a
00855         main MIME type of "text", or the charset is not defined.
00856 
00857         The list will contain one string for each part of the message, plus
00858         one for the container message (i.e. self), so that a non-multipart
00859         message will still return a list of length 1.
00860         """
00861         return [part.get_content_charset(failobj) for part in self.walk()]

def email.message.Message.get_content_charset (   self,
  failobj = None 
) [inherited]
Return the charset parameter of the Content-Type header.

The returned string is always coerced to lower case.  If there is no
Content-Type header, or if that header has no charset parameter,
failobj is returned.

Definition at line 814 of file message.py.

00814 
00815     def get_content_charset(self, failobj=None):
00816         """Return the charset parameter of the Content-Type header.
00817 
00818         The returned string is always coerced to lower case.  If there is no
00819         Content-Type header, or if that header has no charset parameter,
00820         failobj is returned.
00821         """
00822         missing = object()
00823         charset = self.get_param('charset', missing)
00824         if charset is missing:
00825             return failobj
00826         if isinstance(charset, tuple):
00827             # RFC 2231 encoded, so decode it, and it better end up as ascii.
00828             pcharset = charset[0] or 'us-ascii'
00829             try:
00830                 # LookupError will be raised if the charset isn't known to
00831                 # Python.  UnicodeError will be raised if the encoded text
00832                 # contains a character not in the charset.
00833                 as_bytes = charset[2].encode('raw-unicode-escape')
00834                 charset = str(as_bytes, pcharset)
00835             except (LookupError, UnicodeError):
00836                 charset = charset[2]
00837         # charset characters must be in us-ascii range
00838         try:
00839             charset.encode('us-ascii')
00840         except UnicodeError:
00841             return failobj
00842         # RFC 2046, $4.1.2 says charsets are not case sensitive
00843         return charset.lower()

Here is the call graph for this function:

def email.message.Message.get_content_maintype (   self) [inherited]
Return the message's main content type.

This is the `maintype' part of the string returned by
get_content_type().

Definition at line 523 of file message.py.

00523 
00524     def get_content_maintype(self):
00525         """Return the message's main content type.
00526 
00527         This is the `maintype' part of the string returned by
00528         get_content_type().
00529         """
00530         ctype = self.get_content_type()
00531         return ctype.split('/')[0]

Here is the call graph for this function:

def email.message.Message.get_content_subtype (   self) [inherited]
Returns the message's sub-content type.

This is the `subtype' part of the string returned by
get_content_type().

Definition at line 532 of file message.py.

00532 
00533     def get_content_subtype(self):
00534         """Returns the message's sub-content type.
00535 
00536         This is the `subtype' part of the string returned by
00537         get_content_type().
00538         """
00539         ctype = self.get_content_type()
00540         return ctype.split('/')[1]

Here is the call graph for this function:

def email.message.Message.get_content_type (   self) [inherited]
Return the message's content type.

The returned string is coerced to lower case of the form
`maintype/subtype'.  If there was no Content-Type header in the
message, the default type as given by get_default_type() will be
returned.  Since according to RFC 2045, messages always have a default
type this will always return a value.

RFC 2045 defines a message's default type to be text/plain unless it
appears inside a multipart/digest container, in which case it would be
message/rfc822.

Definition at line 499 of file message.py.

00499 
00500     def get_content_type(self):
00501         """Return the message's content type.
00502 
00503         The returned string is coerced to lower case of the form
00504         `maintype/subtype'.  If there was no Content-Type header in the
00505         message, the default type as given by get_default_type() will be
00506         returned.  Since according to RFC 2045, messages always have a default
00507         type this will always return a value.
00508 
00509         RFC 2045 defines a message's default type to be text/plain unless it
00510         appears inside a multipart/digest container, in which case it would be
00511         message/rfc822.
00512         """
00513         missing = object()
00514         value = self.get('content-type', missing)
00515         if value is missing:
00516             # This should have no parameters
00517             return self.get_default_type()
00518         ctype = _splitparam(value)[0].lower()
00519         # RFC 2045, section 5.2 says if its invalid, use text/plain
00520         if ctype.count('/') != 1:
00521             return 'text/plain'
00522         return ctype

Here is the call graph for this function:

Here is the caller graph for this function:

def email.message.Message.get_default_type (   self) [inherited]
Return the `default' content type.

Most messages have a default content type of text/plain, except for
messages that are subparts of multipart/digest containers.  Such
subparts have a default content type of message/rfc822.

Definition at line 541 of file message.py.

00541 
00542     def get_default_type(self):
00543         """Return the `default' content type.
00544 
00545         Most messages have a default content type of text/plain, except for
00546         messages that are subparts of multipart/digest containers.  Such
00547         subparts have a default content type of message/rfc822.
00548         """
00549         return self._default_type

Here is the caller graph for this function:

def email.message.Message.get_filename (   self,
  failobj = None 
) [inherited]
Return the filename associated with the payload if present.

The filename is extracted from the Content-Disposition header's
`filename' parameter, and it is unquoted.  If that header is missing
the `filename' parameter, this method falls back to looking for the
`name' parameter.

Definition at line 740 of file message.py.

00740 
00741     def get_filename(self, failobj=None):
00742         """Return the filename associated with the payload if present.
00743 
00744         The filename is extracted from the Content-Disposition header's
00745         `filename' parameter, and it is unquoted.  If that header is missing
00746         the `filename' parameter, this method falls back to looking for the
00747         `name' parameter.
00748         """
00749         missing = object()
00750         filename = self.get_param('filename', missing, 'content-disposition')
00751         if filename is missing:
00752             filename = self.get_param('name', missing, 'content-type')
00753         if filename is missing:
00754             return failobj
00755         return utils.collapse_rfc2231_value(filename).strip()

Here is the call graph for this function:

Here is the caller graph for this function:

def email.message.Message.get_param (   self,
  param,
  failobj = None,
  header = 'content-type',
  unquote = True 
) [inherited]
Return the parameter value if found in the Content-Type header.

Optional failobj is the object to return if there is no Content-Type
header, or the Content-Type header has no such parameter.  Optional
header is the header to search instead of Content-Type.

Parameter keys are always compared case insensitively.  The return
value can either be a string, or a 3-tuple if the parameter was RFC
2231 encoded.  When it's a 3-tuple, the elements of the value are of
the form (CHARSET, LANGUAGE, VALUE).  Note that both CHARSET and
LANGUAGE can be None, in which case you should consider VALUE to be
encoded in the us-ascii charset.  You can usually ignore LANGUAGE.

Your application should be prepared to deal with 3-tuple return
values, and can convert the parameter to a Unicode string like so:

    param = msg.get_param('foo')
    if isinstance(param, tuple):
param = unicode(param[2], param[0] or 'us-ascii')

In any case, the parameter value (either the returned string, or the
VALUE item in the 3-tuple) is always unquoted, unless unquote is set
to False.

Definition at line 603 of file message.py.

00603 
00604                   unquote=True):
00605         """Return the parameter value if found in the Content-Type header.
00606 
00607         Optional failobj is the object to return if there is no Content-Type
00608         header, or the Content-Type header has no such parameter.  Optional
00609         header is the header to search instead of Content-Type.
00610 
00611         Parameter keys are always compared case insensitively.  The return
00612         value can either be a string, or a 3-tuple if the parameter was RFC
00613         2231 encoded.  When it's a 3-tuple, the elements of the value are of
00614         the form (CHARSET, LANGUAGE, VALUE).  Note that both CHARSET and
00615         LANGUAGE can be None, in which case you should consider VALUE to be
00616         encoded in the us-ascii charset.  You can usually ignore LANGUAGE.
00617 
00618         Your application should be prepared to deal with 3-tuple return
00619         values, and can convert the parameter to a Unicode string like so:
00620 
00621             param = msg.get_param('foo')
00622             if isinstance(param, tuple):
00623                 param = unicode(param[2], param[0] or 'us-ascii')
00624 
00625         In any case, the parameter value (either the returned string, or the
00626         VALUE item in the 3-tuple) is always unquoted, unless unquote is set
00627         to False.
00628         """
00629         if header not in self:
00630             return failobj
00631         for k, v in self._get_params_preserve(failobj, header):
00632             if k.lower() == param.lower():
00633                 if unquote:
00634                     return _unquotevalue(v)
00635                 else:
00636                     return v
00637         return failobj

Here is the call graph for this function:

Here is the caller graph for this function:

def email.message.Message.get_params (   self,
  failobj = None,
  header = 'content-type',
  unquote = True 
) [inherited]
Return the message's Content-Type parameters, as a list.

The elements of the returned list are 2-tuples of key/value pairs, as
split on the `=' sign.  The left hand side of the `=' is the key,
while the right hand side is the value.  If there is no `=' sign in
the parameter the value is the empty string.  The value is as
described in the get_param() method.

Optional failobj is the object to return if there is no Content-Type
header.  Optional header is the header to search instead of
Content-Type.  If unquote is True, the value is unquoted.

Definition at line 580 of file message.py.

00580 
00581     def get_params(self, failobj=None, header='content-type', unquote=True):
00582         """Return the message's Content-Type parameters, as a list.
00583 
00584         The elements of the returned list are 2-tuples of key/value pairs, as
00585         split on the `=' sign.  The left hand side of the `=' is the key,
00586         while the right hand side is the value.  If there is no `=' sign in
00587         the parameter the value is the empty string.  The value is as
00588         described in the get_param() method.
00589 
00590         Optional failobj is the object to return if there is no Content-Type
00591         header.  Optional header is the header to search instead of
00592         Content-Type.  If unquote is True, the value is unquoted.
00593         """
00594         missing = object()
00595         params = self._get_params_preserve(missing, header)
00596         if params is missing:
00597             return failobj
00598         if unquote:
00599             return [(k, _unquotevalue(v)) for k, v in params]
00600         else:
00601             return params

Here is the call graph for this function:

Here is the caller graph for this function:

def email.message.Message.get_payload (   self,
  i = None,
  decode = False 
) [inherited]
Return a reference to the payload.

The payload will either be a list object or a string.  If you mutate
the list object, you modify the message's payload in place.  Optional
i returns that index into the payload.

Optional decode is a flag indicating whether the payload should be
decoded or not, according to the Content-Transfer-Encoding header
(default is False).

When True and the message is not a multipart, the payload will be
decoded if this header's value is `quoted-printable' or `base64'.  If
some other encoding is used, or the header is missing, or if the
payload has bogus data (i.e. bogus base64 or uuencoded data), the
payload is returned as-is.

If the message is a multipart and the decode flag is True, then None
is returned.

Definition at line 199 of file message.py.

00199 
00200     def get_payload(self, i=None, decode=False):
00201         """Return a reference to the payload.
00202 
00203         The payload will either be a list object or a string.  If you mutate
00204         the list object, you modify the message's payload in place.  Optional
00205         i returns that index into the payload.
00206 
00207         Optional decode is a flag indicating whether the payload should be
00208         decoded or not, according to the Content-Transfer-Encoding header
00209         (default is False).
00210 
00211         When True and the message is not a multipart, the payload will be
00212         decoded if this header's value is `quoted-printable' or `base64'.  If
00213         some other encoding is used, or the header is missing, or if the
00214         payload has bogus data (i.e. bogus base64 or uuencoded data), the
00215         payload is returned as-is.
00216 
00217         If the message is a multipart and the decode flag is True, then None
00218         is returned.
00219         """
00220         # Here is the logic table for this code, based on the email5.0.0 code:
00221         #   i     decode  is_multipart  result
00222         # ------  ------  ------------  ------------------------------
00223         #  None   True    True          None
00224         #   i     True    True          None
00225         #  None   False   True          _payload (a list)
00226         #   i     False   True          _payload element i (a Message)
00227         #   i     False   False         error (not a list)
00228         #   i     True    False         error (not a list)
00229         #  None   False   False         _payload
00230         #  None   True    False         _payload decoded (bytes)
00231         # Note that Barry planned to factor out the 'decode' case, but that
00232         # isn't so easy now that we handle the 8 bit data, which needs to be
00233         # converted in both the decode and non-decode path.
00234         if self.is_multipart():
00235             if decode:
00236                 return None
00237             if i is None:
00238                 return self._payload
00239             else:
00240                 return self._payload[i]
00241         # For backward compatibility, Use isinstance and this error message
00242         # instead of the more logical is_multipart test.
00243         if i is not None and not isinstance(self._payload, list):
00244             raise TypeError('Expected list, got %s' % type(self._payload))
00245         payload = self._payload
00246         # cte might be a Header, so for now stringify it.
00247         cte = str(self.get('content-transfer-encoding', '')).lower()
00248         # payload may be bytes here.
00249         if isinstance(payload, str):
00250             if _has_surrogates(payload):
00251                 bpayload = payload.encode('ascii', 'surrogateescape')
00252                 if not decode:
00253                     try:
00254                         payload = bpayload.decode(self.get_param('charset', 'ascii'), 'replace')
00255                     except LookupError:
00256                         payload = bpayload.decode('ascii', 'replace')
00257             elif decode:
00258                 try:
00259                     bpayload = payload.encode('ascii')
00260                 except UnicodeError:
00261                     # This won't happen for RFC compliant messages (messages
00262                     # containing only ASCII codepoints in the unicode input).
00263                     # If it does happen, turn the string into bytes in a way
00264                     # guaranteed not to fail.
00265                     bpayload = payload.encode('raw-unicode-escape')
00266         if not decode:
00267             return payload
00268         if cte == 'quoted-printable':
00269             return utils._qdecode(bpayload)
00270         elif cte == 'base64':
00271             try:
00272                 return base64.b64decode(bpayload)
00273             except binascii.Error:
00274                 # Incorrect padding
00275                 return bpayload
00276         elif cte in ('x-uuencode', 'uuencode', 'uue', 'x-uue'):
00277             in_file = BytesIO(bpayload)
00278             out_file = BytesIO()
00279             try:
00280                 uu.decode(in_file, out_file, quiet=True)
00281                 return out_file.getvalue()
00282             except uu.Error:
00283                 # Some decoding problem
00284                 return bpayload
00285         if isinstance(payload, str):
00286             return bpayload
00287         return payload

Here is the call graph for this function:

def email.message.Message.get_unixfrom (   self) [inherited]

Definition at line 181 of file message.py.

00181 
00182     def get_unixfrom(self):
00183         return self._unixfrom

def http.client.HTTPMessage.getallmatchingheaders (   self,
  name 
) [inherited]
Find all header lines matching a given header name.

Look through the list of headers and find all lines matching a given
header name (and their continuation lines).  A list of the lines is
returned, without interpretation.  If the header does not occur, an
empty list is returned.  If the header occurs multiple times, all
occurrences are returned.  Case is not important in the header name.

Definition at line 217 of file client.py.

00217 
00218     def getallmatchingheaders(self, name):
00219         """Find all header lines matching a given header name.
00220 
00221         Look through the list of headers and find all lines matching a given
00222         header name (and their continuation lines).  A list of the lines is
00223         returned, without interpretation.  If the header does not occur, an
00224         empty list is returned.  If the header occurs multiple times, all
00225         occurrences are returned.  Case is not important in the header name.
00226 
00227         """
00228         name = name.lower() + ':'
00229         n = len(name)
00230         lst = []
00231         hit = 0
00232         for line in self.keys():
00233             if line[:n].lower() == name:
00234                 hit = 1
00235             elif not line[:1].isspace():
00236                 hit = 0
00237             if hit:
00238                 lst.append(line)
00239         return lst

Here is the call graph for this function:

def email.message.Message.is_multipart (   self) [inherited]
Return True if the message consists of multiple parts.

Definition at line 171 of file message.py.

00171 
00172     def is_multipart(self):
00173         """Return True if the message consists of multiple parts."""
00174         return isinstance(self._payload, list)

Here is the caller graph for this function:

def email.message.Message.items (   self) [inherited]
Get all the message's header fields and values.

These will be sorted in the order they appeared in the original
message, or were added to the message, and may contain duplicates.
Any fields deleted and re-inserted are always appended to the header
list.

Definition at line 406 of file message.py.

00406 
00407     def items(self):
00408         """Get all the message's header fields and values.
00409 
00410         These will be sorted in the order they appeared in the original
00411         message, or were added to the message, and may contain duplicates.
00412         Any fields deleted and re-inserted are always appended to the header
00413         list.
00414         """
00415         return [(k, _sanitize_header(k, v)) for k, v in self._headers]

Here is the caller graph for this function:

def email.message.Message.keys (   self) [inherited]
Return a list of all the message's header field names.

These will be sorted in the order they appeared in the original
message, or were added to the message, and may contain duplicates.
Any fields deleted and re-inserted are always appended to the header
list.

Definition at line 386 of file message.py.

00386 
00387     def keys(self):
00388         """Return a list of all the message's header field names.
00389 
00390         These will be sorted in the order they appeared in the original
00391         message, or were added to the message, and may contain duplicates.
00392         Any fields deleted and re-inserted are always appended to the header
00393         list.
00394         """
00395         return [k for k, v in self._headers]

Here is the caller graph for this function:

def email.message.Message.replace_header (   self,
  _name,
  _value 
) [inherited]
Replace a header.

Replace the first matching header found in the message, retaining
header order and case.  If no matching header was found, a KeyError is
raised.

Definition at line 480 of file message.py.

00480 
00481     def replace_header(self, _name, _value):
00482         """Replace a header.
00483 
00484         Replace the first matching header found in the message, retaining
00485         header order and case.  If no matching header was found, a KeyError is
00486         raised.
00487         """
00488         _name = _name.lower()
00489         for i, (k, v) in zip(range(len(self._headers)), self._headers):
00490             if k.lower() == _name:
00491                 self._headers[i] = (k, _value)
00492                 break
00493         else:
00494             raise KeyError(_name)

Here is the caller graph for this function:

def email.message.Message.set_boundary (   self,
  boundary 
) [inherited]
Set the boundary parameter in Content-Type to 'boundary'.

This is subtly different than deleting the Content-Type header and
adding a new one with a new boundary parameter via add_header().  The
main difference is that using the set_boundary() method preserves the
order of the Content-Type header in the original message.

HeaderParseError is raised if the message has no Content-Type header.

Definition at line 769 of file message.py.

00769 
00770     def set_boundary(self, boundary):
00771         """Set the boundary parameter in Content-Type to 'boundary'.
00772 
00773         This is subtly different than deleting the Content-Type header and
00774         adding a new one with a new boundary parameter via add_header().  The
00775         main difference is that using the set_boundary() method preserves the
00776         order of the Content-Type header in the original message.
00777 
00778         HeaderParseError is raised if the message has no Content-Type header.
00779         """
00780         missing = object()
00781         params = self._get_params_preserve(missing, 'content-type')
00782         if params is missing:
00783             # There was no Content-Type header, and we don't know what type
00784             # to set it to, so raise an exception.
00785             raise errors.HeaderParseError('No Content-Type header found')
00786         newparams = []
00787         foundp = False
00788         for pk, pv in params:
00789             if pk.lower() == 'boundary':
00790                 newparams.append(('boundary', '"%s"' % boundary))
00791                 foundp = True
00792             else:
00793                 newparams.append((pk, pv))
00794         if not foundp:
00795             # The original Content-Type header had no boundary attribute.
00796             # Tack one on the end.  BAW: should we raise an exception
00797             # instead???
00798             newparams.append(('boundary', '"%s"' % boundary))
00799         # Replace the existing Content-Type header with the new value
00800         newheaders = []
00801         for h, v in self._headers:
00802             if h.lower() == 'content-type':
00803                 parts = []
00804                 for k, v in newparams:
00805                     if v == '':
00806                         parts.append(k)
00807                     else:
00808                         parts.append('%s=%s' % (k, v))
00809                 newheaders.append((h, SEMISPACE.join(parts)))
00810 
00811             else:
00812                 newheaders.append((h, v))
00813         self._headers = newheaders

Here is the call graph for this function:

def email.message.Message.set_charset (   self,
  charset 
) [inherited]
Set the charset of the payload to a given character set.

charset can be a Charset instance, a string naming a character set, or
None.  If it is a string it will be converted to a Charset instance.
If charset is None, the charset parameter will be removed from the
Content-Type field.  Anything else will generate a TypeError.

The message will be assumed to be of type text/* encoded with
charset.input_charset.  It will be converted to charset.output_charset
and encoded properly, if needed, when generating the plain text
representation of the message.  MIME headers (MIME-Version,
Content-Type, Content-Transfer-Encoding) will be added as needed.

Definition at line 298 of file message.py.

00298 
00299     def set_charset(self, charset):
00300         """Set the charset of the payload to a given character set.
00301 
00302         charset can be a Charset instance, a string naming a character set, or
00303         None.  If it is a string it will be converted to a Charset instance.
00304         If charset is None, the charset parameter will be removed from the
00305         Content-Type field.  Anything else will generate a TypeError.
00306 
00307         The message will be assumed to be of type text/* encoded with
00308         charset.input_charset.  It will be converted to charset.output_charset
00309         and encoded properly, if needed, when generating the plain text
00310         representation of the message.  MIME headers (MIME-Version,
00311         Content-Type, Content-Transfer-Encoding) will be added as needed.
00312         """
00313         if charset is None:
00314             self.del_param('charset')
00315             self._charset = None
00316             return
00317         if not isinstance(charset, Charset):
00318             charset = Charset(charset)
00319         self._charset = charset
00320         if 'MIME-Version' not in self:
00321             self.add_header('MIME-Version', '1.0')
00322         if 'Content-Type' not in self:
00323             self.add_header('Content-Type', 'text/plain',
00324                             charset=charset.get_output_charset())
00325         else:
00326             self.set_param('charset', charset.get_output_charset())
00327         if charset != charset.get_output_charset():
00328             self._payload = charset.body_encode(self._payload)
00329         if 'Content-Transfer-Encoding' not in self:
00330             cte = charset.get_body_encoding()
00331             try:
00332                 cte(self)
00333             except TypeError:
00334                 self._payload = charset.body_encode(self._payload)
00335                 self.add_header('Content-Transfer-Encoding', cte)

Here is the call graph for this function:

Here is the caller graph for this function:

def email.message.Message.set_default_type (   self,
  ctype 
) [inherited]
Set the `default' content type.

ctype should be either "text/plain" or "message/rfc822", although this
is not enforced.  The default content type is not stored in the
Content-Type header.

Definition at line 550 of file message.py.

00550 
00551     def set_default_type(self, ctype):
00552         """Set the `default' content type.
00553 
00554         ctype should be either "text/plain" or "message/rfc822", although this
00555         is not enforced.  The default content type is not stored in the
00556         Content-Type header.
00557         """
00558         self._default_type = ctype

Here is the caller graph for this function:

def email.message.Message.set_param (   self,
  param,
  value,
  header = 'Content-Type',
  requote = True,
  charset = None,
  language = '' 
) [inherited]
Set a parameter in the Content-Type header.

If the parameter already exists in the header, its value will be
replaced with the new value.

If header is Content-Type and has not yet been defined for this
message, it will be set to "text/plain" and the new parameter and
value will be appended as per RFC 2045.

An alternate header can specified in the header argument, and all
parameters will be quoted as necessary unless requote is False.

If charset is specified, the parameter will be encoded according to RFC
2231.  Optional language specifies the RFC 2231 language, defaulting
to the empty string.  Both charset and language should be strings.

Definition at line 639 of file message.py.

00639 
00640                   charset=None, language=''):
00641         """Set a parameter in the Content-Type header.
00642 
00643         If the parameter already exists in the header, its value will be
00644         replaced with the new value.
00645 
00646         If header is Content-Type and has not yet been defined for this
00647         message, it will be set to "text/plain" and the new parameter and
00648         value will be appended as per RFC 2045.
00649 
00650         An alternate header can specified in the header argument, and all
00651         parameters will be quoted as necessary unless requote is False.
00652 
00653         If charset is specified, the parameter will be encoded according to RFC
00654         2231.  Optional language specifies the RFC 2231 language, defaulting
00655         to the empty string.  Both charset and language should be strings.
00656         """
00657         if not isinstance(value, tuple) and charset:
00658             value = (charset, language, value)
00659 
00660         if header not in self and header.lower() == 'content-type':
00661             ctype = 'text/plain'
00662         else:
00663             ctype = self.get(header)
00664         if not self.get_param(param, header=header):
00665             if not ctype:
00666                 ctype = _formatparam(param, value, requote)
00667             else:
00668                 ctype = SEMISPACE.join(
00669                     [ctype, _formatparam(param, value, requote)])
00670         else:
00671             ctype = ''
00672             for old_param, old_value in self.get_params(header=header,
00673                                                         unquote=requote):
00674                 append_param = ''
00675                 if old_param.lower() == param.lower():
00676                     append_param = _formatparam(param, value, requote)
00677                 else:
00678                     append_param = _formatparam(old_param, old_value, requote)
00679                 if not ctype:
00680                     ctype = append_param
00681                 else:
00682                     ctype = SEMISPACE.join([ctype, append_param])
00683         if ctype != self.get(header):
00684             del self[header]
00685             self[header] = ctype

Here is the call graph for this function:

Here is the caller graph for this function:

def email.message.Message.set_payload (   self,
  payload,
  charset = None 
) [inherited]
Set the payload to the given value.

Optional charset sets the message's default character set.  See
set_charset() for details.

Definition at line 288 of file message.py.

00288 
00289     def set_payload(self, payload, charset=None):
00290         """Set the payload to the given value.
00291 
00292         Optional charset sets the message's default character set.  See
00293         set_charset() for details.
00294         """
00295         self._payload = payload
00296         if charset is not None:
00297             self.set_charset(charset)

Here is the call graph for this function:

Here is the caller graph for this function:

def email.message.Message.set_type (   self,
  type,
  header = 'Content-Type',
  requote = True 
) [inherited]
Set the main type and subtype for the Content-Type header.

type must be a string in the form "maintype/subtype", otherwise a
ValueError is raised.

This method replaces the Content-Type header, keeping all the
parameters in place.  If requote is False, this leaves the existing
header's quoting as is.  Otherwise, the parameters will be quoted (the
default).

An alternative header can be specified in the header argument.  When
the Content-Type header is set, we'll always also add a MIME-Version
header.

Definition at line 708 of file message.py.

00708 
00709     def set_type(self, type, header='Content-Type', requote=True):
00710         """Set the main type and subtype for the Content-Type header.
00711 
00712         type must be a string in the form "maintype/subtype", otherwise a
00713         ValueError is raised.
00714 
00715         This method replaces the Content-Type header, keeping all the
00716         parameters in place.  If requote is False, this leaves the existing
00717         header's quoting as is.  Otherwise, the parameters will be quoted (the
00718         default).
00719 
00720         An alternative header can be specified in the header argument.  When
00721         the Content-Type header is set, we'll always also add a MIME-Version
00722         header.
00723         """
00724         # BAW: should we be strict?
00725         if not type.count('/') == 1:
00726             raise ValueError
00727         # Set the Content-Type, you get a MIME-Version
00728         if header.lower() == 'content-type':
00729             del self['mime-version']
00730             self['MIME-Version'] = '1.0'
00731         if header not in self:
00732             self[header] = type
00733             return
00734         params = self.get_params(header=header, unquote=requote)
00735         del self[header]
00736         self[header] = type
00737         # Skip the first param; it's the old type.
00738         for p, v in params[1:]:
00739             self.set_param(p, v, header, requote)

Here is the call graph for this function:

def email.message.Message.set_unixfrom (   self,
  unixfrom 
) [inherited]

Definition at line 178 of file message.py.

00178 
00179     def set_unixfrom(self, unixfrom):
00180         self._unixfrom = unixfrom

def email.message.Message.values (   self) [inherited]
Return a list of all the message's header values.

These will be sorted in the order they appeared in the original
message, or were added to the message, and may contain duplicates.
Any fields deleted and re-inserted are always appended to the header
list.

Definition at line 396 of file message.py.

00396 
00397     def values(self):
00398         """Return a list of all the message's header values.
00399 
00400         These will be sorted in the order they appeared in the original
00401         message, or were added to the message, and may contain duplicates.
00402         Any fields deleted and re-inserted are always appended to the header
00403         list.
00404         """
00405         return [_sanitize_header(k, v) for k, v in self._headers]

Here is the caller graph for this function:


Member Data Documentation

Definition at line 146 of file message.py.

Definition at line 145 of file message.py.

Definition at line 145 of file message.py.


The documentation for this class was generated from the following file: