MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / set_param

Method set_param

tools/python-3.11.9-amd64/Lib/email/message.py:729–778  ·  view source on GitHub ↗

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 parame

(self, param, value, header='Content-Type', requote=True,
                  charset=None, language='', replace=False)

Source from the content-addressed store, hash-verified

727 return failobj
728
729 def set_param(self, param, value, header='Content-Type', requote=True,
730 charset=None, language='', replace=False):
731 """Set a parameter in the Content-Type header.
732
733 If the parameter already exists in the header, its value will be
734 replaced with the new value.
735
736 If header is Content-Type and has not yet been defined for this
737 message, it will be set to "text/plain" and the new parameter and
738 value will be appended as per RFC 2045.
739
740 An alternate header can be specified in the header argument, and all
741 parameters will be quoted as necessary unless requote is False.
742
743 If charset is specified, the parameter will be encoded according to RFC
744 2231. Optional language specifies the RFC 2231 language, defaulting
745 to the empty string. Both charset and language should be strings.
746 """
747 if not isinstance(value, tuple) and charset:
748 value = (charset, language, value)
749
750 if header not in self and header.lower() == 'content-type':
751 ctype = 'text/plain'
752 else:
753 ctype = self.get(header)
754 if not self.get_param(param, header=header):
755 if not ctype:
756 ctype = _formatparam(param, value, requote)
757 else:
758 ctype = SEMISPACE.join(
759 [ctype, _formatparam(param, value, requote)])
760 else:
761 ctype = ''
762 for old_param, old_value in self.get_params(header=header,
763 unquote=requote):
764 append_param = ''
765 if old_param.lower() == param.lower():
766 append_param = _formatparam(param, value, requote)
767 else:
768 append_param = _formatparam(old_param, old_value, requote)
769 if not ctype:
770 ctype = append_param
771 else:
772 ctype = SEMISPACE.join([ctype, append_param])
773 if ctype != self.get(header):
774 if replace:
775 self.replace_header(header, ctype)
776 else:
777 del self[header]
778 self[header] = ctype
779
780 def del_param(self, param, header='content-type', requote=True):
781 """Remove the given parameter completely from the Content-Type header.

Callers 5

set_charsetMethod · 0.95
set_typeMethod · 0.95
_make_multipartMethod · 0.80
_finalize_setFunction · 0.80
set_text_contentFunction · 0.80

Calls 7

getMethod · 0.95
get_paramMethod · 0.95
get_paramsMethod · 0.95
replace_headerMethod · 0.95
_formatparamFunction · 0.70
lowerMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected