(self, *, body=None, status=200,
reason=None, text=None, headers=None, content_type=None,
charset=None)
| 774 | class Response(StreamResponse): |
| 775 | |
| 776 | def __init__(self, *, body=None, status=200, |
| 777 | reason=None, text=None, headers=None, content_type=None, |
| 778 | charset=None): |
| 779 | super().__init__(status=status, reason=reason, headers=headers) |
| 780 | self.set_tcp_cork(True) |
| 781 | |
| 782 | if body is not None and text is not None: |
| 783 | raise ValueError("body and text are not allowed together.") |
| 784 | |
| 785 | if text is not None: |
| 786 | if hdrs.CONTENT_TYPE not in self.headers: |
| 787 | # fast path for filling headers |
| 788 | if not isinstance(text, str): |
| 789 | raise TypeError('text argument must be str (%r)' % |
| 790 | type(text)) |
| 791 | if content_type is None: |
| 792 | content_type = 'text/plain' |
| 793 | elif ";" in content_type: |
| 794 | raise ValueError('charset must not be in content_type ' |
| 795 | 'argument') |
| 796 | charset = charset or 'utf-8' |
| 797 | self.headers[hdrs.CONTENT_TYPE] = ( |
| 798 | content_type + '; charset=%s' % charset) |
| 799 | self._content_type = content_type |
| 800 | self._content_dict = {'charset': charset} |
| 801 | self.body = text.encode(charset) |
| 802 | else: |
| 803 | self.text = text |
| 804 | if content_type or charset: |
| 805 | raise ValueError("Passing both Content-Type header and " |
| 806 | "content_type or charset params " |
| 807 | "is forbidden") |
| 808 | else: |
| 809 | if hdrs.CONTENT_TYPE in self.headers: |
| 810 | if content_type or charset: |
| 811 | raise ValueError("Passing both Content-Type header and " |
| 812 | "content_type or charset params " |
| 813 | "is forbidden") |
| 814 | if content_type: |
| 815 | self.content_type = content_type |
| 816 | if charset: |
| 817 | self.charset = charset |
| 818 | if body is not None: |
| 819 | self.body = body |
| 820 | else: |
| 821 | self.body = None |
| 822 | |
| 823 | @property |
| 824 | def body(self): |
nothing calls this directly
no test coverage detected