示例#1
0
    def __init__ (self, timeout=30, maxread=2000, searchwindowsize=None, logfile=None, cwd=None, env=None,debug=False):

        spawn.__init__(self, None, timeout=timeout, maxread=maxread, searchwindowsize=searchwindowsize, logfile=logfile, cwd=cwd, env=env)

        self.name = '<pxtelnet>'

        #SUBTLE HACK ALERT! Note that the command that SETS the prompt uses a
        #slightly different string than the regular expression to match it. This
        #is because when you set the prompt the command will echo back, but we
        #don't want to match the echoed command. So if we make the set command
        #slightly different than the regex we eliminate the problem. To make the
        #set command different we add a backslash in front of $. The $ doesn't
        #need to be escaped, but it doesn't hurt and serves to make the set
        #prompt command different than the regex.

        # used to match the command-line prompt
        self.UNIQUE_PROMPT = "\[PEXPECT\][\$\#] "
        self.PROMPT = self.UNIQUE_PROMPT

        # used to set shell command-line prompt to UNIQUE_PROMPT.
        self.PROMPT_SET_SH = "PS1='[PEXPECT]\$ '"
        self.PROMPT_SET_CSH = "set prompt='[PEXPECT]\$ '"
        self.SSH_OPTS = ("-o'RSAAuthentication=no'"
                + " -o 'PubkeyAuthentication=no'")
# Disabling host key checking, makes you vulnerable to MITM attacks.
#                + " -o 'StrictHostKeyChecking=no'"
#                + " -o 'UserKnownHostsFile /dev/null' ")
        # Disabling X11 forwarding gets rid of the annoying SSH_ASKPASS from
        # displaying a GUI password dialog. I have not figured out how to
        # disable only SSH_ASKPASS without also disabling X11 forwarding.
        # Unsetting SSH_ASKPASS on the remote side doesn't disable it! Annoying!
        #self.SSH_OPTS = "-x -o'RSAAuthentication=no' -o 'PubkeyAuthentication=no'"
        self.force_password = False
        self.auto_prompt_reset = True
        self.DEBUG=debug
示例#2
0
    def __init__(self, fd, args=[], timeout=30, maxread=2000, searchwindowsize=None, logfile=None):

        """This takes a file descriptor (an int) or an object that support the
        fileno() method (returning an int). All Python file-like objects
        support fileno(). """

        # TODO: Add better handling of trying to use fdspawn in place of spawn
        # TODO: (overload to allow fdspawn to also handle commands as spawn does.

        if not isinstance(fd, int) and hasattr(fd, 'fileno'):
            fd = fd.fileno()

        if not isinstance(fd, int):
            raise ExceptionPexpect(
                "The fd argument is not an int. If this is a command string then maybe you want to use pexpect.spawn.")

        try:  # make sure fd is a valid file descriptor
            os.fstat(fd)
        except OSError:
            raise ExceptionPexpect("The fd argument is not a valid file descriptor.")

        self.args = None
        self.command = None
        spawn.__init__(self, None, args, timeout, maxread, searchwindowsize, logfile)
        self.child_fd = fd
        self.own_fd = False
        self.closed = False
        self.name = '<file descriptor %d>' % fd
    def __init__(self, fd, args=[], timeout=30, maxread=2000, searchwindowsize=None, logfile=None):

        """This takes a file descriptor (an int) or an object that support the
        fileno() method (returning an int). All Python file-like objects
        support fileno(). """

        # TODO: Add better handling of trying to use fdspawn in place of spawn
        # TODO: (overload to allow fdspawn to also handle commands as spawn does.

        if not isinstance(fd, int) and hasattr(fd, 'fileno'):
            fd = fd.fileno()

        if not isinstance(fd, int):
            raise ExceptionPexpect(
                "The fd argument is not an int. If this is a command string then maybe you want to use pexpect.spawn.")

        try:  # make sure fd is a valid file descriptor
            os.fstat(fd)
        except OSError:
            raise ExceptionPexpect("The fd argument is not a valid file descriptor.")

        self.args = None
        self.command = None
        spawn.__init__(self, None, args, timeout, maxread, searchwindowsize, logfile)
        self.child_fd = fd
        self.own_fd = False
        self.closed = False
        self.name = '<file descriptor %d>' % fd
