public final class PyExprUtils extends Object
Important: This class may only be used in implementing plugins (e.g. functions, directives).
| Modifier and Type | Field and Description |
|---|---|
static String |
TRANSLATOR_NAME
The variable name used to reference the current translator instance.
|
| Modifier and Type | Method and Description |
|---|---|
static PyExpr |
concatPyExprs(List<? extends PyExpr> pyExprs)
Builds one Python expression that computes the concatenation of the given Python expressions.
|
static PyExpr |
convertIterableToPyListExpr(Iterable<?> iterable)
Convert a java Iterable object to valid PyExpr as array.
|
static PyExpr |
convertIterableToPyTupleExpr(Iterable<?> iterable)
Convert a java Iterable object to valid PyExpr as tuple.
|
static PyExpr |
convertMapToOrderedDict(Map<PyExpr,PyExpr> dict)
Convert a java Map to valid PyExpr as dict.
|
static PyExpr |
convertMapToPyExpr(Map<PyExpr,PyExpr> dict)
Convert a java Map to valid PyExpr as dict.
|
static PyExpr |
genPyNotNullCheck(PyExpr pyExpr)
Generates a Python not null (None) check expression for the given
PyExpr. |
static PyExpr |
genPyNullCheck(PyExpr expr)
Generates a Python null (None) check expression for the given
PyExpr. |
static PyExpr |
maybeProtect(PyExpr expr,
int minSafePrecedence)
Wraps an expression with parenthesis if it's not above the minimum safe precedence.
|
static int |
pyPrecedenceForOperator(Operator op)
Provide the Python operator precedence for a given operator.
|
static PyExpr |
wrapAsSanitizedContent(SanitizedContent.ContentKind contentKind,
PyExpr pyExpr)
Wraps an expression with the proper SanitizedContent constructor.
|
public static final String TRANSLATOR_NAME
public static PyExpr concatPyExprs(List<? extends PyExpr> pyExprs)
Python doesn't allow arbitrary concatentation between types, so to ensure type safety and consistent behavior, coerce all expressions to Strings before joining them. Python's array joining mechanism is used in place of traditional concatenation to improve performance.
pyExprs - The Python expressions to concatenate.public static PyExpr genPyNotNullCheck(PyExpr pyExpr)
PyExpr.public static PyExpr genPyNullCheck(PyExpr expr)
PyExpr.public static PyExpr maybeProtect(PyExpr expr, int minSafePrecedence)
NOTE: For the sake of brevity, this implementation loses typing information in the expressions.
expr - The expression to wrap.minSafePrecedence - The minimum safe precedence (not inclusive).public static PyExpr wrapAsSanitizedContent(SanitizedContent.ContentKind contentKind, PyExpr pyExpr)
NOTE: The pyExpr provided must be properly escaped for the given ContentKind. Please talk to ISE (ise@) for any questions or concerns.
contentKind - The kind of sanitized content.pyExpr - The expression to wrap.public static int pyPrecedenceForOperator(Operator op)
op - The operator.public static PyExpr convertIterableToPyListExpr(Iterable<?> iterable)
iterable - Iterable of Objects to be converted to PyExpr, it must be Number, PyExpr or
String.public static PyExpr convertIterableToPyTupleExpr(Iterable<?> iterable)
iterable - Iterable of Objects to be converted to PyExpr, it must be Number, PyExpr or
String.public static PyExpr convertMapToOrderedDict(Map<PyExpr,PyExpr> dict)
dict - A Map to be converted to PyExpr as a dictionary, both key and value should be
PyExpr.