本文整理汇总了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), []))
示例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), []))
示例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()
示例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)))
示例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)))
示例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)
示例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)
示例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')
示例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)
示例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()
示例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)))
示例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)
示例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)
示例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