MCPcopy Index your code
hub / github.com/RustPython/RustPython / file_wrapper

Class file_wrapper

Lib/test/support/asyncore.py:602–641  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

600
601if os.name == 'posix':
602 class file_wrapper:
603 # Here we override just enough to make a file
604 # look like a socket for the purposes of asyncore.
605 # The passed fd is automatically os.dup()'d
606
607 def __init__(self, fd):
608 self.fd = os.dup(fd)
609
610 def __del__(self):
611 if self.fd >= 0:
612 warnings.warn("unclosed file %r" % self, ResourceWarning,
613 source=self)
614 self.close()
615
616 def recv(self, *args):
617 return os.read(self.fd, *args)
618
619 def send(self, *args):
620 return os.write(self.fd, *args)
621
622 def getsockopt(self, level, optname, buflen=None):
623 if (level == socket.SOL_SOCKET and
624 optname == socket.SO_ERROR and
625 not buflen):
626 return 0
627 raise NotImplementedError("Only asyncore specific behaviour "
628 "implemented.")
629
630 read = recv
631 write = send
632
633 def close(self):
634 if self.fd < 0:
635 return
636 fd = self.fd
637 self.fd = -1
638 os.close(fd)
639
640 def fileno(self):
641 return self.fd
642
643 class file_dispatcher(dispatcher):
644

Callers 1

set_fileMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected