strictRfc added, off by default.

This commit is contained in:
Jeremy Fincher 2004-02-11 05:57:34 +00:00
parent 0c605c2163
commit c04d3632cc
3 changed files with 29 additions and 15 deletions

View File

@ -134,6 +134,10 @@ if __name__ == '__main__':
dest='allowEval', dest='allowEval',
help='Determines whether the bot will ' help='Determines whether the bot will '
'allow the evaluation of arbitrary Python code.') '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() (options, args) = parser.parse_args()
@ -291,8 +295,7 @@ if __name__ == '__main__':
except ImportError: except ImportError:
log.warning('Psyco isn\'t installed, cannot -OO.') log.warning('Psyco isn\'t installed, cannot -OO.')
if options.allowEval: conf.allowEval = options.allowEval
conf.allowEval = True
if not os.path.exists(conf.supybot.directories.log()): if not os.path.exists(conf.supybot.directories.log()):
os.mkdir(conf.supybot.directories.log()) os.mkdir(conf.supybot.directories.log())
@ -307,6 +310,9 @@ if __name__ == '__main__':
import callbacks import callbacks
import Owner import Owner
import ircutils
ircutils.strictRfc = options.strictRfc
irc = irclib.Irc(nick, user, ident, password) irc = irclib.Irc(nick, user, ident, password)
callback = Owner.Class() callback = Owner.Class()
irc.addCallback(callback) irc.addCallback(callback)

View File

@ -53,7 +53,6 @@ _pluginsDir = os.path.join(installDir, 'plugins')
### ###
allowEval = False allowEval = False
supybot = registry.Group() supybot = registry.Group()
supybot.setName('supybot') supybot.setName('supybot')

View File

@ -54,6 +54,12 @@ from cStringIO import StringIO as sio
import utils 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): def isUserHostmask(s):
"""Returns whether or not the string s is a valid User hostmask.""" """Returns whether or not the string s is a valid User hostmask."""
p1 = s.find('!') p1 = s.find('!')
@ -104,29 +110,33 @@ def nickEqual(nick1, nick2):
"""Returns True if nick1 == nick2 according to IRC case rules.""" """Returns True if nick1 == nick2 according to IRC case rules."""
return toLower(nick1) == toLower(nick2) return toLower(nick1) == toLower(nick2)
_nickchars = r'_[]\`^{}|-' _nickchars = r'_[]\`^{}|-'
nickRe = re.compile(r'^[A-Za-z%s][0-9A-Za-z%s]*$' % (re.escape(_nickchars), strictNickRe = re.compile(r'^[A-Za-z%s][0-9A-Za-z%s]*$'
re.escape(_nickchars))) % (re.escape(_nickchars), re.escape(_nickchars)))
def isCtcp(msg): _nickchars += '@.'
"""Returns whether or not msg is a CTCP message.""" nickRe = re.compile(r'^[A-Za-z%s][0-9A-Za-z%s]*$'
return msg.command == 'PRIVMSG' and \ % (re.escape(_nickchars), re.escape(_nickchars)))
msg.args[1].startswith('\x01') and \
msg.args[1].endswith('\x01')
def isNick(s): def isNick(s):
"""Returns True if s is a valid IRC nick.""" """Returns True if s is a valid IRC nick."""
if re.match(nickRe, s): if strictRfc:
return True return bool(strictNickRe.match(s))
else: else:
return False return bool(nickRe.match(s))
def isChannel(s): def isChannel(s):
"""Returns True if s is a valid IRC channel name.""" """Returns True if s is a valid IRC channel name."""
return (s and s[0] in '#&+!' and len(s) <= 50 and \ return (s and s[0] in '#&+!' and len(s) <= 50 and \
'\x07' not in s and ',' not in s and ' ' not in s) '\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 = {} _patternCache = {}
def _hostmaskPatternEqual(pattern, hostmask): def _hostmaskPatternEqual(pattern, hostmask):
"""Returns True if hostmask matches the hostmask pattern pattern.""" """Returns True if hostmask matches the hostmask pattern pattern."""
@ -163,7 +173,6 @@ def hostmaskPatternEqual(pattern, hostmask):
_hostmaskPatternEqualCache[(pattern, hostmask)] = b _hostmaskPatternEqualCache[(pattern, hostmask)] = b
return b return b
def banmask(hostmask): def banmask(hostmask):
"""Returns a properly generic banning hostmask for a hostmask. """Returns a properly generic banning hostmask for a hostmask.