def _render_expression(self, check):
expressions = []<EOL>args = []<EOL>skeys = set(check.keys())<EOL>skeys.difference_update(set(self._keys))<EOL>skeys.difference_update(set(['<STR_LIT>', '<STR_LIT>']))<EOL>if skeys:<EOL><INDENT>raise KeyError("<STR_LIT>"%skeys)<EOL><DEDENT>for name,sub_check in check.iteritems():<EOL><INDENT>if isinstance(sub_check, dict):<EOL><INDENT>for test,value in sub_check.iteritems():<EOL><INDENT>try:<EOL><INDENT>op = operators[test]<EOL><DEDENT>except KeyError:<EOL><INDENT>raise KeyError("<STR_LIT>"%test)<EOL><DEDENT>if isinstance(op, tuple):<EOL><INDENT>op, join = op<EOL><DEDENT>if value is None and op in null_operators:<EOL><INDENT>expr = "<STR_LIT>" % (name, null_operators[op])<EOL><DEDENT>else:<EOL><INDENT>expr = "<STR_LIT>"%(name, op)<EOL>if isinstance(value, (tuple,list)):<EOL><INDENT>if op in null_operators and any([v is None for v in value]):<EOL><INDENT>raise ValueError("<STR_LIT>"%test)<EOL><DEDENT>expr = '<STR_LIT>'%( join.join([expr]*len(value)) )<EOL>args.extend(value)<EOL><DEDENT>else:<EOL><INDENT>args.append(value)<EOL><DEDENT><DEDENT>expressions.append(expr)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if sub_check is None:<EOL><INDENT>expressions.append("<STR_LIT>" % name)<EOL><DEDENT>else:<EOL><INDENT>expressions.append("<STR_LIT>"%name)<EOL>args.append(sub_check)<EOL><DEDENT><DEDENT><DEDENT>expr = "<STR_LIT>".join(expressions)<EOL>return expr, args<EOL>
Turn a mongodb-style search dict into an SQL query.