Migrate most uses of if type() to if isinstance()

Also convert those checks to use abcs instead of dict and list.

Make a sentinel class for strategies to report when they've reache the end
This commit is contained in:
Toshio Kuratomi 2017-03-26 09:24:30 -07:00
commit 6bad4e57bd
12 changed files with 49 additions and 34 deletions

View file

@ -43,13 +43,16 @@
import argparse
import os.path
import sys
import paramiko
from collections import MutableSequence
try:
import json
except ImportError:
import simplejson as json
import paramiko
SSH_CONF = '~/.ssh/config'
_key = 'ssh_config'
@ -68,7 +71,7 @@ def get_config():
cfg.parse(f)
ret_dict = {}
for d in cfg._config:
if type(d['host']) is list:
if isinstance(d['host'], MutableSequence):
alias = d['host'][0]
else:
alias = d['host']
@ -93,7 +96,7 @@ def print_list():
# If the attribute is a list, just take the first element.
# Private key is returned in a list for some reason.
attr = attributes[ssh_opt]
if type(attr) is list:
if isinstance(attr, MutableSequence):
attr = attr[0]
tmp_dict[ans_opt] = attr
if tmp_dict: