當前位置: 首頁>>代碼示例>>Python>>正文


Python session.packRequest_pty_req方法代碼示例

本文整理匯總了Python中twisted.conch.ssh.session.packRequest_pty_req方法的典型用法代碼示例。如果您正苦於以下問題:Python session.packRequest_pty_req方法的具體用法?Python session.packRequest_pty_req怎麽用?Python session.packRequest_pty_req使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在twisted.conch.ssh.session的用法示例。


在下文中一共展示了session.packRequest_pty_req方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_requestPty

# 需要導入模塊: from twisted.conch.ssh import session [as 別名]
# 或者: from twisted.conch.ssh.session import packRequest_pty_req [as 別名]
def test_requestPty(self):
        """
        When a client requests a PTY, the SSHSession object should make
        the request by getting an ISession adapter for the avatar, then
        calling getPty with the terminal type, the window size, and any modes
        the client gave us.
        """
        # 'bad' terminal type fails
        ret = self.session.requestReceived(
            b'pty_req',  session.packRequest_pty_req(
                b'bad', (1, 2, 3, 4), b''))
        self.assertFalse(ret)
        self.assertSessionIsStubSession()
        self.assertRequestRaisedRuntimeError()
        # 'good' terminal type succeeds
        self.assertTrue(self.session.requestReceived(b'pty_req',
            session.packRequest_pty_req(b'good', (1, 2, 3, 4), b'')))
        self.assertEqual(self.session.session.ptyRequest,
                (b'good', (1, 2, 3, 4), [])) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:21,代碼來源:test_session.py

示例2: test_requestPty

# 需要導入模塊: from twisted.conch.ssh import session [as 別名]
# 或者: from twisted.conch.ssh.session import packRequest_pty_req [as 別名]
def test_requestPty(self):
        """
        When a client requests a PTY, the SSHSession object should make
        the request by getting an ISession adapter for the avatar, then
        calling getPty with the terminal type, the window size, and any modes
        the client gave us.
        """
        # 'bad' terminal type fails
        ret = self.session.requestReceived(
            'pty_req',  session.packRequest_pty_req(
                'bad', (1, 2, 3, 4), ''))
        self.assertFalse(ret)
        self.assertSessionIsStubSession()
        self.assertRequestRaisedRuntimeError()
        # 'good' terminal type succeeds
        self.assertTrue(self.session.requestReceived('pty_req',
            session.packRequest_pty_req('good', (1, 2, 3, 4), '')))
        self.assertEquals(self.session.session.ptyRequest,
                ('good', (1, 2, 3, 4), [])) 
開發者ID:kuri65536,項目名稱:python-for-android,代碼行數:21,代碼來源:test_session.py

示例3: test_requestPtyReqGetsSession

# 需要導入模塊: from twisted.conch.ssh import session [as 別名]
# 或者: from twisted.conch.ssh.session import packRequest_pty_req [as 別名]
def test_requestPtyReqGetsSession(self):
        """
        If an ISession adapter isn't already present, request_pty_req should
        get one.
        """
        self.session.requestReceived(b'pty_req',
                                     session.packRequest_pty_req(
                b'term', (0, 0, 0, 0), b''))
        self.assertSessionProvidesISession() 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:11,代碼來源:test_session.py

示例4: test_packRequest_pty_req_old

# 需要導入模塊: from twisted.conch.ssh import session [as 別名]
# 或者: from twisted.conch.ssh.session import packRequest_pty_req [as 別名]
def test_packRequest_pty_req_old(self):
        """
        See test_parseRequest_pty_req for the payload format.
        """
        packed = session.packRequest_pty_req(b'xterm', (2, 1, 3, 4),
                                             b'\x05\x00\x00\x00\x06')

        self.assertEqual(packed,
                          common.NS(b'xterm') +
                          struct.pack('>4L', 1, 2, 3, 4) +
                          common.NS(struct.pack('>BL', 5, 6))) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:13,代碼來源:test_session.py

示例5: test_packRequest_pty_req

