PYSON is the PYthon Statement and Object Notation.
There is also a more practical introduction into PYSON statements.
trytond.pyson.
PYSON
¶Base class of any PYSON statement. It is never used directly.
Instance methods:
PYSON.
pyson
()¶Method that returns the internal dictionary representation of the statement.
PYSON.
types
()¶Method that returns a set of all possible types which the statement can become when evaluated.
PYSON.
eval
(dct, context)¶Method which returns the evaluation of the statement given in
dct
within the context
. dct
contains a
dictionary which is the internal representation of a PYSON
statement. context
contains a dictionary with contextual
values.
trytond.pyson.
PYSONEncoder
¶Encoder for PYSON statements into string representations.
Instance method:
PYSONEncoder.
encode
(object)¶Returns a string representation of a given PYSON statement.
object
contains a PYSON statement.
trytond.pyson.
PYSONDecoder
([context[, noeval]])¶Decoder for string into the evaluated or not PYSON statement.
Instance method:
PYSONDecoder.
decode
(object)¶Returns a PYSON statement evaluated or not of a given string.
object
contains a string.
The following statements can be used in PYSON
.
trytond.pyson.
Eval
(value[, default])¶An Eval()
object represents the PYSON Eval()
statement for evaluations. When evaluated, it returns the
value of the statement named by value
, if defined in the
evaluation context, otherwise the default
value (empty
string by default). Returns an instance of itself.
Note
The default value determines the type of the statement.
trytond.pyson.
Not
(value)¶A Not
object represents the PYSON Not()
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.
trytond.pyson.
Bool
(value)¶A Bool
object represents the PYSON Bool()
statement for boolean evaluations. Returns the boolean
representation of the value of the statement named by
value
.
trytond.pyson.
And
(*statements)¶An And
object represents the PYSON And()
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.
trytond.pyson.
Or
(*statements)¶An Or
object represents the PYSON Or()
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.
trytond.pyson.
Equal
(statement1, statement2)¶An Equal
object represents the PYSON Equal()
statement for equation comparisons. Returns true when a value of
a statement named by statement1
and the value of a statement
named by statement2
are equal, otherwise returns false.
trytond.pyson.
Greater
(statement1, statement2[, equal])¶A Greater
object represents the PYSON Greater()
statement for greater-than comparisons. Returns true when the value
of the statement named by statement1
is strictly greater than the
value of the statement named by statement2
, otherwise
returns false. Is the value of the variable named by equal
is
true, then returns also true when both values of statements named by
statement1
and statement2
are equal. In this case
Greater
works as a greater-than or equal operator.
Note
None value is replaced by 0 for the comparison.
trytond.pyson.
Less
(statement1, statement2[, equal])¶A Less
object represents the PYSON Less()
statement for less-than comparisons. Returns true when the value
of the statement named by statement1
is strictly less than the
value of the statement named by statement2
, otherwise
returns false. Is the value of the variable named equal
is true,
then returns also true when both values of the statements named by
statement1
and statement2
are equal. In this case
Less
works as a less-than or equal operator.
Note
None value is replaced by 0 for the comparison.
trytond.pyson.
If
(condition, then_statement, else_statement)¶An If
object represents the PYSON If()
statement for conditional flow control operations. Returns the
value of the statement named by then_statement
when the value
of the statement named by condition
evaluates true.
Otherwise returns the value of the statement named by
else_statement
.
trytond.pyson.
Get
(obj, key[, default])¶A Get
object represents the PYSON Get()
statement for dictionary look-up operations and evaluation.
Look up and returns the value of a key named by key
in an
object named by obj
if defined.
Otherwise returns the value of the variable named by default
.
trytond.pyson.
In
(key, obj)¶An In
object represents the PYSON In()
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 by key
. Otherwise returns false.
trytond.pyson.
Date
([year[, month[, day[, delta_years[, delta_month[, delta_days]]]]]])¶A Date
object represents the PYSON Date()
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
or month
or
day
take their defaults from the actual date. When values of
arguments named by delta_*
are given, they are added to the
values of the appropriate arguments in a date and time preserving
manner.
Arguments:
year
month
day
delta_years
delta_month
delta_days
trytond.pyson.
DateTime
([year[, month[, day[, hour[, minute[, second[, microsecond[, delta_years[, delta_months[, delta_days[, delta_hours[, delta_minutes[, delta_seconds[, delta_microseconds]]]]]]]]]]]]]])¶A DateTime
object represents the PYSON Date()
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 from the actual date and time.
When values of arguments named by delta_*
are given, these are
added to the appropriate attributes in a date and time preserving
manner.
Arguments:
year
month
day
hour
minute
second
microsecond
delta_years
delta_month
delta_days
delta_hours
delta_minutes
delta_seconds
delta_microseconds
trytond.pyson.
Len
(value)¶A Len
object represents the PYSON Len()
statement for length of a
dictionary, list or string. Returns the number of items in value
.
trytond.pyson.
Id
(module, fs_id)¶An Id
object represents the PYSON Id()
statement for filesystem id
evaluations. When converted into the internal dictionary, it returns the
database id stored in ir.model.data.