示例#1
0
 def test_clone_with_mutations(self):
     T = namedtuple('T', 'foo, bar')
     a = T(5, 'hello')
     self.assertEqual((5, 'bye'),
                      tuple_util.clone(a, mutations={'bar': 'bye'}))
     self.assertEqual((9, 'bye2'),
                      tuple_util.clone(a,
                                       mutations={
                                           'foo': 9,
                                           'bar': 'bye2'
                                       }))
示例#2
0
    def scan(clazz,
             hostname,
             key_type=None,
             include_ip_address=True,
             include_comment=True):
        check.check_string(hostname)
        check.check_string(key_type, allow_none=True)
        check.check_bool(include_ip_address)
        check.check_bool(include_comment)

        key_type = key_type or clazz.DEFAULT_KEY_TYPE
        if not clazz.is_valid_key_type(key_type):
            raise ssh_config_error('Invalid key type: "{}"'.format(key_type))
        args = ['-t', key_type, hostname]
        output = clazz._call_ssh_keyscan(args)
        result = clazz._parse_ssh_keyscan_output(
            output, include_comment=include_comment)
        ip_address = socket.gethostbyname(hostname)
        hostname_is_ip = hostname == ip_address
        if hostname_is_ip:
            return result
        if include_ip_address:
            hostnames = result.hostnames + [ip_address]
        else:
            hostnames = result.hostnames
        return tuple_util.clone(result, mutations={'hostnames': hostnames})
示例#3
0
 def clone(self, mutations=None):
     mutations = mutations or {}
     if 'position' in mutations:
         position = mutations['position']
         check.check_point(position)
     else:
         position = self.position
     copied_mutations = copy.deepcopy(mutations)
     copied_mutations['position'] = position.clone()
     return tuple_util.clone(self, mutations=copied_mutations)
示例#4
0
 def clone(self, mutations = None):
   return tuple_util.clone(self, mutations = mutations)
示例#5
0
 def test_clone_with_mutations_invalid_field(self):
     T = namedtuple('T', 'foo, bar')
     a = T(5, 'hello')
     with self.assertRaises(ValueError) as ctx:
         tuple_util.clone(a, mutations={'kiwi': 'hi'})
示例#6
0
 def test_clone(self):
     T = namedtuple('T', 'foo, bar')
     a = T(5, 'hello')
     self.assertEqual((5, 'hello'), tuple_util.clone(a))