# 需要導入模塊: from twisted.conch.ssh import session [as 別名]
# 或者: from twisted.conch.ssh.session import packRequest_pty_req [as 別名]
def test_packRequest_pty_req(self):
        """
        See test_parseRequest_pty_req for the payload format.
        """
        packed = session.packRequest_pty_req(b'xterm', (2, 1, 3, 4),
                                             b'\x05\x00\x00\x00\x06')
        self.assertEqual(packed,
                          common.NS(b'xterm') +
                          struct.pack('>4L', 1, 2, 3, 4) +
                          common.NS(struct.pack('>BL', 5, 6))) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:12,代碼來源:test_session.py

示例6: channelOpen

# 需要導入模塊: from twisted.conch.ssh import session [as 別名]
# 或者: from twisted.conch.ssh.session import packRequest_pty_req [as 別名]
def channelOpen(self, foo):
        #global globalSession
        #globalSession = self
        # turn off local echo
        self.escapeMode = 1
        c = session.SSHSessionClient()
        if options['escape']:
            c.dataReceived = self.handleInput
        else:
            c.dataReceived = self.write
        c.connectionLost = self.sendEOF
        frame.callback = c.dataReceived
        frame.canvas.focus_force()
        if options['subsystem']:
            self.conn.sendRequest(self, b'subsystem', \
                common.NS(options['command']))
        elif options['command']:
            if options['tty']:
                term = os.environ.get('TERM', 'xterm')
                #winsz = fcntl.ioctl(fd, tty.TIOCGWINSZ, '12345678')
                winSize = (25,80,0,0) #struct.unpack('4H', winsz)
                ptyReqData = session.packRequest_pty_req(term, winSize, '')
                self.conn.sendRequest(self, b'pty-req', ptyReqData)
            self.conn.sendRequest(self, 'exec', \
                common.NS(options['command']))
        else:
            if not options['notty']:
                term = os.environ.get('TERM', 'xterm')
                #winsz = fcntl.ioctl(fd, tty.TIOCGWINSZ, '12345678')
                winSize = (25,80,0,0) #struct.unpack('4H', winsz)
                ptyReqData = session.packRequest_pty_req(term, winSize, '')
                self.conn.sendRequest(self, b'pty-req', ptyReqData)
            self.conn.sendRequest(self, b'shell', b'')
        self.conn.transport.transport.setTcpNoDelay(1) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:36,代碼來源:tkconch.py

示例7: channelOpen

# 需要導入模塊: from twisted.conch.ssh import session [as 別名]
# 或者: from twisted.conch.ssh.session import packRequest_pty_req [as 別名]
def channelOpen(self, ignored):
        """
        Create a pty by sending a pty-req to the server
        """
        term = 'xterm'
        winSize = (25, 80, 0, 0)
        ptyReqData = session.packRequest_pty_req(term, winSize, '')
        self.conn.sendRequest(self, 'pty-req', ptyReqData)
        command = self.conn.sendRequest(
            self, 'exec', NS(self._command), wantReply=True)
        command.addCallbacks(self._execSuccess, self._execFailure) 
開發者ID:ClusterHQ,項目名稱:flocker,代碼行數:13,代碼來源:_conch.py

示例8: channelOpen

# 需要導入模塊: from twisted.conch.ssh import session [as 別名]
# 或者: from twisted.conch.ssh.session import packRequest_pty_req [as 別名]
def channelOpen(self, ignored):
            data = session.packRequest_pty_req('conch-test-term', (24, 80, 0, 0), '')
            d = self.conn.sendRequest(self, 'pty-req', data, 1)
            d.addCallback(self._cbPtyReq)
            d.addErrback(self._ebPtyReq)
            log.msg('opened shell') 
開發者ID:kuri65536,項目名稱:python-for-android,代碼行數:8,代碼來源:test_ssh.py

示例9: channelOpen

