PYSON#
PYSON is the Python Statement and Object Notation.
There is also a more practical introduction into PYSON statements.
- class trytond.pyson.PYSON#
Base class of any PYSON statement. It is never used directly.
Instance methods:
- PYSON.pyson()#
Return the internal dictionary representation of the statement.
- PYSON.types()#
Return a set of all possible types which the statement can become when evaluated.
Class methods:
- classmethod PYSON.eval(dct, context)#
Return the evaluation of the statement given in
dctwithin thecontext.dctcontains a dictionary which is the internal representation of a PYSON statement.contextcontains a dictionary with contextual values.
Encoder and Decoder#
- class trytond.pyson.PYSONEncoder#
Encoder for PYSON statements into string representations.
Instance methods:
- PYSONEncoder.encode(object)#
Return a string representation of a given PYSON statement.
objectcontains a PYSON statement.
- class trytond.pyson.PYSONDecoder([context[, noeval]])#
Decoder for string into the evaluated or not PYSON statement.
Instance methods:
- PYSONDecoder.decode(object)#
Return a PYSON statement evaluated or not of a given string.
objectcontains a string.
Statements#
The following classes can be used as PYSON statement:
Eval#
- class trytond.pyson.Eval(value[, default])#
Represent the PYSON statement for evaluations.
When evaluated, it returns the value of the statement named by
value, if defined in the evaluation context, otherwise thedefaultvalue (empty string by default).Note
The default value determines the type of the statement.
Note
If the
valueincludes dots the value will be dereferenced. For example:Eval('_parent_sale.number')The
numbervalue of the_parent_salekey of the evaluation context will be returned.
Not#
- class trytond.pyson.Not(value)#
Represent the PYSON statement for logical negations.
When evaluated, returns the boolean negation of the value of the statement named by
value, if defined in the evaluation context. Returns an instance of itself.
Bool#
- class trytond.pyson.Bool(value)#
Represent the PYSON statement for boolean evaluations.
Returns the boolean representation of the value of the statement named by
value.
And#
- class trytond.pyson.And(\*statements)#
Represent the PYSON statement for logical and operations.
Returns the result of the logical conjunction of two or more values named by the statements in the
statementstuple.
Or#
- class trytond.pyson.Or(\*statements)#
Represent the PYSON statement for logical or operations.
Returns the result of the logical disjunction of two or more values named by the statements in the
statementstuple.
Equal#
- class trytond.pyson.Equal(statement1, statement2)#
Represent the PYSON statement for equation comparisons.
Returns
Truewhen a value of a statement named bystatement1and the value of a statement named bystatement2are equal, otherwise returnsFalse.
Greater#
- class trytond.pyson.Greater(statement1, statement2[, equal])#
Represent the PYSON statement for greater-than comparisons.
Returns
Truewhen the value of the statement named bystatement1is strictly greater than the value of the statement named bystatement2, otherwise returns false. Is the value of the variable named byequalisTrue, then returns alsoTruewhen both values of statements named bystatement1andstatement2are equal. In this caseGreaterworks as a greater-than or equal operator.Note
Nonevalue is replaced by0for the comparison.
Less#
- class trytond.pyson.Less(statement1, statement2[, equal])#
Represent the PYSON statement for less-than comparisons.
Returns
Truewhen the value of the statement named bystatement1is strictly less than the value of the statement named bystatement2, otherwise returnsFalse. Is the value of the variable namedequalis true, then returns also true when both values of the statements named bystatement1andstatement2are equal. In this caseLessworks as a less-than or equal operator.Note
Nonevalue is replaced by0for the comparison.
If#
- class trytond.pyson.If(condition, then_statement, else_statement)#
Represent the PYSON statement for conditional flow control operations.
Returns the value of the statement named by
then_statementwhen the value of the statement named byconditionevaluates true. Otherwise returns the value of the statement named byelse_statement.
Get#
- class trytond.pyson.Get(obj, key[, default])#
Represent the PYSON statement for dictionary look-up operations and evaluation.
Look up and returns the value of a key named by
keyin an object named byobjif defined. Otherwise returns the value of the variable named bydefault.
In#
- class trytond.pyson.In(key, obj)#
Represent the PYSON statement for look-up dictionary or integer objects.
Returns true when a list (or dictionary) object named by
objcontains the value of the variable (or key) named bykey. Otherwise returns false.
Date#
- class trytond.pyson.Date([year[, month[, day[, delta_years[, delta_month[, delta_days[, start]]]]]]])#
Represent the PYSON statement for date related conversions and basic calculations.
Returns a date object which represents the values of arguments named by the variables explained below. Missing values of arguments named by
yearormonthordaytake their defaults fromstartor the actual date. When values of arguments named bydelta_*are given, they are added to the values of the appropriate arguments in a date and time preserving manner.Arguments:
yearA PYSON statement of type int or long.
monthA PYSON statement of type int or long.
dayA PYSON statement of type int or long.
delta_yearsA PYSON statement of type int or long.
delta_monthA PYSON statement of type int or long.
delta_daysA PYSON statement of type int or long.
startA PYSON statement of type date.
DateTime#
- class trytond.pyson.DateTime([year[, month[, day[, hour[, minute[, second[, microsecond[, delta_years[, delta_months[, delta_days[, delta_hours[, delta_minutes[, delta_seconds[, delta_microseconds[, start]]]]]]]]]]]]]]])#
Represent the PYSON statement for date and time related conversions and calculations.
Returns a date time object which represents the values of variables named by the arguments explained below. Missing values of arguments named by
year,month,day,hour,minute,second,microsecondstake their defaults fromstartor the actual date and time in UTC. When values of arguments named bydelta_*are given, these are added to the appropriate attributes in a date and time preserving manner.Arguments:
yearA PYSON statement of type int or long.
monthA PYSON statement of type int or long.
dayA PYSON statement of type int or long.
hourA PYSON statement of type int or long.
minuteA PYSON statement of type int or long.
secondA PYSON statement of type int or long.
microsecondA PYSON statement of type int or long.
delta_yearsA PYSON statement of type int or long.
delta_monthA PYSON statement of type int or long.
delta_daysA PYSON statement of type int or long.
delta_hoursA PYSON statement of type int or long.
delta_minutesA PYSON statement of type int or long.
delta_secondsA PYSON statement of type int or long.
delta_microsecondsA PYSON statement of type int or long.
startA PYSON statement of type datetime.
Len#
- class trytond.pyson.Len(value)#
Represent the PYSON statement for length of a dictionary, list or string.
Returns the number of items in
value.
Id#
- class trytond.pyson.Id(module, fs_id)#
Represent the PYSON statement for filesystem id evaluations.
When converted into the internal dictionary, it returns the database id stored in
ir.model.data.