示例#4
0
    def __init__(self,
                 timeout=30,
                 maxread=2000,
                 searchwindowsize=None,
                 logfile=None,
                 cwd=None,
                 env=None,
                 interpreter=None):

        spawn.__init__(self,
                       None,
                       timeout=timeout,
                       maxread=maxread,
                       searchwindowsize=searchwindowsize,
                       logfile=logfile,
                       cwd=cwd,
                       env=env)

        self.name = '<pxshell>'

        #SUBTLE HACK ALERT! Note that the command that SETS the prompt uses a
        #slightly different string than the regular expression to match it. This
        #is because when you set the prompt the command will echo back, but we
        #don't want to match the echoed command. So if we make the set command
        #slightly different than the regex we eliminate the problem. To make the
        #set command different we add a backslash in front of $. The $ doesn't
        #need to be escaped, but it doesn't hurt and serves to make the set
        #prompt command different than the regex.

        # prepare a basic interpreter
        self.interpreter = interpreter
        print("interpreter: " + str(self.interpreter))
示例#5
0
    def __init__(self,
                 command,
                 args=[],
                 timeout=30,
                 maxread=2000,
                 searchwindowsize=None,
                 logfile=None,
                 cwd=None,
                 env=None,
                 ignore_sighup=True,
                 echo=True):
        if len(inspect.getfullargspec(spawn.__init__)[0]) == 9:
            spawn.__init__(self, command, args, timeout, maxread,
                           searchwindowsize, logfile, cwd, env)
        else:
            spawn.__init__(self, command, args, timeout, maxread,
                           searchwindowsize, logfile, cwd, env, ignore_sighup,
                           echo)

        # used to match the command-line prompt
        self.UNIQUE_PROMPT_HEAD = "[PEXPECT]"
        self.UNIQUE_PROMPT = r"\[PEXPECT\][\$\#] "
        self.PROMPT = self.UNIQUE_PROMPT

        # used to set shell command-line prompt to UNIQUE_PROMPT.
        self.PROMPT_SET_SH = r"PS1='[PEXPECT]\$ '"
        self.PROMPT_SET_CSH = r"set prompt='[PEXPECT]\$ '"
        self.SSH_OPTS = ("-o'RSAAuthentication=no'" +
                         " -o 'PubkeyAuthentication=no'")

        self.set_unique_prompt()
 def __init__(self, command, args=[], timeout=30, maxread=900, searchwindowsize=None, logfile=None, cwd=None, 
              env=None, escapeCharacters=None, substitutionList=None, windowRows=24, windowColumns=80,
              loggerName=None):
     """Constructor"""
     spawn.__init__(self, command, args, timeout, maxread, searchwindowsize, logfile, cwd, env)
     self.loggerName = '{}.loggingSpawn'.format(loggerName)
     self.logger = logging.getLogger(self.loggerName)
     isinstance(self.logger, Slicklogger)
     self.logger.info(command)
     self.loggingBuffer = ''
示例#7
0
 def __init__(self, timeout=30, maxread=2000,
     searchwindowsize=None,logfile=None, cwd=None, env=None, echo=True):
     spawn.__init__(self, None, timeout=timeout, maxread=maxread,
             searchwindowsize=searchwindowsize, logfile=logfile, cwd=cwd,
             env=env, echo=echo)
     self.name = '<pxssh>'
     self.UNIQUE_PROMPT = "\[PEXPECT\][\$\#] "
     self.PROMPT = self.UNIQUE_PROMPT
     self.PROMPT_SET_SH = "PS1='[PEXPECT]\$ '"
     self.PROMPT_SET_CSH = "set prompt='[PEXPECT]\$ '"
     self.SSH_OPTS = ("-o'RSAAuthentication=no'"
             + " -o 'PubkeyAuthentication=no'")
