mirror of
https://github.com/jlu5/PyLink.git
synced 2024-11-01 01:09:22 +01:00
use isinstance() for conf values as well
This commit is contained in:
parent
7ab0e8f105
commit
3e356180a0
8
conf.py
8
conf.py
@ -62,7 +62,7 @@ def _log(level, text, *args, logger=None, **kwargs):
|
|||||||
|
|
||||||
def validateConf(conf, logger=None):
|
def validateConf(conf, logger=None):
|
||||||
"""Validates a parsed configuration dict."""
|
"""Validates a parsed configuration dict."""
|
||||||
validate(type(conf) == dict,
|
validate(isinstance(conf, dict),
|
||||||
"Invalid configuration given: should be type dict, not %s."
|
"Invalid configuration given: should be type dict, not %s."
|
||||||
% type(conf).__name__)
|
% 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. "
|
_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)
|
"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', {})
|
newlogins = conf['login'].get('accounts', {})
|
||||||
|
|
||||||
validate(old_login_valid or newlogins, "No accounts were set, aborting!")
|
validate(old_login_valid or newlogins, "No accounts were set, aborting!")
|
||||||
for account, block in newlogins.items():
|
for account, block in newlogins.items():
|
||||||
validate(type(account) == str, "Bad username format %s" % account)
|
validate(isinstance(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(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!")
|
validate(conf['login'].get('password') != "changeme", "You have not set the login details correctly!")
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ class IRCCommonProtocol(IRCNetwork):
|
|||||||
% (k, self.name))
|
% (k, self.name))
|
||||||
|
|
||||||
port = self.serverdata['port']
|
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"
|
"Invalid port %r for network %s"
|
||||||
% (port, self.name))
|
% (port, self.name))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user