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
dct
within thecontext
.dct
contains a dictionary which is the internal representation of a PYSON statement.context
contains 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.
object
contains 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.
object
contains 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 thedefault
value (empty string by default).Note
The default value determines the type of the statement.
Note
If the
value
includes dots the value will be dereferenced. For example:Eval('_parent_sale.number')
The
number
value of the_parent_sale
key 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
statements
tuple.
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
statements
tuple.
Equal¶
- class trytond.pyson.Equal(statement1, statement2)¶
Represent the PYSON statement for equation comparisons.
Returns
True
when a value of a statement named bystatement1
and the value of a statement named bystatement2
are equal, otherwise returnsFalse
.
Greater¶
- class trytond.pyson.Greater(statement1, statement2[, equal])¶
Represent the PYSON statement for greater-than comparisons.
Returns
True
when the value of the statement named bystatement1
is strictly greater than the value of the statement named bystatement2
, otherwise returns false. Is the value of the variable named byequal
isTrue
, then returns alsoTrue
when both values of statements named bystatement1
andstatement2
are equal. In this caseGreater
works as a greater-than or equal operator.Note
None
value is replaced by0
for the comparison.
Less¶
- class trytond.pyson.Less(statement1, statement2[, equal])¶
Represent the PYSON statement for less-than comparisons.
Returns
True
when the value of the statement named bystatement1
is strictly less than the value of the statement named bystatement2
, otherwise returnsFalse
. Is the value of the variable namedequal
is true, then returns also true when both values of the statements named bystatement1
andstatement2
are equal. In this caseLess
works as a less-than or equal operator.Note
None
value is replaced by0
for 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_statement
when the value of the statement named bycondition
evaluates 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
key
in an object named byobj
if 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
obj
contains 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
year
ormonth
orday
take their defaults fromstart
or 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:
year
A PYSON statement of type int or long.
month
A PYSON statement of type int or long.
day
A PYSON statement of type int or long.
delta_years
A PYSON statement of type int or long.
delta_month
A PYSON statement of type int or long.
delta_days
A PYSON statement of type int or long.
start
A 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
,microseconds
take their defaults fromstart
or 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:
year
A PYSON statement of type int or long.
month
A PYSON statement of type int or long.
day
A PYSON statement of type int or long.
hour
A PYSON statement of type int or long.
minute
A PYSON statement of type int or long.
second
A PYSON statement of type int or long.
microsecond
A PYSON statement of type int or long.
delta_years
A PYSON statement of type int or long.
delta_month
A PYSON statement of type int or long.
delta_days
A PYSON statement of type int or long.
delta_hours
A PYSON statement of type int or long.
delta_minutes
A PYSON statement of type int or long.
delta_seconds
A PYSON statement of type int or long.
delta_microseconds
A PYSON statement of type int or long.
start
A 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
.