示例#8
0
文件: conn.py 项目: Python3pkg/MONK
 def __init__(self, timeout=30, maxread=2000,
     searchwindowsize=None,logfile=None, cwd=None, env=None, echo=True):
     spawn.__init__(self, None, timeout=timeout, maxread=maxread,
             searchwindowsize=searchwindowsize, logfile=logfile, cwd=cwd,
             env=env, echo=echo)
     self.name = '<pxssh>'
     self.UNIQUE_PROMPT = "\[PEXPECT\][\$\#] "
     self.PROMPT = self.UNIQUE_PROMPT
     self.PROMPT_SET_SH = "PS1='[PEXPECT]\$ '"
     self.PROMPT_SET_CSH = "set prompt='[PEXPECT]\$ '"
     self.SSH_OPTS = ("-o'RSAAuthentication=no'"
             + " -o 'PubkeyAuthentication=no'")
示例#9
0
 def __init__(
     self,
     timeout=30,
     ignore_sighup=True,
     encoding="utf-8",
 ) -> None:
     """Ruckus SSH client constructor."""
     spawn.__init__(
         self,
         None,
         timeout=timeout,
         ignore_sighup=ignore_sighup,
         encoding=encoding,
     )
示例#10
0
    def __init__(self, command, setpgrp=False, timeout=30):
        """Initialise `spawn` class and private attributes.

        :param command: command to launch
        :type command: `str`
        :param setpgrp: set new process group for the spawned process (default:
            `False`)
        :type setpgrp: `bool`
        :param timeout: timeout on getting output from child's stdout/stderr
        :type timeout: `int`
        """
        spawn.__init__(self, command, args=[], timeout=timeout,
                       maxread=2000, searchwindowsize=None,
                       logfile=None, env=None)
        self.__output = ''
        self.__setpgrp = setpgrp
示例#11
0
    def __init__ (self, timeout=30, maxread=2000, searchwindowsize=None,
                    logfile=None, cwd=None, env=None, interpreter=None):

        spawn.__init__(self, None, timeout=timeout, maxread=maxread, searchwindowsize=searchwindowsize, logfile=logfile, cwd=cwd, env=env)

        self.name = '<pxshell>'

        #SUBTLE HACK ALERT! Note that the command that SETS the prompt uses a
        #slightly different string than the regular expression to match it. This
        #is because when you set the prompt the command will echo back, but we
        #don't want to match the echoed command. So if we make the set command
        #slightly different than the regex we eliminate the problem. To make the
        #set command different we add a backslash in front of $. The $ doesn't
        #need to be escaped, but it doesn't hurt and serves to make the set
        #prompt command different than the regex.

        # prepare a basic interpreter
        self.interpreter = interpreter
        print("interpreter: " + str(self.interpreter))
 def __init__(self,
              command,
              term,
              timeout=30,
              maxread=2000,
              searchwindowsize=None,
              logfile=None,
              cwd=None,
              env=None):
     assert isinstance(
         term, ANSI.term), 'pxtty should be passed a terminal instance'
     pexpect_spawn.__init__(self,
                            command,
                            timeout=timeout,
                            maxread=maxread,
                            searchwindowsize=searchwindowsize,
                            logfile=logfile,
                            cwd=cwd,
                            env=env)
     self.term = term
     self.logfiles_read.append(self.term)
示例#13
0
    def __init__(self, command, setpgrp=False, timeout=30):
        """Initialise `spawn` class and private attributes.

        :param command: command to launch
        :type command: `str`
        :param setpgrp: set new process group for the spawned process (default:
            `False`)
        :type setpgrp: `bool`
        :param timeout: timeout on getting output from child's stdout/stderr
        :type timeout: `int`
        """
        spawn.__init__(self,
                       command,
                       args=[],
                       timeout=timeout,
                       maxread=2000,
                       searchwindowsize=None,
                       logfile=None,
                       env=None)
        self.__output = ''
        self.__setpgrp = setpgrp
示例#14
0
 def __init__(self,timeout=10):
     self.name='<sftp>'
     self.PROMPT="sftp>"
     self.logined=False
     self.err_str=""
     spawn.__init__(self, None, timeout=timeout)