# 需要導入模塊: from twisted.conch.ssh import session [as 別名]
# 或者: from twisted.conch.ssh.session import packRequest_pty_req [as 別名]
def channelOpen(self, data):
            term = session.packRequest_pty_req("vt102", (self.height, self.width, 0, 0), '')
            self.conn.sendRequest(self, 'pty-req', term)
            self.conn.sendRequest(self, 'shell', '')

            self._protocolInstance = self.protocolFactory(*self.protocolArgs, **self.protocolKwArgs)
            self._protocolInstance.factory = self
            self._protocolInstance.makeConnection(self) 
開發者ID:kuri65536,項目名稱:python-for-android,代碼行數:10,代碼來源:test_recvline.py

示例10: test_requestPtyReqGetsSession

# 需要導入模塊: from twisted.conch.ssh import session [as 別名]
# 或者: from twisted.conch.ssh.session import packRequest_pty_req [as 別名]
def test_requestPtyReqGetsSession(self):
        """
        If an ISession adapter isn't already present, request_pty_req should
        get one.
        """
        self.session.requestReceived('pty_req',
                                     session.packRequest_pty_req(
                'term', (0, 0, 0, 0), ''))
        self.assertSessionProvidesISession() 
開發者ID:kuri65536,項目名稱:python-for-android,代碼行數:11,代碼來源:test_session.py

示例11: test_packRequest_pty_req_old

# 需要導入模塊: from twisted.conch.ssh import session [as 別名]
# 或者: from twisted.conch.ssh.session import packRequest_pty_req [as 別名]
def test_packRequest_pty_req_old(self):
        """
        See test_parseRequest_pty_req for the payload format.
        """
        packed = session.packRequest_pty_req('xterm', (2, 1, 3, 4),
                                             '\x05\x00\x00\x00\x06')

        self.assertEquals(packed,
                          common.NS('xterm') + struct.pack('>4L', 1, 2, 3, 4) +
                          common.NS(struct.pack('>BL', 5, 6))) 
開發者ID:kuri65536,項目名稱:python-for-android,代碼行數:12,代碼來源:test_session.py

示例12: channelOpen

# 需要導入模塊: from twisted.conch.ssh import session [as 別名]
# 或者: from twisted.conch.ssh.session import packRequest_pty_req [as 別名]
def channelOpen(self, foo):
        log.msg('session %s open' % self.id)
        if options['agent']:
            d = self.conn.sendRequest(self, 'auth-agent-req@openssh.com', '', wantReply=1)
            d.addBoth(lambda x:log.msg(x))
        if options['noshell']: return
        if (options['command'] and options['tty']) or not options['notty']:
            _enterRawMode()
        c = session.SSHSessionClient()
        if options['escape'] and not options['notty']:
            self.escapeMode = 1
            c.dataReceived = self.handleInput
        else:
            c.dataReceived = self.write
        c.connectionLost = lambda x=None,s=self:s.sendEOF()
        self.stdio = stdio.StandardIO(c)
        fd = 0
        if options['subsystem']:
            self.conn.sendRequest(self, 'subsystem', \
                common.NS(options['command']))
        elif options['command']:
            if options['tty']:
                term = os.environ['TERM']
                winsz = fcntl.ioctl(fd, tty.TIOCGWINSZ, '12345678')
                winSize = struct.unpack('4H', winsz)
                ptyReqData = session.packRequest_pty_req(term, winSize, '')
                self.conn.sendRequest(self, 'pty-req', ptyReqData)
                signal.signal(signal.SIGWINCH, self._windowResized)
            self.conn.sendRequest(self, 'exec', \
                common.NS(options['command']))
        else:
            if not options['notty']:
                term = os.environ['TERM']
                winsz = fcntl.ioctl(fd, tty.TIOCGWINSZ, '12345678')
                winSize = struct.unpack('4H', winsz)
                ptyReqData = session.packRequest_pty_req(term, winSize, '')
                self.conn.sendRequest(self, 'pty-req', ptyReqData)
                signal.signal(signal.SIGWINCH, self._windowResized)
            self.conn.sendRequest(self, 'shell', '')
            #if hasattr(conn.transport, 'transport'):
            #    conn.transport.transport.setTcpNoDelay(1) 
