mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-12-25 04:02:46 +01:00
Factored out the args component of wrap into its own function, so it can be used in more situations.
This commit is contained in:
parent
2e07e23fd5
commit
7558a437e1
@ -301,17 +301,16 @@ argWrappers = ircutils.IrcDict({
|
|||||||
'regexpReplacer': getReplacer,
|
'regexpReplacer': getReplacer,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
def args(irc,msg,args, required=[], optional=[], getopts=None, noExtra=False):
|
||||||
_wrappers = wrappers # Used below so we can use a keyword argument "wrappers".
|
starArgs = []
|
||||||
def wrap(f, required=[], optional=[],
|
req = required[:]
|
||||||
wrappers=None, getopts=None, noExtra=False):
|
opt = optional[:]
|
||||||
if getopts is not None:
|
if getopts is not None:
|
||||||
getoptL = []
|
getoptL = []
|
||||||
for (key, value) in getopts.iteritems():
|
for (key, value) in getopts.iteritems():
|
||||||
if value != '': # value can be None, remember.
|
if value != '': # value can be None, remember.
|
||||||
key += '='
|
key += '='
|
||||||
getoptL.append(key)
|
getoptL.append(key)
|
||||||
|
|
||||||
def getArgWrapper(x):
|
def getArgWrapper(x):
|
||||||
if isinstance(x, tuple):
|
if isinstance(x, tuple):
|
||||||
assert x
|
assert x
|
||||||
@ -325,11 +324,6 @@ def wrap(f, required=[], optional=[],
|
|||||||
return argWrappers[name], args
|
return argWrappers[name], args
|
||||||
else:
|
else:
|
||||||
return lambda irc, msg, args: args.pop(0), args
|
return lambda irc, msg, args: args.pop(0), args
|
||||||
|
|
||||||
def newf(self, irc, msg, args, **kwargs):
|
|
||||||
starArgs = []
|
|
||||||
req = (required or [])[:]
|
|
||||||
opt = (optional or [])[:]
|
|
||||||
def getConversion(name):
|
def getConversion(name):
|
||||||
(converter, convertArgs) = getArgWrapper(name)
|
(converter, convertArgs) = getArgWrapper(name)
|
||||||
v = converter(irc, msg, args, *convertArgs)
|
v = converter(irc, msg, args, *convertArgs)
|
||||||
@ -380,6 +374,18 @@ def wrap(f, required=[], optional=[],
|
|||||||
starArgs.append('')
|
starArgs.append('')
|
||||||
if noExtra and args:
|
if noExtra and args:
|
||||||
raise callbacks.ArgumentError
|
raise callbacks.ArgumentError
|
||||||
|
return starArgs
|
||||||
|
|
||||||
|
# These are used below, but we need to rename them so their names aren't
|
||||||
|
# shadowed by our locals.
|
||||||
|
_args = args
|
||||||
|
_wrappers = wrappers
|
||||||
|
def wrap(f, required=[], optional=[],
|
||||||
|
wrappers=None, getopts=None, noExtra=False):
|
||||||
|
def newf(self, irc, msg, args, **kwargs):
|
||||||
|
starArgs = _args(irc, msg, args,
|
||||||
|
getopts=getopts, noExtra=noExtra,
|
||||||
|
required=required, optional=optional)
|
||||||
f(self, irc, msg, args, *starArgs, **kwargs)
|
f(self, irc, msg, args, *starArgs, **kwargs)
|
||||||
|
|
||||||
if wrappers is not None:
|
if wrappers is not None:
|
||||||
|
Loading…
Reference in New Issue
Block a user