Changeset 391 for python/trunk/Lib/email/message.py
- Timestamp:
- Mar 19, 2014, 11:31:01 PM (11 years ago)
- Location:
- python/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
python/trunk
-
Property svn:mergeinfo
set to
/python/vendor/Python-2.7.6 merged eligible /python/vendor/current merged eligible
-
Property svn:mergeinfo
set to
-
python/trunk/Lib/email/message.py
r2 r391 40 40 """Convenience function to format and return a key=value pair. 41 41 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. 43 45 """ 44 46 if value is not None and len(value) > 0: … … 64 66 s = s[1:] 65 67 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: 67 69 end = s.find(';', end + 1) 68 70 if end < 0: … … 100 102 101 103 Message objects implement part of the `mapping' interface, which assumes 102 there is exactly one occurr ance of the header per message. Some headers104 there is exactly one occurrence of the header per message. Some headers 103 105 do in fact appear multiple times (e.g. Received) and for those headers, 104 106 you must use the explicit API to set or get all the headers. Not all of … … 252 254 # Charset constructor? 253 255 self._charset = charset 254 if not self.has_key('MIME-Version'):256 if 'MIME-Version' not in self: 255 257 self.add_header('MIME-Version', '1.0') 256 if not self.has_key('Content-Type'):258 if 'Content-Type' not in self: 257 259 self.add_header('Content-Type', 'text/plain', 258 260 charset=charset.get_output_charset()) 259 261 else: 260 262 self.set_param('charset', charset.get_output_charset()) 263 if isinstance(self._payload, unicode): 264 self._payload = self._payload.encode(charset.output_charset) 261 265 if str(charset) != charset.get_output_charset(): 262 266 self._payload = charset.body_encode(self._payload) 263 if not self.has_key('Content-Transfer-Encoding'):267 if 'Content-Transfer-Encoding' not in self: 264 268 cte = charset.get_body_encoding() 265 269 try: … … 287 291 288 292 Note that if the header appeared multiple times, exactly which 289 occurr ance gets returned is undefined. Use get_all() to get all293 occurrence gets returned is undefined. Use get_all() to get all 290 294 the values matching a header field name. 291 295 """ … … 390 394 additional parameters for the header field, with underscores converted 391 395 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. 393 400 394 401 Example: … … 554 561 to False. 555 562 """ 556 if not self.has_key(header):563 if header not in self: 557 564 return failobj 558 565 for k, v in self._get_params_preserve(failobj, header): … … 585 592 value = (charset, language, value) 586 593 587 if not self.has_key(header)and header.lower() == 'content-type':594 if header not in self and header.lower() == 'content-type': 588 595 ctype = 'text/plain' 589 596 else: … … 620 627 header. 621 628 """ 622 if not self.has_key(header):629 if header not in self: 623 630 return 624 631 new_ctype = '' … … 656 663 del self['mime-version'] 657 664 self['MIME-Version'] = '1.0' 658 if not self.has_key(header):665 if header not in self: 659 666 self[header] = type 660 667 return
Note:
See TracChangeset
for help on using the changeset viewer.