Contact: fumanchu@aminus.org

Log in as guest/geniusql to create tickets

Changeset 216

Show
Ignore:
Timestamp:
11/05/07 23:20:44
Author:
fumanchu
Message:

logic.filter now allows an empty dict. Also a Py2.5 bugfix.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/geniusql/logic.py

    r214 r216  
    284284            if isinstance(func, dict): 
    285285                func = _filter_func(**func) 
    286                 earlybind = False 
     286                # It might be tempting to set earlybind to False, since 
     287                # we've hand-generated our func, but we need to change 
     288                # e.g. lambda: True from a Global to a Const so we don't 
     289                # end up with the ast: Name('True'). 
    287290            self.func = func 
    288291            lp = astwalk.LambdaParser(func, env=builtins, reduce=earlybind) 
     
    380383 
    381384def _filter_func(**kwargs): 
    382     items = kwargs.items() 
     385    """Return a new function object from the given kwargs. 
     386     
     387    The new function will be of the form: 
     388        lambda x: k1 == v1 and k2 == v2... 
     389     
     390    unless kwargs is empty, in which case it will be: 
     391        lambda x: True 
     392    """ 
     393    if not kwargs: 
     394        return lambda x: True 
     395     
    383396    co = [] 
    384397    kwlen = len(kwargs) 
     
    398411    co.append(83) 
    399412     
    400     items = [('x', None)] + items 
    401     names, consts = zip(*items) 
     413    if sys.version_info >= (2, 5): 
     414        # 2.5 doesn't include arguments in co_names anymore 
     415        names = tuple(kwargs.keys()) 
     416    else: 
     417        names = tuple(['x'] + kwargs.keys()) 
     418    consts = tuple([None] + kwargs.values()) 
    402419     
    403420    # Form code object and function.