예제 #1
0
파일: posix.py 프로젝트: melund/winpexpect
 def write(self, buf):
     if not isinstance(buf, bytes):
         raise TypeError('Expecting raw bytes not unicode')
     if self.timeout is not None:
         endtime = time.time() + self.timeout
     byteswritten = 0
     buf = compat.buffer(buf)
     while True:
         try:
             nbytes = os.write(self.fd, buf[byteswritten:])
             assert nbytes != 0
             byteswritten += nbytes
         except OSError as e:
             if e.errno == errno.EINTR:
                 continue
             elif e.errno != errno.EAGAIN:
                 raise
         if byteswritten == len(buf):
             break
         if self.timeout is None:
             timeleft = None
         else:
             timeleft = endtime - time.time()
             if timeleft < 0:
                 raise TIMEOUT('Timeout writing to fd')
         try:
             select.select([], [self.fd], [], timeleft)
         except select.error as e:
             if e[0] != errno.EINTR:
                 raise
     return byteswritten
예제 #2
0
파일: posix.py 프로젝트: melund/winpexpect
 def write(self, buf):
     if not isinstance(buf, bytes):
         raise TypeError('Expecting raw bytes not unicode')
     if self.timeout is not None:
         endtime = time.time() + self.timeout
     byteswritten = 0
     buf = compat.buffer(buf)
     while True:
         try:
             nbytes = os.write(self.fd, buf[byteswritten:])
             assert nbytes != 0
             byteswritten += nbytes
         except OSError as e:
             if e.errno == errno.EINTR:
                 continue
             elif e.errno != errno.EAGAIN:
                 raise
         if byteswritten == len(buf):
             break
         if self.timeout is None:
             timeleft = None
         else:
             timeleft = endtime - time.time()
             if timeleft < 0:
                 raise TIMEOUT('Timeout writing to fd')
         try:
             select.select([], [self.fd], [], timeleft)
         except select.error as e:
             if e[0] != errno.EINTR:
                 raise
     return byteswritten
예제 #3
0
 def write(self, buf):
     if self.timeout is None:
         timeout = None
     else:
         timeout = Timeout(self.timeout)
         timeout.start()
     buf = compat.buffer(buf)
     byteswritten = 0
     try:
         while byteswritten != len(buf):
             nbytes = fd.write(self.fd, buf[byteswritten:])
             assert nbytes != 0
             byteswritten += nbytes
     except Timeout as e:
         if e is not timeout:
             raise
         raise TIMEOUT('Timeout writing to fd')
     else:
         if timeout is not None:
             timeout.cancel()
     return len(buf)