Skip to content

Commit 4425243

Browse files
committed
Dispatcher.add_method as a decorator generator
1 parent 2a091b4 commit 4425243

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

jsonrpc/dispatcher.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
For usage examples see :meth:`Dispatcher.add_method`
44
55
"""
6+
from . import six
67
import collections
78
from functools import wraps
89

@@ -111,7 +112,20 @@ def add_method(self, f, name=None):
111112
def mymethod(*args, **kwargs):
112113
print(args, kwargs)
113114
115+
>>> @d.add_method(name='MyMethod')
116+
def mymethod(*args, **kwargs):
117+
print(args, kwargs)
118+
114119
"""
120+
if isinstance(f, six.string_types):
121+
name, f = f, name
122+
123+
if f is None:
124+
# Be decorator generator
125+
def _add_method(f):
126+
return self.add_method(f, name)
127+
return _add_method
128+
115129
self[name or f.__name__] = f
116130
return f
117131

0 commit comments

Comments
 (0)