Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

New syntax for wrap(). Now supports being used as a Python decorator …

…with arguments.

For example, in Admin, "join = wrap(join, ['validChannel', additional('something')])" could become "@wrap(['validChannel', additional('something')])".
  • Loading branch information...
commit 66025cf7e412790bc8943f169324f923129e92c2 1 parent b887a97
@ProgVal authored
Showing with 14 additions and 1 deletion.
  1. +14 −1 src/commands.py
View
15 src/commands.py
@@ -1038,7 +1038,7 @@ def __call__(self, irc, msg, args, stateAttrs={}):
raise callbacks.ArgumentError
return state
-def wrap(f, specList=[], name=None, **kw):
+def _wrap(f, specList=[], name=None, **kw):
name = name or f.func_name
spec = Spec(specList, **kw)
def newf(self, irc, msg, args, **kwargs):
@@ -1059,6 +1059,19 @@ def newf(self, irc, msg, args, **kwargs):
'function ;)')
raise
return utils.python.changeFunctionName(newf, name, f.__doc__)
+
+def wrap(f, *args, **kwargs):
+ if callable(f):
+ # Old-style call OR decorator syntax with no converter.
+ # f is the command.
+ return _wrap(f, *args, **kwargs)
+ else:
+ # Call with the Python decorator syntax
+ assert isinstance(f, list) or isinstance(f, tuple)
+ specList = f
+ def decorator(f):
+ return _wrap(f, specList, *args, **kwargs)
+ return decorator
wrap.__doc__ = """Useful wrapper for plugin commands.
Valid converters are: %s.
Please sign in to comment.
Something went wrong with that request. Please try again.