def wait_readwrite(fileno, timeout=-1, timeout_exc=_socket.timeout('timed out')): evt = core.readwrite_event(fileno, _wait_helper, timeout, (getcurrent(), timeout_exc)) try: switch_result = get_hub().switch() assert evt is switch_result, 'Invalid switch into wait_readwrite(): %r' % (switch_result, ) finally: evt.cancel()
def wait_write(fileno, timeout=-1, timeout_exc=_socket.timeout('timed out')): evt = core.write_event(fileno, _wait_helper, timeout, (getcurrent(), timeout_exc)) try: switch_result = get_hub().switch() assert evt is switch_result, 'Invalid switch into wait_write(): %r' % ( switch_result, ) finally: evt.cancel()
def _sendfile_use_sendfile(self, file, offset=0, count=None): self._check_sendfile_params(file, offset, count) sockno = self.fileno() try: fileno = file.fileno() except (AttributeError, io.UnsupportedOperation) as err: raise _GiveupOnSendfile(err) try: fsize = os.fstat(fileno).st_size except OSError as err: raise _GiveupOnSendfile(err) if not fsize: return 0 blocksize = fsize if not count else count timeout = self.gettimeout() if timeout == 0: raise ValueError('non-blocking sockets are not supported') if hasattr(selectors, 'PollSelector'): selector = selectors.PollSelector() else: selector = selectors.SelectSelector() selector.register(sockno, selectors.EVENT_WRITE) total_sent = 0 selector_select = selector.select os_sendfile = os.sendfile try: while True: if timeout and not selector_select(timeout): raise _socket.timeout('timed out') if count: blocksize = count - total_sent if blocksize <= 0: break try: sent = os_sendfile(sockno, fileno, offset, blocksize) except BlockingIOError: if not timeout: selector_select() continue except OSError as err: if total_sent == 0: raise _GiveupOnSendfile(err) raise err from None else: if sent == 0: break offset += sent total_sent += sent return total_sent finally: if total_sent > 0 and hasattr(file, 'seek'): file.seek(offset)
def ssh_client(hostname, username, password): """ SSH client with a workaround for using IPv4 addresses """ ssh = paramiko.SSHClient() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh.connect(hostname, username=username, password=password, timeout=60) return ssh if ssh.get_transport() is None: # An SSH Transport attaches to a stream (usually a socket), negotiates an encrypted session, # authenticates, and then creates stream tunnels, called channels, across the session. # If connection is not established, returns None. raise timeout("No pingable IP found")
def _sendfile_use_sendfile(self, file, offset=0, count=None): self._check_sendfile_params(file, offset, count) sockno = self.fileno() try: fileno = file.fileno() except (AttributeError, io.UnsupportedOperation) as err: raise _GiveupOnSendfile(err) # not a regular file try: fsize = os.fstat(fileno).st_size except OSError as err: raise _GiveupOnSendfile(err) # not a regular file if not fsize: return 0 # empty file # Truncate to 1GiB to avoid OverflowError, see bpo-38319. blocksize = min(count or fsize, 2 ** 30) timeout = self.gettimeout() if timeout == 0: raise ValueError("non-blocking sockets are not supported") # poll/select have the advantage of not requiring any # extra file descriptor, contrarily to epoll/kqueue # (also, they require a single syscall). if hasattr(selectors, 'PollSelector'): selector = selectors.PollSelector() else: selector = selectors.SelectSelector() selector.register(sockno, selectors.EVENT_WRITE) total_sent = 0 # localize variable access to minimize overhead selector_select = selector.select os_sendfile = os.sendfile try: while True: if timeout and not selector_select(timeout): raise _socket.timeout('timed out') if count: blocksize = count - total_sent if blocksize <= 0: break try: sent = os_sendfile(sockno, fileno, offset, blocksize) except BlockingIOError: if not timeout: # Block until the socket is ready to send some # data; avoids hogging CPU resources. selector_select() continue except OSError as err: if total_sent == 0: # We can get here for different reasons, the main # one being 'file' is not a regular mmap(2)-like # file, in which case we'll fall back on using # plain send(). raise _GiveupOnSendfile(err) raise err from None else: if sent == 0: break # EOF offset += sent total_sent += sent return total_sent finally: if total_sent > 0 and hasattr(file, 'seek'): file.seek(offset)
def _sendfile_use_sendfile(self, file, offset=0, count=None): self._check_sendfile_params(file, offset, count) sockno = self.fileno() try: fileno = file.fileno() except (AttributeError, io.UnsupportedOperation) as err: raise _GiveupOnSendfile(err) # not a regular file try: fsize = os.fstat(fileno).st_size except OSError as err: raise _GiveupOnSendfile(err) # not a regular file if not fsize: return 0 # empty file blocksize = fsize if not count else count timeout = self.gettimeout() if timeout == 0: raise ValueError("non-blocking sockets are not supported") # poll/select have the advantage of not requiring any # extra file descriptor, contrarily to epoll/kqueue # (also, they require a single syscall). if hasattr(selectors, 'PollSelector'): selector = selectors.PollSelector() else: selector = selectors.SelectSelector() selector.register(sockno, selectors.EVENT_WRITE) total_sent = 0 # localize variable access to minimize overhead selector_select = selector.select os_sendfile = os.sendfile try: while True: if timeout and not selector_select(timeout): raise _socket.timeout('timed out') if count: blocksize = count - total_sent if blocksize <= 0: break try: sent = os_sendfile(sockno, fileno, offset, blocksize) except BlockingIOError: if not timeout: # Block until the socket is ready to send some # data; avoids hogging CPU resources. selector_select() continue except OSError as err: if total_sent == 0: # We can get here for different reasons, the main # one being 'file' is not a regular mmap(2)-like # file, in which case we'll fall back on using # plain send(). raise _GiveupOnSendfile(err) raise err from None else: if sent == 0: break # EOF offset += sent total_sent += sent return total_sent finally: if total_sent > 0 and hasattr(file, 'seek'): file.seek(offset)
if sbginp: #If we are in the user-interactive mode, ask for a valid option for the subgroup output to continue. while testsbg: sbgopt=raw_input("\nDo you want to generate a multifasta file with the sequences analyzed?\nWrite 'Y' to make it or 'N' to continue): ") if sbgopt.lower() in yesopt: print '\nDONE:' subgroupseq(filename,int(minlen),int(maxlen),currTime,wrng) print '- '*29+'-' testsbg=0 elif sbgopt.lower() in noopt: testsbg=0 else: print "Bad option, try again." else: #If we are in the command-line mode and the parameter for the subgroup output is given, do the analysis. subgroupseq(filename,int(minlen),int(maxlen),currTime,wrng) print '- '*34+'-' timeout(1) #=========================================================================# if testps: if psinp: #If we are in the user-interactive mode, ask for a valid option for the pseudosequence output to continue. while testps: psopt=raw_input("\nDo you want to generate a pseudosequence?\nWrite 'Y' to build it or 'N' to continue): ") if psopt.lower() in yesopt: pschk=1 while pschk: nrep=raw_input("Please, give the NUMBER of repeats of the ambiguous\nresidue to concatenate the sequences: ") try: if int(nrep)>=0: print '\nDONE:' pseudoseq(filename,int(nrep),int(minlen),int(maxlen),currTime,wrng) #Correct number of repetitions, continue. print '- '*29+'-' pschk=0