開發者ID:kuri65536,項目名稱:python-for-android,代碼行數:43,代碼來源:conch.py

示例13: channelOpen

# 需要導入模塊: from twisted.conch.ssh import session [as 別名]
# 或者: from twisted.conch.ssh.session import packRequest_pty_req [as 別名]
def channelOpen(self, foo):
        #global globalSession
        #globalSession = self
        # turn off local echo
        self.escapeMode = 1
        c = session.SSHSessionClient()
        if options['escape']:
            c.dataReceived = self.handleInput
        else:
            c.dataReceived = self.write
        c.connectionLost = self.sendEOF
        frame.callback = c.dataReceived
        frame.canvas.focus_force()
        if options['subsystem']:
            self.conn.sendRequest(self, 'subsystem', \
                common.NS(options['command']))
        elif options['command']:
            if options['tty']:
                term = os.environ.get('TERM', 'xterm')
                #winsz = fcntl.ioctl(fd, tty.TIOCGWINSZ, '12345678')
                winSize = (25,80,0,0) #struct.unpack('4H', winsz)
                ptyReqData = session.packRequest_pty_req(term, winSize, '')
                self.conn.sendRequest(self, 'pty-req', ptyReqData)                
            self.conn.sendRequest(self, 'exec', \
                common.NS(options['command']))
        else:
            if not options['notty']:
                term = os.environ.get('TERM', 'xterm')
                #winsz = fcntl.ioctl(fd, tty.TIOCGWINSZ, '12345678')
                winSize = (25,80,0,0) #struct.unpack('4H', winsz)
                ptyReqData = session.packRequest_pty_req(term, winSize, '')
                self.conn.sendRequest(self, 'pty-req', ptyReqData)
            self.conn.sendRequest(self, 'shell', '')
        self.conn.transport.transport.setTcpNoDelay(1) 
開發者ID:kuri65536,項目名稱:python-for-android,代碼行數:36,代碼來源:tkconch.py

示例14: test_shell

# 需要導入模塊: from twisted.conch.ssh import session [as 別名]
# 或者: from twisted.conch.ssh.session import packRequest_pty_req [as 別名]
def test_shell(self):
        """
        L{SSHChannel.sendRequest} can open a shell with a I{pty-req} request,
        specifying a terminal type and window size.
        """
        channel = self._ourServerOurClientTest()

        data = session.packRequest_pty_req(
            b'conch-test-term', (24, 80, 0, 0), b'')
        def cbChannel(channel):
            self.channel = channel
            return channel.conn.sendRequest(channel, b'pty-req', data, 1)
        channel.addCallback(cbChannel)

        def cbPty(ignored):
            # The server-side object corresponding to our client side channel.
            session = self.realm.avatar.conn.channels[0].session
            self.assertIs(session.avatar, self.realm.avatar)
            self.assertEqual(session._terminalType, b'conch-test-term')
            self.assertEqual(session._windowSize, (24, 80, 0, 0))
            self.assertTrue(session.ptyReq)
            channel = self.channel
            return channel.conn.sendRequest(channel, b'shell', b'', 1)
        channel.addCallback(cbPty)

        def cbShell(ignored):
            self.channel.write(b'testing the shell!\x00')
            self.channel.conn.sendEOF(self.channel)
            return defer.gatherResults([
                    self.channel.onClose,
                    self.realm.avatar._testSession.onClose])
        channel.addCallback(cbShell)

        def cbExited(ignored):
            if self.channel.status != 0:
                log.msg(
                    'shell exit status was not 0: %i' % (self.channel.status,))
            self.assertEqual(
                b"".join(self.channel.received),
                b'testing the shell!\x00\r\n')
            self.assertTrue(self.channel.eofCalled)
            self.assertTrue(
                self.realm.avatar._testSession.eof)
        channel.addCallback(cbExited)
        return channel 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:47,代碼來源:test_ssh.py


注:本文中的twisted.conch.ssh.session.packRequest_pty_req方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。