mirror of https://github.com/Mikaela/Limnoria.git
Updated _int to accept other bases.
This commit is contained in:
parent
54d1a91e80
commit
51c0fb4cc1
|
@ -150,7 +150,23 @@ decorators = ircutils.IrcDict({
|
||||||
|
|
||||||
# This is just so we can centralize this, since it may change.
|
# This is just so we can centralize this, since it may change.
|
||||||
def _int(s):
|
def _int(s):
|
||||||
return int(float(s))
|
base = 10
|
||||||
|
if s.startswith('0x'):
|
||||||
|
base = 16
|
||||||
|
s = s[2:]
|
||||||
|
elif s.startswith('0b'):
|
||||||
|
base = 2
|
||||||
|
s = s[2:]
|
||||||
|
elif s.startswith('0') and len(s) > 1:
|
||||||
|
base = 8
|
||||||
|
s = s[1:]
|
||||||
|
try:
|
||||||
|
return int(s, base)
|
||||||
|
except ValueError:
|
||||||
|
if base == 10:
|
||||||
|
return int(float(s))
|
||||||
|
else:
|
||||||
|
raise
|
||||||
|
|
||||||
def getInt(irc, msg, args, state, type='integer', p=None):
|
def getInt(irc, msg, args, state, type='integer', p=None):
|
||||||
try:
|
try:
|
||||||
|
@ -356,6 +372,12 @@ def private(irc, msg, args, state):
|
||||||
if ircutils.isChannel(msg.args[0]):
|
if ircutils.isChannel(msg.args[0]):
|
||||||
irc.errorRequiresPrivacy(Raise=True)
|
irc.errorRequiresPrivacy(Raise=True)
|
||||||
|
|
||||||
|
def public(irc, msg, args, state, errmsg=None):
|
||||||
|
if not ircutils.isChannel(msg.args[0]):
|
||||||
|
if errmsg is None:
|
||||||
|
errmsg = 'This message must be sent in a channel.'
|
||||||
|
irc.error(errmsg, Raise=True)
|
||||||
|
|
||||||
def checkCapability(irc, msg, args, state, cap):
|
def checkCapability(irc, msg, args, state, cap):
|
||||||
cap = ircdb.canonicalCapability(cap)
|
cap = ircdb.canonicalCapability(cap)
|
||||||
if not ircdb.checkCapability(msg.prefix, cap):
|
if not ircdb.checkCapability(msg.prefix, cap):
|
||||||
|
@ -377,9 +399,40 @@ def getNow(irc, msg, args, state):
|
||||||
|
|
||||||
def getCommandName(irc, msg, args, state):
|
def getCommandName(irc, msg, args, state):
|
||||||
state.args.append(callbacks.canonicalName(args.pop(0)))
|
state.args.append(callbacks.canonicalName(args.pop(0)))
|
||||||
|
|
||||||
|
def getIp(irc, msg, args, state):
|
||||||
|
if utils.isIP(args[0]):
|
||||||
|
state.args.append(args.pop(0))
|
||||||
|
else:
|
||||||
|
irc.errorInvalid('ip', args[0])
|
||||||
|
|
||||||
|
def getLetter(irc, msg, args, state):
|
||||||
|
if len(args[0]) == 1:
|
||||||
|
state.args.append(args.pop(0))
|
||||||
|
else:
|
||||||
|
irc.errorInvalid('letter', args[0])
|
||||||
|
|
||||||
|
def getMatch(irc, msg, args, state, regexp, errmsg):
|
||||||
|
m = regexp.search(args[0])
|
||||||
|
if m is not None:
|
||||||
|
state.args.append(m)
|
||||||
|
del args[0]
|
||||||
|
else:
|
||||||
|
irc.error(errmsg, Raise=True)
|
||||||
|
|
||||||
|
def getLiteral(irc, msg, args, state, literals, errmsg=None):
|
||||||
|
if isinstance(literals, basestring):
|
||||||
|
literals = (literals,)
|
||||||
|
if args[0] in literals:
|
||||||
|
state.args.append(args.pop(0))
|
||||||
|
elif errmsg is not None:
|
||||||
|
irc.error(errmsg, Raise=True)
|
||||||
|
else:
|
||||||
|
raise callbacks.ArgumentError
|
||||||
|
|
||||||
wrappers = ircutils.IrcDict({
|
wrappers = ircutils.IrcDict({
|
||||||
'id': getId,
|
'id': getId,
|
||||||
|
'ip': getIp,
|
||||||
'int': getInt,
|
'int': getInt,
|
||||||
'now': getNow,
|
'now': getNow,
|
||||||
'url': getUrl,
|
'url': getUrl,
|
||||||
|
@ -387,8 +440,10 @@ wrappers = ircutils.IrcDict({
|
||||||
'nonInt': getNonInt,
|
'nonInt': getNonInt,
|
||||||
'positiveInt': getPositiveInt,
|
'positiveInt': getPositiveInt,
|
||||||
'nonNegativeInt': getNonNegativeInt,
|
'nonNegativeInt': getNonNegativeInt,
|
||||||
|
'letter': getLetter,
|
||||||
'haveOp': getHaveOp,
|
'haveOp': getHaveOp,
|
||||||
'expiry': getExpiry,
|
'expiry': getExpiry,
|
||||||
|
'literal': getLiteral,
|
||||||
'nick': getNick,
|
'nick': getNick,
|
||||||
'channel': getChannel,
|
'channel': getChannel,
|
||||||
'inChannel': inChannel,
|
'inChannel': inChannel,
|
||||||
|
@ -405,6 +460,7 @@ wrappers = ircutils.IrcDict({
|
||||||
'hostmask': getHostmask,
|
'hostmask': getHostmask,
|
||||||
'banmask': getBanmask,
|
'banmask': getBanmask,
|
||||||
'user': getUser,
|
'user': getUser,
|
||||||
|
'public': public,
|
||||||
'private': private,
|
'private': private,
|
||||||
'otherUser': getOtherUser,
|
'otherUser': getOtherUser,
|
||||||
'regexpMatcher': getMatcher,
|
'regexpMatcher': getMatcher,
|
||||||
|
|
Loading…
Reference in New Issue