Ignore:
Timestamp:
Mar 19, 2014, 11:31:01 PM (11 years ago)
Author:
dmik
Message:

python: Merge vendor 2.7.6 to trunk.

Location:
python/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • python/trunk

  • python/trunk/Lib/email/message.py

    r2 r391  
    4040    """Convenience function to format and return a key=value pair.
    4141
    42     This will quote the value if needed or if quote is true.
     42    This will quote the value if needed or if quote is true.  If value is a
     43    three tuple (charset, language, value), it will be encoded according
     44    to RFC2231 rules.
    4345    """
    4446    if value is not None and len(value) > 0:
     
    6466        s = s[1:]
    6567        end = s.find(';')
    66         while end > 0 and s.count('"', 0, end) % 2:
     68        while end > 0 and (s.count('"', 0, end) - s.count('\\"', 0, end)) % 2:
    6769            end = s.find(';', end + 1)
    6870        if end < 0:
     
    100102
    101103    Message objects implement part of the `mapping' interface, which assumes
    102     there is exactly one occurrance of the header per message.  Some headers
     104    there is exactly one occurrence of the header per message.  Some headers
    103105    do in fact appear multiple times (e.g. Received) and for those headers,
    104106    you must use the explicit API to set or get all the headers.  Not all of
     
    252254        # Charset constructor?
    253255        self._charset = charset
    254         if not self.has_key('MIME-Version'):
     256        if 'MIME-Version' not in self:
    255257            self.add_header('MIME-Version', '1.0')
    256         if not self.has_key('Content-Type'):
     258        if 'Content-Type' not in self:
    257259            self.add_header('Content-Type', 'text/plain',
    258260                            charset=charset.get_output_charset())
    259261        else:
    260262            self.set_param('charset', charset.get_output_charset())
     263        if isinstance(self._payload, unicode):
     264            self._payload = self._payload.encode(charset.output_charset)
    261265        if str(charset) != charset.get_output_charset():
    262266            self._payload = charset.body_encode(self._payload)
    263         if not self.has_key('Content-Transfer-Encoding'):
     267        if 'Content-Transfer-Encoding' not in self:
    264268            cte = charset.get_body_encoding()
    265269            try:
     
    287291
    288292        Note that if the header appeared multiple times, exactly which
    289         occurrance gets returned is undefined.  Use get_all() to get all
     293        occurrence gets returned is undefined.  Use get_all() to get all
    290294        the values matching a header field name.
    291295        """
     
    390394        additional parameters for the header field, with underscores converted
    391395        to dashes.  Normally the parameter will be added as key="value" unless
    392         value is None, in which case only the key will be added.
     396        value is None, in which case only the key will be added.  If a
     397        parameter value contains non-ASCII characters it must be specified as a
     398        three-tuple of (charset, language, value), in which case it will be
     399        encoded according to RFC2231 rules.
    393400
    394401        Example:
     
    554561        to False.
    555562        """
    556         if not self.has_key(header):
     563        if header not in self:
    557564            return failobj
    558565        for k, v in self._get_params_preserve(failobj, header):
     
    585592            value = (charset, language, value)
    586593
    587         if not self.has_key(header) and header.lower() == 'content-type':
     594        if header not in self and header.lower() == 'content-type':
    588595            ctype = 'text/plain'
    589596        else:
     
    620627        header.
    621628        """
    622         if not self.has_key(header):
     629        if header not in self:
    623630            return
    624631        new_ctype = ''
     
    656663            del self['mime-version']
    657664            self['MIME-Version'] = '1.0'
    658         if not self.has_key(header):
     665        if header not in self:
    659666            self[header] = type
    660667            return
Note: See TracChangeset for help on using the changeset viewer.