3
0
mirror of https://github.com/jlu5/PyLink.git synced 2024-12-28 21:52:38 +01:00

Merge branch 'type-to-isinstance' of https://github.com/cooper/PyLink into devel

This commit is contained in:
James Lu 2017-07-14 05:22:37 -07:00
commit 880d0975db
4 changed files with 15 additions and 14 deletions

View File

@ -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)

View File

@ -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!")

View File

@ -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 = {}

View File

@ -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)