当前位置: 首页>>代码示例>>Python>>正文


Python session.SSHSession方法代码示例

本文整理汇总了Python中twisted.conch.ssh.session.SSHSession方法的典型用法代码示例。如果您正苦于以下问题:Python session.SSHSession方法的具体用法?Python session.SSHSession怎么用?Python session.SSHSession使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在twisted.conch.ssh.session的用法示例。


在下文中一共展示了session.SSHSession方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from twisted.conch.ssh import session [as 别名]
# 或者: from twisted.conch.ssh.session import SSHSession [as 别名]
def __init__(self, username):
        ConchUser.__init__(self)
        self.username = username
        self.pwdData = pwd.getpwnam(self.username)
        l = [self.pwdData[3]]
        for groupname, password, gid, userlist in grp.getgrall():
            if username in userlist:
                l.append(gid)
        self.otherGroups = l
        self.listeners = {}  # Dict mapping (interface, port) -> listener
        self.channelLookup.update(
                {b"session": session.SSHSession,
                 b"direct-tcpip": forwarding.openConnectForwardingClient})

        self.subsystemLookup.update(
                {b"sftp": filetransfer.FileTransferServer}) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:18,代码来源:unix.py

示例2: test_sessionClose

# 需要导入模块: from twisted.conch.ssh import session [as 别名]
# 或者: from twisted.conch.ssh.session import SSHSession [as 别名]
def test_sessionClose(self):
        """
        Closing a session should notify an SFTP subsystem launched by that
        session.
        """
        # make a session
        testSession = session.SSHSession(conn=FakeConn(), avatar=self.avatar)

        # start an SFTP subsystem on the session
        testSession.request_subsystem(common.NS(b'sftp'))
        sftpServer = testSession.client.transport.proto

        # intercept connectionLost so we can check that it's called
        self.interceptConnectionLost(sftpServer)

        # close session
        testSession.closeReceived()

        self.assertSFTPConnectionLost() 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:21,代码来源:test_filetransfer.py

示例3: test_lookupSubsystemDoesNotNeedISession

# 需要导入模块: from twisted.conch.ssh import session [as 别名]
# 或者: from twisted.conch.ssh.session import SSHSession [as 别名]
def test_lookupSubsystemDoesNotNeedISession(self):
        """
        Previously, if one only wanted to implement a subsystem, an ISession
        adapter wasn't needed because subsystems were looked up using the
        lookupSubsystem method on the avatar.
        """
        s = session.SSHSession(avatar=SubsystemOnlyAvatar(),
                               conn=StubConnection())
        ret = s.request_subsystem(
            common.NS(b'subsystem') + b'data')
        self.assertTrue(ret)
        self.assertIsNotNone(s.client)
        self.assertIsNone(s.conn.closes.get(s))
        s.eofReceived()
        self.assertTrue(s.conn.closes.get(s))
        # these should not raise errors
        s.loseConnection()
        s.closed() 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:20,代码来源:test_session.py

示例4: test_requestShell

# 需要导入模块: from twisted.conch.ssh import session [as 别名]
# 或者: from twisted.conch.ssh.session import SSHSession [as 别名]
def test_requestShell(self):
        """
        When a client requests a shell, the SSHSession object should get
        the shell by getting an ISession adapter for the avatar, then
        calling openShell() with a ProcessProtocol to attach.
        """
        # gets a shell the first time
        ret = self.session.requestReceived(b'shell', b'')
        self.assertTrue(ret)
        self.assertSessionIsStubSession()
        self.assertIsInstance(self.session.client,
                              session.SSHSessionProcessProtocol)
        self.assertIs(self.session.session.shellProtocol, self.session.client)
        # doesn't get a shell the second time
        self.assertFalse(self.session.requestReceived(b'shell', b''))
        self.assertRequestRaisedRuntimeError() 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:18,代码来源:test_session.py

示例5: test_requestExec

