| 158 | |
| 159 | @property |
| 160 | def charset(self): |
| 161 | if self._charset is not None: |
| 162 | return self._charset |
| 163 | # The Content-Type header may not yet be set, because the charset is |
| 164 | # being inserted *into* it. |
| 165 | if content_type := self.headers.get("Content-Type"): |
| 166 | if matched := _charset_from_content_type_re.search(content_type): |
| 167 | # Extract the charset and strip its double quotes. |
| 168 | # Note that having parsed it from the Content-Type, we don't |
| 169 | # store it back into the _charset for later intentionally, to |
| 170 | # allow for the Content-Type to be switched again later. |
| 171 | return matched["charset"].replace('"', "") |
| 172 | return settings.DEFAULT_CHARSET |
| 173 | |
| 174 | @charset.setter |
| 175 | def charset(self, value): |