def _render_expression(self, check):
        """Turn a mongodb-style search dict into an SQL query."""
        expressions = []
        args = []
        
        skeys = set(check.keys())
        skeys.difference_update(set(self._keys))
        skeys.difference_update(set(['buffers', 'result_buffers']))
        if skeys:
            raise KeyError("Illegal testing key(s): %s"%skeys)
        
        for name,sub_check in check.items():
            if isinstance(sub_check, dict):
                for test,value in sub_check.items():
                    try:
                        op = operators[test]
                    except __HOLE__:
                        raise KeyError("Unsupported operator: %r"%test)
                    if isinstance(op, tuple):
                        op, join = op
                    
                    if value is None and op in null_operators:
                            expr = "%s %s"%null_operators[op]
                    else:
                        expr = "%s %s ?"%(name, op)
                        if isinstance(value, (tuple,list)):
                            if op in null_operators and any([v is None for v in value]):
                                # equality tests don't work with NULL
                                raise ValueError("Cannot use %r test with NULL values on SQLite backend"%test)
                            expr = '( %s )'%( join.join([expr]*len(value)) )
                            args.extend(value)
                        else:
                            args.append(value)
                    expressions.append(expr)
            else:
                # it's an equality check
                if sub_check is None:
                    expressions.append("%s IS NULL")
                else:
                    expressions.append("%s = ?"%name)
                    args.append(sub_check)
        
        expr = " AND ".join(expressions)
        return expr, args
dataset/ETHPy150Open ipython/ipython-py3k/IPython/parallel/controller/sqlitedb.py/SQLiteDB._render_expression