diff --git a/classes.py b/classes.py index e97c07d..d7a45a3 100644 --- a/classes.py +++ b/classes.py @@ -502,7 +502,7 @@ class PyLinkNetworkCoreWithUtils(PyLinkNetworkCore): # C = Mode that changes a setting and only has a parameter when set. # D = Mode that changes a setting and never has a parameter. - if type(args) == str: + if isinstance(args, str): # If the modestring was given as a string, split it into a list. args = args.split() @@ -692,9 +692,10 @@ class PyLinkNetworkCoreWithUtils(PyLinkNetworkCore): => {('-m', None), ('-r', None), ('-l', None), ('+o', 'person')}) {('s', None), ('+o', 'whoever') => {('-s', None), ('-o', 'whoever')}) """ - origtype = type(modes) + origstring = isinstance(modes, str) + # If the query is a string, we have to parse it first. - if origtype == str: + if origstring: modes = self.parse_modes(target, modes.split(" ")) # Get the current mode list first. if utils.isChannel(target): @@ -750,7 +751,7 @@ class PyLinkNetworkCoreWithUtils(PyLinkNetworkCore): newmodes.append(mpair) log.debug('(%s) reverse_modes: new modes: %s', self.name, newmodes) - if origtype == str: + if origstring: # If the original query is a string, send it back as a string. return self.join_modes(newmodes) else: @@ -1069,8 +1070,8 @@ class PyLinkNetworkCoreWithUtils(PyLinkNetworkCore): # conditions that would otherwise desync channel modes. with self._ts_lock: our_ts = self.channels[channel].ts - assert type(our_ts) == int, "Wrong type for our_ts (expected int, got %s)" % type(our_ts) - assert type(their_ts) == int, "Wrong type for their_ts (expected int, got %s)" % type(their_ts) + assert isinstance(our_ts, int), "Wrong type for our_ts (expected int, got %s)" % type(our_ts) + assert isinstance(their_ts, int), "Wrong type for their_ts (expected int, got %s)" % type(their_ts) # Check if we're the mode sender based on the UID / SID given. our_mode = self.is_internal_client(sender) or self.is_internal_server(sender) diff --git a/conf.py b/conf.py index de74cfe..e78aefd 100644 --- a/conf.py +++ b/conf.py @@ -62,7 +62,7 @@ def _log(level, text, *args, logger=None, **kwargs): def validateConf(conf, logger=None): """Validates a parsed configuration dict.""" - validate(type(conf) == dict, + validate(isinstance(conf, dict), "Invalid configuration given: should be type dict, not %s." % type(conf).__name__) @@ -88,13 +88,13 @@ def validateConf(conf, logger=None): _log(logging.WARNING, "The 'login:user' and 'login:password' options are deprecated since PyLink 1.1. " "Please switch to the new 'login:accounts' format as outlined in the example config.", logger=logger) - old_login_valid = type(conf['login'].get('password')) == type(conf['login'].get('user')) == str + old_login_valid = isinstance(conf['login'].get('password'), str) and isinstance(conf['login'].get('user'), str) newlogins = conf['login'].get('accounts', {}) validate(old_login_valid or newlogins, "No accounts were set, aborting!") for account, block in newlogins.items(): - validate(type(account) == str, "Bad username format %s" % account) - validate(type(block.get('password')) == str, "Bad password %s for account %s" % (block.get('password'), account)) + validate(isinstance(account, str), "Bad username format %s" % account) + validate(isinstance(block.get('password'), str), "Bad password %s for account %s" % (block.get('password'), account)) validate(conf['login'].get('password') != "changeme", "You have not set the login details correctly!") diff --git a/protocols/ircs2s_common.py b/protocols/ircs2s_common.py index 679b5c6..f225385 100644 --- a/protocols/ircs2s_common.py +++ b/protocols/ircs2s_common.py @@ -32,7 +32,7 @@ class IRCCommonProtocol(IRCNetwork): % (k, self.name)) port = self.serverdata['port'] - conf.validate(type(port) == int and 0 < port < 65535, + conf.validate(isinstance(port, int) and 0 < port < 65535, "Invalid port %r for network %s" % (port, self.name)) @@ -152,7 +152,7 @@ class IRCCommonProtocol(IRCNetwork): Parses a string of capabilities in the 005 / RPL_ISUPPORT format. """ - if type(args) == str: + if isinstance(args, str): args = args.split(' ') caps = {} diff --git a/utils.py b/utils.py index 2f64d8f..396291e 100644 --- a/utils.py +++ b/utils.py @@ -243,13 +243,13 @@ class ServiceBot(): Joins the given service bot to the given channel(s). """ - if type(irc) == str: + if isinstance(irc, str): netname = irc else: netname = irc.name # Ensure type safety: pluralize strings if only one channel was given, then convert to set. - if type(channels) == str: + if isinstance(channels, str): channels = [channels] channels = set(channels)