MCPcopy
hub / github.com/ponyorm/pony / apply_lambda

Method apply_lambda

pony/orm/sqltranslation.py:901–953  ·  view source on GitHub ↗
(translator, func_id, filter_num, order_by, func_ast, argnames, original_names, extractors, vars, vartypes)

Source from the content-addressed store, hash-verified

899 for m in monads: translator.conditions.extend(m.getsql())
900 return translator
901 def apply_lambda(translator, func_id, filter_num, order_by, func_ast, argnames, original_names, extractors, vars, vartypes):
902 translator = translator.deepcopy()
903 func_ast = copy_ast(func_ast) # func_ast = deepcopy(func_ast)
904 translator.code_key = func_id
905 translator.filter_num = filter_num
906 translator.extractors.update(extractors)
907 translator.vars = vars
908 translator.vartypes = translator.vartypes.copy() # make HashableDict mutable again
909 translator.vartypes.update(vartypes)
910
911 if not original_names:
912 assert argnames
913 namespace = {name: monad for name, monad in zip(argnames, translator.expr_monads)}
914 elif argnames:
915 namespace = {name: translator.namespace[name] for name in argnames}
916 else:
917 namespace = None
918 if namespace is not None:
919 translator.namespace_stack.append(namespace)
920 try:
921 with translator:
922 translator.dispatch(func_ast)
923 if isinstance(func_ast, ast.Tuple):
924 nodes = func_ast.elts
925 else:
926 nodes = (func_ast,)
927 if order_by:
928 translator.inside_order_by = True
929 new_order = []
930 for node in nodes:
931 monad = node.monad.to_single_cell_value()
932 if isinstance(monad, SetMixin):
933 t = monad.type.item_type
934 if isinstance(type(t), type): t = t.__name__
935 throw(TranslationError, 'Set of %s (%s) cannot be used for ordering'
936 % (t, ast2src(node)))
937 new_order.extend(node.monad.getsql())
938 translator.order[:0] = new_order
939 translator.inside_order_by = False
940 else:
941 for node in nodes:
942 monad = node.monad
943 if isinstance(monad, AndMonad): cond_monads = monad.operands
944 else: cond_monads = [ monad ]
945 for m in cond_monads:
946 if not m.aggregated: translator.conditions.extend(m.getsql())
947 else: translator.having_conditions.extend(m.getsql())
948 translator.vars = None
949 return translator
950 finally:
951 if namespace is not None:
952 ns = translator.namespace_stack.pop()
953 assert ns is namespace
954 def preGeneratorExp(translator, node):
955 translator_cls = translator.__class__
956 try:

Callers 1

_process_lambdaMethod · 0.80

Calls 11

copy_astFunction · 0.90
throwFunction · 0.90
ast2srcFunction · 0.90
deepcopyMethod · 0.80
appendMethod · 0.80
extendMethod · 0.80
updateMethod · 0.45
copyMethod · 0.45
dispatchMethod · 0.45
to_single_cell_valueMethod · 0.45
getsqlMethod · 0.45

Tested by

no test coverage detected