mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-12-24 19:52:54 +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,
|
||||
})
|
||||
|
||||
|
||||
_wrappers = wrappers # Used below so we can use a keyword argument "wrappers".
|
||||
def wrap(f, required=[], optional=[],
|
||||
wrappers=None, getopts=None, noExtra=False):
|
||||
def args(irc,msg,args, required=[], optional=[], getopts=None, noExtra=False):
|
||||
starArgs = []
|
||||
req = required[:]
|
||||
opt = optional[:]
|
||||
if getopts is not None:
|
||||
getoptL = []
|
||||
for (key, value) in getopts.iteritems():
|
||||
if value != '': # value can be None, remember.
|
||||
key += '='
|
||||
getoptL.append(key)
|
||||
|
||||
def getArgWrapper(x):
|
||||
if isinstance(x, tuple):
|
||||
assert x
|
||||
@ -325,11 +324,6 @@ def wrap(f, required=[], optional=[],
|
||||
return argWrappers[name], args
|
||||
else:
|
||||
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):
|
||||
(converter, convertArgs) = getArgWrapper(name)
|
||||
v = converter(irc, msg, args, *convertArgs)
|
||||
@ -380,6 +374,18 @@ def wrap(f, required=[], optional=[],
|
||||
starArgs.append('')
|
||||
if noExtra and args:
|
||||
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)
|
||||
|
||||
if wrappers is not None:
|
||||
|
Loading…
Reference in New Issue
Block a user