# 需要导入模块: from twisted.conch.ssh import session [as 别名]
# 或者: from twisted.conch.ssh.session import SSHSession [as 别名]
def test_requestExec(self):
        """
        When a client requests a command, the SSHSession object should get
        the command by getting an ISession adapter for the avatar, then
        calling execCommand with a ProcessProtocol to attach and the
        command line.
        """
        ret = self.session.requestReceived(b'exec',
                                           common.NS(b'failure'))
        self.assertFalse(ret)
        self.assertRequestRaisedRuntimeError()
        self.assertIsNone(self.session.client)

        self.assertTrue(self.session.requestReceived(b'exec',
                                                     common.NS(b'success')))
        self.assertSessionIsStubSession()
        self.assertIsInstance(self.session.client,
                              session.SSHSessionProcessProtocol)
        self.assertIs(self.session.session.execProtocol, self.session.client)
        self.assertEqual(self.session.session.execCommandLine,
                b'success') 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:23,代码来源:test_session.py

示例6: test_requestWindowChange

# 需要导入模块: from twisted.conch.ssh import session [as 别名]
# 或者: from twisted.conch.ssh.session import SSHSession [as 别名]
def test_requestWindowChange(self):
        """
        When the client requests to change the window size, the SSHSession
        object should make the request by getting an ISession adapter for the
        avatar, then calling windowChanged with the new window size.
        """
        ret = self.session.requestReceived(
            b'window_change',
            session.packRequest_window_change((0, 0, 0, 0)))
        self.assertFalse(ret)
        self.assertRequestRaisedRuntimeError()
        self.assertSessionIsStubSession()
        self.assertTrue(self.session.requestReceived(b'window_change',
            session.packRequest_window_change((1, 2, 3, 4))))
        self.assertEqual(self.session.session.windowChange,
                (1, 2, 3, 4)) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:18,代码来源:test_session.py

示例7: test_sessionClose

# 需要导入模块: from twisted.conch.ssh import session [as 别名]
# 或者: from twisted.conch.ssh.session import SSHSession [as 别名]
def test_sessionClose(self):
        """
        Closing a session should notify an SFTP subsystem launched by that
        session.
        """
        # make a session
        testSession = session.SSHSession(conn=FakeConn(), avatar=self.avatar)

        # start an SFTP subsystem on the session
        testSession.request_subsystem(common.NS('sftp'))
        sftpServer = testSession.client.transport.proto

        # intercept connectionLost so we can check that it's called
        self.interceptConnectionLost(sftpServer)

        # close session
        testSession.closeReceived()

        self.assertSFTPConnectionLost() 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:21,代码来源:test_filetransfer.py

示例8: test_lookupSubsystemDoesNotNeedISession

# 需要导入模块: from twisted.conch.ssh import session [as 别名]
# 或者: from twisted.conch.ssh.session import SSHSession [as 别名]
def test_lookupSubsystemDoesNotNeedISession(self):
        """
        Previously, if one only wanted to implement a subsystem, an ISession
        adapter wasn't needed because subsystems were looked up using the
        lookupSubsystem method on the avatar.
        """
        s = session.SSHSession(avatar=SubsystemOnlyAvatar(),
                               conn=StubConnection())
        ret = s.request_subsystem(
            common.NS('subsystem') + 'data')
        self.assertTrue(ret)
        self.assertNotIdentical(s.client, None)
        self.assertIdentical(s.conn.closes.get(s), None)
        s.eofReceived()
        self.assertTrue(s.conn.closes.get(s))
        # these should not raise errors
        s.loseConnection()
        s.closed() 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:20,代码来源:test_session.py

示例9: test_requestShell

# 需要导入模块: from twisted.conch.ssh import session [as 别名]
# 或者: from twisted.conch.ssh.session import SSHSession [as 别名]
def test_requestShell(self):
        """
        When a client requests a shell, the SSHSession object should get
        the shell by getting an ISession adapter for the avatar, then
        calling openShell() with a ProcessProtocol to attach.
        """
        # gets a shell the first time
        ret = self.session.requestReceived('shell', '')
        self.assertTrue(ret)
        self.assertSessionIsStubSession()
        self.assertIsInstance(self.session.client,
                              session.SSHSessionProcessProtocol)
        self.assertIdentical(self.session.session.shellProtocol,
                self.session.client)
        # doesn't get a shell the second time
        self.assertFalse(self.session.requestReceived('shell', ''))
        self.assertRequestRaisedRuntimeError() 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:19,代码来源:test_session.py

