Day20 django/http/response.py HttpResponseBase
class HttpResponseBase(------------): @property def reason_phrase(self): if self._reason_phrase is not None: return self._reason_phrase # Leave self._reason_phrase unset in order to use the default # reason phrase for status code. return responses.get(self.status_code, 'Unknown Status Code')
@propatyとは値を変更することはできないが、使うこと(読み取ること)はできるようにするものらしい。
if self._reason_phraseがあれば、その値を返す
そのままであれば、httpのresponseからstatus_codeをgetしてstatus_codeと 'Unknown Status Code'を返す。
@reason_phrase.setter def reason_phrase(self, value): self._reason_phrase = value
新たな値を設定したいときにその手続きが行われる関数。上記のpropatyデコレータとセットで使用する。
@property def charset(self): if self._charset is not None: return self._charset content_type = self.get('Content-Type', '') matched = _charset_from_content_type_re.search(content_type) if matched: # Extract the charset and strip its double quotes return matched['charset'].replace('"', '') return settings.DEFAULT_CHARSET
・charsetが存在したら、charseインスタンスを返す
content_typeはContet-Typeをとって代入する
machedにはcharset_from_content__のsearchで上記のcontent_typeを投入
もしmatchedしたらmatchedの'charset'の部分の""を''で置き換える。
そして何にも当てはまらなかったらdefault_charsetを返す。