davsclaus commented on code in PR #27525:
URL: https://github.com/apache/camel/pull/27525#discussion_r4220143201
##########
components/camel-python3/src/main/java/org/apache/camel/language/python3/Python3Language.java:
##########
@@ -166,15 +171,29 @@ public <T> T evaluate(String script, Map<String, Object>
bindings, Class<T> resu
Object evaluateExpression(String script, Exchange exchange) {
try (Context cx = Python3Helper.newContext(engine(), hostAccess)) {
Value b = cx.getBindings("python");
- // Default: data only. Do not bind exchange/message/context — they
are undefined (NameError)
- // unless createWithHostAccess() opted into trusted host-object
bindings.
+ Message message = exchange.getMessage();
+ Map<String, Object> headers = message.getHeaders();
+ Map<String, Object> properties = exchange.getAllProperties();
+ Map<String, Object> variables = exchange.getVariables();
+ // Default: data only, with the data names
ExchangeHelper.populateVariableMap gives Groovy. The host objects
+ // are undefined (NameError) unless createWithHostAccess() opted
into trusted host-object bindings.
b.putMember("exchangeId", exchange.getExchangeId());
- b.putMember("headers", exchange.getMessage().getHeaders());
- b.putMember("properties", exchange.getAllProperties());
- b.putMember("body", exchange.getMessage().getBody());
+ b.putMember("body", message.getBody());
+ b.putMember("header", headers);
+ b.putMember("headers", headers);
+ b.putMember("exchangeProperty", properties);
+ b.putMember("exchangeProperties", properties);
+ b.putMember("variable", variables);
+ b.putMember("variables", variables);
+ // deprecated name of exchangeProperties
+ b.putMember("properties", properties);
Review Comment:
Optional: camel-python3 is new in 4.23.0 (it isn't on `camel-4.22.x`), so no
released version ever bound `properties` or `context`. Instead of shipping them
as deprecated aliases in a brand-new language, we could drop them here, at
lines 196-197 for `context`, and in the Javadoc and the deprecated rows of
python3-language.adoc. The upgrade-guide note then only needs to say that
python3 uses the Groovy names. Fine to keep them if you'd rather not break
snapshot users.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]