Exemplo n.º 1
0
 def testFromString(self):
     for url, expected in urls:
         result = Url.from_string(url)
         error = 'URL:      ' + url + '\n'
         error += 'Result:   ' + str(result) + '\n'
         error += 'Expected: ' + expected
         self.assert_(isinstance(result, Url))
         self.assert_(str(result) == expected, error)
Exemplo n.º 2
0
 def testToString(self):
     for url, expected in urls:
         result = Url.from_string(url)
         error = 'URL:      ' + url + '\n'
         error += 'Result:   ' + str(result) + '\n'
         error += 'Expected: ' + expected
         self.assertIsInstance(result, Url, error)
         self.assertEqual(result.to_string(), expected, error)
Exemplo n.º 3
0
 def testFromString(self):
     for url, expected in urls:
         result = Url.from_string(url)
         error = 'URL:      ' + url + '\n'
         error += 'Result:   ' + str(result) + '\n'
         error += 'Expected: ' + expected
         self.assertIsInstance(result, Url)
         self.assertTrue(str(result) == expected, error)
Exemplo n.º 4
0
    def testConstructor(self):
        host = Host('localhost')
        self.assertEqual(host.get_protocol(), 'telnet')
        host = Host('localhost', default_protocol = 'foo')
        self.assertEqual(host.get_protocol(), 'foo')

        for url, result in urls:
            host = Host(url)
            uri  = Url.from_string(url)
            self.assertEqual(host.get_name(),    uri.hostname)
            self.assertEqual(host.get_address(), uri.hostname)
            self.assertEqual(host.get_uri(), str(uri))
Exemplo n.º 5
0
    def testConstructor(self):
        host = Host('localhost')
        self.assertEqual(host.get_protocol(), 'telnet')
        host = Host('localhost', default_protocol='foo')
        self.assertEqual(host.get_protocol(), 'foo')

        for url, result in urls:
            host = Host(url)
            uri = Url.from_string(url)
            self.assertEqual(host.get_name(), uri.hostname)
            self.assertEqual(host.get_address(), uri.hostname)
            self.assertEqual(host.get_uri(), str(uri))
Exemplo n.º 6
0
    def set_uri(self, uri):
        """
        Defines the protocol, hostname/address, TCP port number, username,
        and password from the given URL. The hostname may be URL formatted,
        so the following formats are all valid:

            - myhostname
            - myhostname.domain
            - ssh:hostname
            - ssh:hostname.domain
            - ssh://hostname
            - ssh://user@hostname
            - ssh://user:password@hostname
            - ssh://user:password@hostname:21

        For a list of supported protocols please see set_protocol().

        @type  uri: string
        @param uri: An URL formatted hostname.
        """
        try:
            uri = Url.from_string(uri, self.protocol)
        except ValueError:
            raise ValueError('Hostname parse error: ' + repr(uri))
        hostname = uri.hostname or ''
        name = uri.path and hostname + uri.path or hostname
        self.set_protocol(uri.protocol)
        self.set_tcp_port(uri.port)
        self.set_name(name)
        self.set_address(name)

        if uri.username is not None \
           or uri.password1 is not None \
           or uri.password2:
            account = Account(uri.username, uri.password1, uri.password2)
            self.set_account(account)

        for key, val in uri.vars.iteritems():
            self.set(key, val)
Exemplo n.º 7
0
 def testGetUri(self):
     for url, result in urls:
         host = Host(url)
         uri = Url.from_string(url)
         self.assertEqual(host.get_uri().split('&').sort(),
                          str(uri).split('&').sort())
Exemplo n.º 8
0
 def testSetUri(self):
     for url, result in urls:
         self.host.set_uri(url)
         uri = Url.from_string(url)
         self.assertEqual(self.host.get_name(), uri.hostname)
         self.assertEqual(self.host.get_address(), uri.hostname)
Exemplo n.º 9
0
 def testGetUri(self):
     for url, result in urls:
         host = Host(url)
         uri  = Url.from_string(url)
         self.assertEqual(host.get_uri(), str(uri))
Exemplo n.º 10
0
 def testSetUri(self):
     for url, result in urls:
         self.host.set_uri(url)
         uri = Url.from_string(url)
         self.assertEqual(self.host.get_name(),    uri.hostname)
         self.assertEqual(self.host.get_address(), uri.hostname)