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 an
(self, param, value, header='Content-Type', requote=True,
charset=None, language='', replace=False)
| 743 | return failobj |
| 744 | |
| 745 | def set_param(self, param, value, header='Content-Type', requote=True, |
| 746 | charset=None, language='', replace=False): |
| 747 | """Set a parameter in the Content-Type header. |
| 748 | |
| 749 | If the parameter already exists in the header, its value will be |
| 750 | replaced with the new value. |
| 751 | |
| 752 | If header is Content-Type and has not yet been defined for this |
| 753 | message, it will be set to "text/plain" and the new parameter and |
| 754 | value will be appended as per RFC 2045. |
| 755 | |
| 756 | An alternate header can be specified in the header argument, and all |
| 757 | parameters will be quoted as necessary unless requote is False. |
| 758 | |
| 759 | If charset is specified, the parameter will be encoded according to RFC |
| 760 | 2231. Optional language specifies the RFC 2231 language, defaulting |
| 761 | to the empty string. Both charset and language should be strings. |
| 762 | """ |
| 763 | if not isinstance(value, tuple) and charset: |
| 764 | value = (charset, language, value) |
| 765 | |
| 766 | if header not in self and header.lower() == 'content-type': |
| 767 | ctype = 'text/plain' |
| 768 | else: |
| 769 | ctype = self.get(header) |
| 770 | if not self.get_param(param, header=header): |
| 771 | if not ctype: |
| 772 | ctype = _formatparam(param, value, requote) |
| 773 | else: |
| 774 | ctype = SEMISPACE.join( |
| 775 | [ctype, _formatparam(param, value, requote)]) |
| 776 | else: |
| 777 | ctype = '' |
| 778 | for old_param, old_value in self.get_params(header=header, |
| 779 | unquote=requote): |
| 780 | append_param = '' |
| 781 | if old_param.lower() == param.lower(): |
| 782 | append_param = _formatparam(param, value, requote) |
| 783 | else: |
| 784 | append_param = _formatparam(old_param, old_value, requote) |
| 785 | if not ctype: |
| 786 | ctype = append_param |
| 787 | else: |
| 788 | ctype = SEMISPACE.join([ctype, append_param]) |
| 789 | if ctype != self.get(header): |
| 790 | if replace: |
| 791 | self.replace_header(header, ctype) |
| 792 | else: |
| 793 | del self[header] |
| 794 | self[header] = ctype |
| 795 | |
| 796 | def del_param(self, param, header='content-type', requote=True): |
| 797 | """Remove the given parameter completely from the Content-Type header. |