From c04d3632ccbcc9a7d549b9d4f1a7b9eac7c9833d Mon Sep 17 00:00:00 2001 From: Jeremy Fincher Date: Wed, 11 Feb 2004 05:57:34 +0000 Subject: [PATCH] strictRfc added, off by default. --- scripts/supybot | 10 ++++++++-- src/conf.py | 1 - src/ircutils.py | 33 +++++++++++++++++++++------------ 3 files changed, 29 insertions(+), 15 deletions(-) diff --git a/scripts/supybot b/scripts/supybot index 8a90ece73..9a5fb2871 100755 --- a/scripts/supybot +++ b/scripts/supybot @@ -134,6 +134,10 @@ if __name__ == '__main__': dest='allowEval', help='Determines whether the bot will ' 'allow the evaluation of arbitrary Python code.') + parser.add_option('', '--strict-rfc', action='store_true', + dest='strictRfc', + help='Determines whether the bot will strictly follow ' + 'RFC guidelines defining nicks and channels.') (options, args) = parser.parse_args() @@ -291,8 +295,7 @@ if __name__ == '__main__': except ImportError: log.warning('Psyco isn\'t installed, cannot -OO.') - if options.allowEval: - conf.allowEval = True + conf.allowEval = options.allowEval if not os.path.exists(conf.supybot.directories.log()): os.mkdir(conf.supybot.directories.log()) @@ -307,6 +310,9 @@ if __name__ == '__main__': import callbacks import Owner + import ircutils + ircutils.strictRfc = options.strictRfc + irc = irclib.Irc(nick, user, ident, password) callback = Owner.Class() irc.addCallback(callback) diff --git a/src/conf.py b/src/conf.py index 95ff35009..20d27b1ca 100644 --- a/src/conf.py +++ b/src/conf.py @@ -53,7 +53,6 @@ _pluginsDir = os.path.join(installDir, 'plugins') ### allowEval = False - supybot = registry.Group() supybot.setName('supybot') diff --git a/src/ircutils.py b/src/ircutils.py index 78ba35e29..49eafa33d 100644 --- a/src/ircutils.py +++ b/src/ircutils.py @@ -54,6 +54,12 @@ from cStringIO import StringIO as sio import utils +### +# strictRfc: Determines whether the bot will very strictly follow the RCE +# or whether it will allow things like @ and . in nicks. +### +strictRfc = False + def isUserHostmask(s): """Returns whether or not the string s is a valid User hostmask.""" p1 = s.find('!') @@ -104,29 +110,33 @@ def nickEqual(nick1, nick2): """Returns True if nick1 == nick2 according to IRC case rules.""" return toLower(nick1) == toLower(nick2) + _nickchars = r'_[]\`^{}|-' -nickRe = re.compile(r'^[A-Za-z%s][0-9A-Za-z%s]*$' % (re.escape(_nickchars), - re.escape(_nickchars))) -def isCtcp(msg): - """Returns whether or not msg is a CTCP message.""" - return msg.command == 'PRIVMSG' and \ - msg.args[1].startswith('\x01') and \ - msg.args[1].endswith('\x01') +strictNickRe = re.compile(r'^[A-Za-z%s][0-9A-Za-z%s]*$' + % (re.escape(_nickchars), re.escape(_nickchars))) +_nickchars += '@.' +nickRe = re.compile(r'^[A-Za-z%s][0-9A-Za-z%s]*$' + % (re.escape(_nickchars), re.escape(_nickchars))) def isNick(s): """Returns True if s is a valid IRC nick.""" - if re.match(nickRe, s): - return True + if strictRfc: + return bool(strictNickRe.match(s)) else: - return False + return bool(nickRe.match(s)) def isChannel(s): """Returns True if s is a valid IRC channel name.""" return (s and s[0] in '#&+!' and len(s) <= 50 and \ '\x07' not in s and ',' not in s and ' ' not in s) -_match = fnmatch.fnmatchcase +def isCtcp(msg): + """Returns whether or not msg is a CTCP message.""" + return msg.command == 'PRIVMSG' and \ + msg.args[1].startswith('\x01') and \ + msg.args[1].endswith('\x01') +_match = fnmatch.fnmatchcase _patternCache = {} def _hostmaskPatternEqual(pattern, hostmask): """Returns True if hostmask matches the hostmask pattern pattern.""" @@ -163,7 +173,6 @@ def hostmaskPatternEqual(pattern, hostmask): _hostmaskPatternEqualCache[(pattern, hostmask)] = b return b - def banmask(hostmask): """Returns a properly generic banning hostmask for a hostmask.