| 8 | | def _decorator_from_middleware(view_func, *args, **kwargs): |
|---|
| | 10 | def _decorator_from_middleware(*args, **kwargs): |
|---|
| | 11 | has_func = True |
|---|
| | 12 | try: |
|---|
| | 13 | view_func = kwargs.pop('view_func') |
|---|
| | 14 | except KeyError: |
|---|
| | 15 | if len(args): |
|---|
| | 16 | view_func, args = args[0], args[1:] |
|---|
| | 17 | else: |
|---|
| | 18 | has_func = False |
|---|
| | 19 | if not (has_func and isinstance(view_func, types.FunctionType)): |
|---|
| | 20 | # For historical reasons, these decorators are also called as |
|---|
| | 21 | # dec(func, *args) instead of dec(*args)(func). This branch handles |
|---|
| | 22 | # the backwards compatibility. |
|---|
| | 23 | if has_func: |
|---|
| | 24 | args = (view_func,) + args |
|---|
| | 25 | middleware = middleware_class(*args, **kwargs) |
|---|
| | 26 | |
|---|
| | 27 | def decorator_func(fn): |
|---|
| | 28 | return _decorator_from_middleware(fn, *args, **kwargs) |
|---|
| | 29 | return decorator_func |
|---|
| | 30 | |
|---|