decorators: add to_iter() decorator to transform any generator into an iterable object

This commit is contained in:
Benjamin Dauvergne 2014-04-17 16:23:54 +02:00
parent eba089ceaa
commit 1b7148af20
1 changed files with 8 additions and 0 deletions

View File

@ -2,6 +2,8 @@ from django.contrib.auth.decorators import login_required
from django.http import HttpResponseRedirect
from functools import wraps
from . import utils
TRANSIENT_USER_TYPES = []
def is_transient_user(user):
@ -21,3 +23,9 @@ def to_list(func):
def f(*args, **kwargs):
return list(func(*args, **kwargs))
return f
def to_iter(func):
@wraps(func)
def f(*args, **kwargs):
return utils.IterableFactory(lambda: func(*args, **kwargs))
return f