| 590 | |
| 591 | if os.name == 'posix': |
| 592 | class file_wrapper: |
| 593 | # Here we override just enough to make a file |
| 594 | # look like a socket for the purposes of asyncore. |
| 595 | # The passed fd is automatically os.dup()'d |
| 596 | |
| 597 | def __init__(self, fd): |
| 598 | self.fd = os.dup(fd) |
| 599 | |
| 600 | def __del__(self): |
| 601 | if self.fd >= 0: |
| 602 | warnings.warn("unclosed file %r" % self, ResourceWarning, |
| 603 | source=self) |
| 604 | self.close() |
| 605 | |
| 606 | def recv(self, *args): |
| 607 | return os.read(self.fd, *args) |
| 608 | |
| 609 | def send(self, *args): |
| 610 | return os.write(self.fd, *args) |
| 611 | |
| 612 | def getsockopt(self, level, optname, buflen=None): |
| 613 | if (level == socket.SOL_SOCKET and |
| 614 | optname == socket.SO_ERROR and |
| 615 | not buflen): |
| 616 | return 0 |
| 617 | raise NotImplementedError("Only asyncore specific behaviour " |
| 618 | "implemented.") |
| 619 | |
| 620 | read = recv |
| 621 | write = send |
| 622 | |
| 623 | def close(self): |
| 624 | if self.fd < 0: |
| 625 | return |
| 626 | fd = self.fd |
| 627 | self.fd = -1 |
| 628 | os.close(fd) |
| 629 | |
| 630 | def fileno(self): |
| 631 | return self.fd |
| 632 | |
| 633 | class file_dispatcher(dispatcher): |
| 634 |
no outgoing calls
no test coverage detected
searching dependent graphs…