(self, arg)
| 419 | self.headers_sent = True |
| 420 | |
| 421 | def write(self, arg): |
| 422 | self.send_headers() |
| 423 | if not isinstance(arg, bytes): |
| 424 | raise TypeError('%r is not a byte' % arg) |
| 425 | arglen = len(arg) |
| 426 | tosend = arglen |
| 427 | if self.response_length is not None: |
| 428 | if self.sent >= self.response_length: |
| 429 | # Never write more than self.response_length bytes |
| 430 | return |
| 431 | |
| 432 | tosend = min(self.response_length - self.sent, tosend) |
| 433 | if tosend < arglen: |
| 434 | arg = arg[:tosend] |
| 435 | |
| 436 | # Sending an empty chunk signals the end of the |
| 437 | # response and prematurely closes the response |
| 438 | if self.chunked and tosend == 0: |
| 439 | return |
| 440 | |
| 441 | self.sent += tosend |
| 442 | util.write(self.sock, arg, self.chunked) |
| 443 | |
| 444 | def can_sendfile(self): |
| 445 | return self.cfg.sendfile is not False |
no test coverage detected