예제 #1
0
    def __init__(self,
                 hostname,
                 echo=True,
                 login_type=LOGIN_TYPE_BOTH,
                 strict=True,
                 banner=None):
        """
        :type  hostname: str
        :param hostname: The hostname, used for the prompt.

        :keyword banner: A string to show as soon as the connection is opened.
        :keyword login_type: integer constant, one of LOGIN_TYPE_PASSWORDONLY,
            LOGIN_TYPE_USERONLY, LOGIN_TYPE_BOTH, LOGIN_TYPE_NONE.
        :keyword echo: whether to echo the command in a response.
        :keyword strict: Whether to raise when a given command has no handler.
        """
        self.hostname = hostname
        self.banner = banner or 'Welcome to %s!\n' % str(hostname)
        self.echo = echo
        self.login_type = login_type
        self.prompt = hostname + '> '
        self.logged_in = False
        self.commands = CommandSet(strict=strict)
        self.user_prompt = 'User: '******'Password: '
        self.init()
예제 #2
0
    def testAdd(self):
        cs = CommandSet()
        self.assertRaises(Exception, cs.eval, 'foo')

        cs = CommandSet(strict=False)
        self.assertEqual(cs.eval('foo'), None)

        cs = CommandSet(strict=True)
        self.assertRaises(Exception, cs.eval, 'foo')
        cs.add('foo', 'bar')
        self.assertEqual(cs.eval('foo'), 'bar')

        def sayhello(cmd):
            return 'hello'

        cs.add('hi', sayhello)
        self.assertEqual(cs.eval('hi'), 'hello')
예제 #3
0
 def testConstructor(self):
     CommandSet()
     CommandSet(strict=True)
     CommandSet(strict=False)