Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(99)

Delta Between Two Patch Sets: doc/ref/pyson.rst

Issue 975044: PYSON doc (Closed)
Left Patch Set: Overwork doc Created 14 years, 11 months ago
Right Patch Set: fix last issues Created 14 years, 11 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | doc/topics/pyson.rst » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 .. _ref-pyson: 1 .. _ref-pyson:
2 .. module:: trytond.pyson 2 .. module:: trytond.pyson
3 3
4 ===== 4 =====
5 PYSON 5 PYSON
6 ===== 6 =====
7 7
8 PYSON is the Python statement and object notation.· 8
9 PYSON is the PYthon Statement and Object Notation.
10
11 There is also a more :ref:`practical introduction into
12 PYSON statements <topics-pyson>`.
9 13
10 .. class:: PYSON 14 .. class:: PYSON
11 15
12 Base class of any PYSON statement. It is never used directly. 16 Base class of any PYSON statement. It is never used directly.
13 17
14 Instance methods: 18 Instance methods:
15 19
16 .. method:: PYSON.pyson() 20 .. method:: PYSON.pyson()
17 21
18 Method that returns the dictionary representation of the statement. 22 Method that returns the internal dictionary representation of the
23 statement.
19 24
20 .. method:: PYSON.types() 25 .. method:: PYSON.types()
21 26
22 Method that returns all possible types which the statement can become 27 Method that returns a set of all possible types which the statement
23 when evaluated. 28 can become when evaluated.
24 29
25 .. classmethod:: PYSON.eval(dct, context) 30 .. classmethod:: PYSON.eval(dct, context)
26 31
27 Method which returns the evaluation of the statement given in· 32 Method which returns the evaluation of the statement given in
28 :attr:`eval.dct` within the :attr:`eval.context`.· 33 ``dct`` within the ``context``. ``dct`` contains a
29 34 dictionary which is the internal representation of a PYSON
30 Attributes: 35 statement. ``context`` contains a dictionary with contextual
31 36 values.
32 .. attribute:: eval.dct 37
33 38
34 Contains a dictionary with statements to evaluate. 39 Encoder and Decoder
35 40 ===================
36 .. attribute:: eval.context 41
37 42 .. class:: PYSONEncoder()
38 Contains a dictionary with the evaluation context. 43
39 44 Encoder for PYSON statements into string representations.
40
41 ============
42 PYSONEncoder
43 ============
44
45 .. class:: pyson.PYSONEncoder
46
47 Encoder for PYSON statements into string representations.
48 45
49 Instance method: 46 Instance method:
50 47
51 .. method:: pyson.PYSONEncoder.encode(object) 48 .. method:: PYSONEncoder.encode(object)
52 49
53 Returns a string representation of a given PYSON statement. 50 Returns a string representation of a given PYSON statement.
54 51 ``object`` contains a PYSON statement.
55 Attribute: 52
56 53 .. class:: PYSONDecoder()
57 .. attribute:: encode.object 54
58 55 Decoder for string into PYSON statement representation.
59 Contains a PYSON statement. 56
60 57 Instance method:
61 58
62 ========== 59 .. method:: PYSONDecoder.decode(object)
60
61 Returns a PYSON statement representation of a given string.
62 ``object`` contains a string.
63
63 Statements 64 Statements
64 ========== 65 ==========
65 66
66 The following statements are implemented in :class:`PYSON`. 67 The following statements can be used in :class:`PYSON`.
67 There is also an overview introduction into·
68 :ref:`PYSON statements <topics-pyson>`.
69
70
71 Eval
72 ====
73
74 An :class:`Eval()` object represents the PYSON ``Eval()``·
75 statement for evaluation.
76 68
77 .. class:: Eval(value[, default]) 69 .. class:: Eval(value[, default])
78 70
79 Returns :attr:`Eval.value` if defined in the evaluation context,· 71 An :class:`Eval()` object represents the PYSON ``Eval()``
80 or the optional :attr:`Eval.default`. 72 statement for evaluations. When evaluated, it returns the
81 73 value of the statement named by ``value``, if defined in the
82 Class attributes: 74 evaluation context, otherwise the ``default`` value (empty
83 75 string by default). ``value`` can use the dot notation to
84 .. attribute:: Eval.value 76 access objects values in the context. Returns an instance of
85 77 itself.
86 It contains a PYSON statement.
87
88 .. attribute:: Eval.default
89
90 It contains a default value or ``''``.
91
92
93 Not
94 ===
95
96 A :class:`Not` object represents the PYSON ``Not()``·
97 operator for boolean operation.
98 78
99 .. class:: Not(value) 79 .. class:: Not(value)
100 80
101 Returns the logical negation of :attr:`Not.value`. 81 A :class:`Not` object represents the PYSON ``Not()``
102 82 statement for logical negations. When evaluated, returns
103 Class attribute: 83 the boolean negation of the value of the statement named by
104 84 ``value``, if defined in the evaluation context. Returns an
105 .. attribute:: Not.value 85 instance of itself.
106
107 Contains a PYSON statement of type boolean.
108
109
110 Bool
111 ====
112
113 A :class:`Bool` object represents the PYSON ``Bool()``·
114 statement for boolean evaluation.
115 86
116 .. class:: Bool(value) 87 .. class:: Bool(value)
117 88
118 Returns the boolean representation of :attr:`Bool.value` 89 A :class:`Bool` object represents the PYSON ``Bool()``
119 90 statement for boolean evaluations. Returns the boolean
120 Class attribute: 91 representation of the value of the statement named by
121 92 ``value``.
122 .. attribute:: Bool.value
123
124 Contains a PYSON statement which can be evaluated to boolean.
125
126
127 And
128 ===
129
130 An :class:`And` object represents the PYSON ``And()``·
131 operator for boolean operation.
132 93
133 .. class:: And(\*statements) 94 .. class:: And(\*statements)
134 95
135 Returns the result of the logical conjuction of two or more· 96 An :class:`And` object represents the PYSON ``And()``
136 :attr:`And.statements` . 97 statement for logical *and* operations. Returns the result of
137 98 the logical conjunction of two or more values named by the
138 Class attribute: 99 statements in the ``statements`` tuple.
139
140 .. attribute:: And.statements
141
142 Contains a tuple with two or more PYSON statements of type boolean.
143
144
145 Or
146 ==
147
148 An :class:`Or` object represents the PYSON ``Or()``·
149 operator for boolean operation.
150 100
151 .. class:: Or(\*statements) 101 .. class:: Or(\*statements)
152 102
153 Returns the result of the logical disjunction of two or more· 103 An :class:`Or` object represents the PYSON ``Or()``
154 PYSON :attr:`Or.statements`. 104 statement for logical *or* operations. Returns the result of
155 105 the logical disjunction of two or more values named by the
156 106 statements in the ``statements`` tuple.
157 Class attribute: 107
158 108 .. class:: Equal(statement1, statement2)
159 .. attribute:: Or.statements 109
160 110 An :class:`Equal` object represents the PYSON ``Equal()``
161 Contains a tuple with two or more PYSON statements of type boolean. 111 statement for equation comparisons. Returns true when a value of
162 112 a statement named by ``statement1`` and the value of a statement
163 113 named by ``statement2`` are equal, otherwise returns false.
164 Equal
165 =====
166
167 An :class:`Equal` object represents the PYSON ``Equal()``·
168 operator for comparison.
169
170 .. class:: Equal(statemant1, statement2)
171
172 Returns true when :attr:`statement1` and :attr:`statement2` are·
173 equal, otherwise returns false.
174
175 Class attribute:
176
177 .. attribute:: Equal.statement1
178
179 Contains a PYSON statement of the same type as :attr:`statement2`.
180
181 .. attribute:: Equal.statement2
182
183 Contains a PYSON statement of the same type as :attr:`statement1`.
184
185
186 Greater
187 =======
188
189 A :class:`Greater` object represents the PYSON ``Greater()``·
190 operator for comparison.
191 114
192 .. class:: Greater(statement1, statement2[, equal]) 115 .. class:: Greater(statement1, statement2[, equal])
193 116
194 Returns true when :attr:`Greater.statement1` is strictly greater than· 117 A :class:`Greater` object represents the PYSON ``Greater()``
195 :attr:`Greater.statement2`, otherwise returns false.· 118 statement for *greater-than* comparisons. Returns true when the value
196 ··· 119 of the statement named by ``statement1`` is strictly greater than the
197 When :attr:`Greater.equal` is true:· 120 value of the statement named by ``statement2``, otherwise
198 Returns true when :attr:`Greater.statement1`is greater than· 121 returns false. Is the value of the variable named by ``equal`` is·
199 or equal :attr:`Greater.statement2`, otherwise returns false.· 122 true, then returns also true when both values of statements named by
200 123 ``statement1`` and ``statement2`` are equal. In this case
201 Class attribute: 124 :class:`Greater` works as a *greater-than or equal* operator.
202
203 .. attribute:: Greater.statement1
204
205 The left hand side statement of type long, integer or float.
206
207 .. attribute:: Greater.statement2
208
209 The right hand side statement of type long, integer or float.
210
211 .. attribute:: Greater.equal
212
213 Contains a boolean. When set true *greater than or equal* operation
214 is used for comparison, otherwise *strictly greater than* (default).
215
216
217 Less
218 ====
219
220 A :class:`Less` object represents the PYSON ``Less()``·
221 operator for comparison.
222 125
223 .. class:: Less(statement1, statement2[, equal]) 126 .. class:: Less(statement1, statement2[, equal])
224 127
225 Returns true when :attr:`Less.statement1` is strictly less than· 128 A :class:`Less` object represents the PYSON ``Less()``
226 :attr:`Less.statement2`, otherwise returns false.· 129 statement for *less-than* comparisons. Returns true when the value
227 ··· 130 of the statement named by ``statement1`` is strictly less than the
228 When :attr:`Less.equal` is true: 131 value of the statement named by ``statement2``, otherwise
229 Returns true when :attr:`Less.statement1`is less than or equal· 132 returns false. Is the value of the variable named ``equal`` is true,
230 :attr:`Less.statement2`, otherwise returns false.· 133 then returns also true when both values of the statements named by
231 134 ``statement1`` and ``statement2`` are equal. In this case
232 .. attribute:: Less.statement1 135 :class:`Less` works as a *less-than or equal* operator.
233
234 Contains a PYSON statement of type long, integer or float.
235
236 .. attribute:: Less.statement2
237
238 Contains a PYSON statement of type long, integer or float.
239
240 .. attribute:: Less.equal
241
242 Contains a PYSON statement of type boolean. When set true,·
243 *less than or equal* operation is used for comparison,·
244 otherwise *strictly less than* (default).
245
246
247 If
248 ==
249
250 An :class:`If` object represents the PYSON ``If()`` statement for·
251 conditional flow control.
252 136
253 .. class:: If(condition, then_statement, else_statement) 137 .. class:: If(condition, then_statement, else_statement)
254 138
255 Returns :attr:`If.then_statement` when :attr:`If.condition` is 139 An :class:`If` object represents the PYSON ``If()``
256 true, otherwise returns :attr:`If.else_statement`. 140 statement for conditional flow control operations. Returns the
257 141 value of the statement named by ``then_statement`` when the value
258 Class attribute: 142 of the statement named by ``condition`` evaluates true.
259 143 Otherwise returns the value of the statement named by
260 .. attribute:: If.condition 144 ``else_statement``.
261
262 Contains a PYSON statement of type boolean.
263
264 .. attribute:: If.then_statement
265
266 Contains a PYSON statement with the same type as·
267 :attr:`If.else_statement` .
268
269
270 .. attribute:: If.else_statement
271
272 Contains a PYSON statement with the same type as·
273 :attr:`If.then_statement` .
274
275
276 Get
277 ===
278
279 A :class:`Get` object represents the PYSON ``Get()`` statement for·
280 dictionary look-ups.
281 145
282 .. class:: Get(obj, key[, default]) 146 .. class:: Get(obj, key[, default])
283 147
284 Look up :attr:`Get.obj` for :attr:`Get.key` and returns· 148 A :class:`Get` object represents the PYSON ``Get()``
285 the value if defined, otherwise returns :attr:`Get.default`. 149 statement for dictionary look-up operations and evaluation.
286 150 Look up and returns the value of a key named by ``key`` in an
287 Class attribute: 151 object named by ``obj`` if defined.
288 152 Otherwise returns the value of the variable named by ``default``.
289 .. attribute:: Get.obj
290
291 Contains a PYSON statement of type dictionary.
292
293 .. attribute:: Get.key
294
295 Contains a PYSON statement of type string.
296
297 .. attribute:: Get.default
298
299 Contains PYSON statement.
300
301
302 In
303 ==
304
305 An :class:`In` object represents the PYSON ``In()``·
306 operator for comparison.
307 153
308 .. class:: In(key, obj) 154 .. class:: In(key, obj)
309 155
310 Returns true when :attr:`In.obj` contains :attr:`In.key`,· 156 An :class:`In` object represents the PYSON ``In()``
311 otherwise returns false. 157 statement for look-up dictionary or integer objects. Returns true when
312 158 a list (or dictionary) object named by ``obj`` contains the value of
313 Class attributes: 159 the variable (or key) named by ``key``. Otherwise returns false.
314
315 .. attribute:: In.key
316
317 Contains a PYSON statement of type string when :attr:`In.obj`·
318 is of type dict. Otherwise contains a PYSON statement of type
319 integer or long.
320
321 .. attribute:: In.obj
322
323 Contains a PYSON statement of type dict or list.
324
325
326 Date
327 ====
328
329 A :class:`Date` object represents the PYSON ``Date()`` statement for
330 date related calculations.
331 160
332 .. class:: Date([year[, month[, day[, delta_years[, delta_month[, delta_days]]]] ]]) 161 .. class:: Date([year[, month[, day[, delta_years[, delta_month[, delta_days]]]] ]])
333 162
334 Returns a datetime.date object which represents the given attributes. 163 A :class:`Date` object represents the PYSON ``Date()``
335 Missing attributes of :attr:`Date.year` or :attr:`Date.month` or· 164 statement for date related conversions and basic calculations.
336 :attr:`day` are defaulted from datetime.date.today(). 165 Returns a date object which represents
337 166 the values of arguments named by the *variables* explained below.
338 When delta_* attributes are given, they are added to the· 167 Missing values of arguments named by ``year`` or ``month`` or
339 appropriate attributes. 168 ``day`` take their defaults from the actual date. When values of
340 ··· 169 arguments named by ``delta_*`` are given, they are added to the
341 Class attributes: 170 values of the appropriate arguments in a date and time preserving
342 171 manner.
343 .. attribute:: Date.year 172
344 173 Arguments:
345 Contains a PYSON statement of type int or long. 174
346 175 ``year``
347 .. attribute:: Date.month 176 Contains a PYSON statement of type int or long.
348 177
349 Contains a PYSON statement of type int or long. 178 ``month``
350 179 Contains a PYSON statement of type int or long.
351 .. attribute:: Date.day 180
352 181 ``day``
353 Contains a PYSON statement of type int or long. 182 Contains a PYSON statement of type int or long.
354 183
355 .. attribute:: Date.delta_years 184 ``delta_years``
356 185 Contains a PYSON statement of type int or long.
357 Contains a PYSON statement of type int or long. 186
358 187 ``delta_month``
359 .. attribute:: Date.delta_month 188 Contains a PYSON statement of type int or long.
360 189
361 Contains a PYSON statement of type int or long. 190 ``delta_days``
362 191 Contains a PYSON statement of type int or long.
363 .. attribute:: Date.delta_days
364
365 Contains a PYSON statement of type int or long.
366
367
368 DateTime
369 ========
370
371 A :class:`Date` object represents the PYSON ``Date()`` statement for
372 date and time related calculations.
373 192
374 .. class:: DateTime([year[, month[, day[, hour[, minute[, second[, microsecond[, delta_years[, delta_months[, delta_days[, delta_hours[, delta_minutes[, delta_s econds[, delta_microseconds]]]]]]]]]]]]]]) 193 .. class:: DateTime([year[, month[, day[, hour[, minute[, second[, microsecond[, delta_years[, delta_months[, delta_days[, delta_hours[, delta_minutes[, delta_s econds[, delta_microseconds]]]]]]]]]]]]]])
375 194
376 Returns a datetime.datetime object which represents the given· 195 A :class:`DateTime` object represents the PYSON ``Date()``
377 attributes. Missing attributes of :attr:`DateTime.year`, 196 statement for date and time related conversions and calculations.
378 :attr:`DateTime.month`, :attr:`DateTime.day`,· 197 Returns a date time object which represents the values of
379 :attr:`DateTime.hour`, :attr:`Date.minute`, :attr:`Date.second`, 198 variables named by the *arguments* explained below.
380 :attr:`DateTime.microseconds` are defaulted to· 199 Missing values of arguments named by ``year``, ``month``, ``day``,
381 datetime.date.today() and datetime.datetime.now().time(). 200 ``hour``, ``minute``, ``second``, ``microseconds`` take their
382 201 defaults from the actual date and time.
383 When delta_* attributes are given, they are added to the· 202 When values of arguments named by ``delta_*`` are given, these are
384 appropriate attributes. 203 added to the appropriate attributes in a date and time preserving
385 204 manner.
386 Class attributes: 205
387 206 Arguments:
388 .. attribute:: DateTime.year 207
389 208 ``year``
390 Contains a PYSON statement of type int or long. 209 Contains a PYSON statement of type int or long.
391 210
392 .. attribute:: DateTime.month 211 ``month``
393 212 Contains a PYSON statement of type int or long.
394 Contains a PYSON statement of type int or long. 213
395 214 ``day``
396 .. attribute:: DateTime.day 215 Contains a PYSON statement of type int or long.
397 216
398 Contains a PYSON statement of type int or long. 217 ``hour``
399 218 Contains a PYSON statement of type int or long.
400 .. attribute:: DateTime.hour 219
401 220 ``minute``
402 Contains a PYSON statement of type int or long. 221 Contains a PYSON statement of type int or long.
403 222
404 .. attribute:: DateTime.minute 223 ``second``
405 224 Contains a PYSON statement of type int or long.
406 Contains a PYSON statement of type int or long. 225
407 226 ``microsecond``
408 .. attribute:: DateTime.second 227 Contains a PYSON statement of type int or long.
409 228
410 Contains a PYSON statement of type int or long. 229 ``delta_years``
411 230 Contains a PYSON statement of type int or long.
412 .. attribute:: DateTime.microsecond 231
413 232 ``delta_month``
414 Contains a PYSON statement of type int or long. 233 Contains a PYSON statement of type int or long.
415 234
416 .. attribute:: DateTime.delta_years 235 ``delta_days``
417 236 Contains a PYSON statement of type int or long.
418 Contains a PYSON statement of type int or long. 237
419 238 ``delta_hours``
420 .. attribute:: DateTime.delta_month 239 Contains a PYSON statement of type int or long.
421 240
422 Contains a PYSON statement of type int or long. 241 ``delta_minutes``
423 242 Contains a PYSON statement of type int or long.
424 .. attribute:: DateTime.delta_days 243
425 244 ``delta_seconds``
426 Contains a PYSON statement of type int or long. 245 Contains a PYSON statement of type int or long.
427 246
428 .. attribute:: DateTime.delta_hours 247 ``delta_microseconds``
429 248 Contains a PYSON statement of type int or long.
430 Contains a PYSON statement of type int or long. 249
431 250
432 .. attribute:: DateTime.delta_minutes
433
434 Contains a PYSON statement of type int or long.
435
436 .. attribute:: DateTime.delta_seconds
437
438 Contains a PYSON statement of type int or long.
439
440 .. attribute:: DateTime.delta_microseconds
441
442 Contains a PYSON statement of type int or long.
443
444
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b