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 th
(self, type, header='Content-Type', requote=True)
| 816 | self[header] = new_ctype |
| 817 | |
| 818 | def set_type(self, type, header='Content-Type', requote=True): |
| 819 | """Set the main type and subtype for the Content-Type header. |
| 820 | |
| 821 | type must be a string in the form "maintype/subtype", otherwise a |
| 822 | ValueError is raised. |
| 823 | |
| 824 | This method replaces the Content-Type header, keeping all the |
| 825 | parameters in place. If requote is False, this leaves the existing |
| 826 | header's quoting as is. Otherwise, the parameters will be quoted (the |
| 827 | default). |
| 828 | |
| 829 | An alternative header can be specified in the header argument. When |
| 830 | the Content-Type header is set, we'll always also add a MIME-Version |
| 831 | header. |
| 832 | """ |
| 833 | # BAW: should we be strict? |
| 834 | if not type.count('/') == 1: |
| 835 | raise ValueError |
| 836 | # Set the Content-Type, you get a MIME-Version |
| 837 | if header.lower() == 'content-type': |
| 838 | del self['mime-version'] |
| 839 | self['MIME-Version'] = '1.0' |
| 840 | if header not in self: |
| 841 | self[header] = type |
| 842 | return |
| 843 | params = self.get_params(header=header, unquote=requote) |
| 844 | del self[header] |
| 845 | self[header] = type |
| 846 | # Skip the first param; it's the old type. |
| 847 | for p, v in params[1:]: |
| 848 | self.set_param(p, v, header, requote) |
| 849 | |
| 850 | def get_filename(self, failobj=None): |
| 851 | """Return the filename associated with the payload if present. |