def setResponseCode(self, code, message=None):
        """
        Set the HTTP status response code, but takes care that this is called
        before any data is written.
        """
        assert not self.written, "Response code cannot be set after data has been written: %s." % "@@@@".join(self.written)
        self.responseCode = code
        self.responseMessage = message

        Set the HTTP status response code, but takes care that this is called
        before any data is written.
        
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/requesthelper.py