MCPcopy
hub / github.com/aio-libs/aiohttp / __init__

Method __init__

aiohttp/web_reqrep.py:776–821  ·  view source on GitHub ↗
(self, *, body=None, status=200,
                 reason=None, text=None, headers=None, content_type=None,
                 charset=None)

Source from the content-addressed store, hash-verified

774class 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):

Callers

nothing calls this directly

Calls 3

encodeMethod · 0.80
__init__Method · 0.45
set_tcp_corkMethod · 0.45

Tested by

no test coverage detected