示例10: test_requestExec

# 需要导入模块: from twisted.conch.ssh import session [as 别名]
# 或者: from twisted.conch.ssh.session import SSHSession [as 别名]
def test_requestExec(self):
        """
        When a client requests a command, the SSHSession object should get
        the command by getting an ISession adapter for the avatar, then
        calling execCommand with a ProcessProtocol to attach and the
        command line.
        """
        ret = self.session.requestReceived('exec',
                                           common.NS('failure'))
        self.assertFalse(ret)
        self.assertRequestRaisedRuntimeError()
        self.assertIdentical(self.session.client, None)

        self.assertTrue(self.session.requestReceived('exec',
                                                     common.NS('success')))
        self.assertSessionIsStubSession()
        self.assertIsInstance(self.session.client,
                              session.SSHSessionProcessProtocol)
        self.assertIdentical(self.session.session.execProtocol,
                self.session.client)
        self.assertEquals(self.session.session.execCommandLine,
                'success') 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:24,代码来源:test_session.py

示例11: test_requestWindowChange

# 需要导入模块: from twisted.conch.ssh import session [as 别名]
# 或者: from twisted.conch.ssh.session import SSHSession [as 别名]
def test_requestWindowChange(self):
        """
        When the client requests to change the window size, the SSHSession
        object should make the request by getting an ISession adapter for the
        avatar, then calling windowChanged with the new window size.
        """
        ret = self.session.requestReceived(
            'window_change',
            session.packRequest_window_change((0, 0, 0, 0)))
        self.assertFalse(ret)
        self.assertRequestRaisedRuntimeError()
        self.assertSessionIsStubSession()
        self.assertTrue(self.session.requestReceived('window_change',
            session.packRequest_window_change((1, 2, 3, 4))))
        self.assertEquals(self.session.session.windowChange,
                (1, 2, 3, 4)) 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:18,代码来源:test_session.py

示例12: __init__

# 需要导入模块: from twisted.conch.ssh import session [as 别名]
# 或者: from twisted.conch.ssh.session import SSHSession [as 别名]
def __init__(self):
        avatar.ConchUser.__init__(self)
        self.listeners = {}
        self.globalRequests = {}
        self.channelLookup.update(
            {b'session': session.SSHSession,
             b'direct-tcpip':forwarding.openConnectForwardingClient})
        self.subsystemLookup.update({b'crazy': CrazySubsystem}) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:10,代码来源:test_ssh.py

示例13: __init__

# 需要导入模块: from twisted.conch.ssh import session [as 别名]
# 或者: from twisted.conch.ssh.session import SSHSession [as 别名]
def __init__(self):
        avatar.ConchUser.__init__(self)
        self.channelLookup[b'session'] = session.SSHSession
        self.subsystemLookup[b'sftp'] = filetransfer.FileTransferServer 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:6,代码来源:test_filetransfer.py

示例14: lookupSubsystem

# 需要导入模块: from twisted.conch.ssh import session [as 别名]
# 或者: from twisted.conch.ssh.session import SSHSession [as 别名]
def lookupSubsystem(self, name, data):
        """
        If the user requests the TestSubsystem subsystem, connect them to a
        MockProtocol.  If they request neither, then None is returned which is
        interpreted by SSHSession as a failure.
        """
        if name == b'TestSubsystem':
            self.subsystem = MockProtocol()
            self.subsystem.packetData = data
            return self.subsystem 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:12,代码来源:test_session.py

示例15: test_init

# 需要导入模块: from twisted.conch.ssh import session [as 别名]
# 或者: from twisted.conch.ssh.session import SSHSession [as 别名]
def test_init(self):
        """
        SSHSession initializes its buffer (buf), client, and ISession adapter.
        The avatar should not need to be adaptable to an ISession immediately.
        """
        s = session.SSHSession(avatar=object) # use object because it doesn't
                                              # have an adapter
        self.assertEqual(s.buf, b'')
        self.assertIsNone(s.client)
        self.assertIsNone(s.session) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:12,代码来源:test_session.py


注:本文中的twisted.conch.ssh.session.SSHSession方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。