Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(453)

Side by Side Diff: mojo/public/tools/bindings/generators/python_templates/module.py.tmpl

Issue 538613005: mojo: Start generating structs for python bindings (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Make structs immutable. Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 {% from "module_macros.tmpl" import enum_values %}
1 # Copyright 2014 The Chromium Authors. All rights reserved. 2 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 4 # found in the LICENSE file.
4 5
5 import mojo.bindings.reflection as _reflection 6 import mojo.bindings.reflection as _reflection
6 {% if imports %} 7 {% if imports %}
7 8
8 {% for import in imports %} 9 {% for import in imports %}
9 import {{import.python_module}} 10 import {{import.python_module}}
10 {% endfor %} 11 {% endfor %}
11 {% endif %} 12 {% endif %}
12 {#--- Constants #} 13 {#--- Constants #}
13 {% if module.constants %} 14 {% if module.constants %}
14 15
15 {% for constant in module.constants %} 16 {% for constant in module.constants %}
16 {{constant|name}} = {{constant.value|expression_to_text}} 17 {{constant|name}} = {{constant.value|expression_to_text}}
17 {% endfor %} 18 {% endfor %}
18 {% endif %} 19 {% endif %}
19 {% for enum in module.enums %} 20 {% for enum in module.enums %}
20 21
21 class {{enum.name}}(object): 22 class {{enum|name}}(object):
22 __metaclass__ = _reflection.MojoEnumType 23 __metaclass__ = _reflection.MojoEnumType
23 VALUES = [ 24 VALUES = {{enum_values(enum)|indent(2)}}
24 {% for field in enum.fields %}
25 {% if field.value %}
26 ('{{field.name}}', {{field.value|expression_to_text}}),
27 {% else %}
28 '{{field.name}}',
29 {% endif %}
30 {% endfor %}
31 ]
32 {% endfor %} 25 {% endfor %}
26 {% for struct in module.structs %}
27
28 class {{struct|name}}(object):
29 __metaclass__ = _reflection.MojoStructType
30 DESCRIPTOR = {
31 {% if struct.constants %}
32 'constants': {
33 {% for constant in struct.constants %}
34 '{{constant|name}}': {{constant.value|expression_to_text}}
pkl (ping after 24h if needed) 2014/09/04 18:12:12 missing , at the end?
qsr 2014/09/05 11:55:49 Done.
35 {% endfor %}
36 },
37 {% endif %}
38 {% if struct.enums %}
39 'enums': {
40 {% for enum in struct.enums %}
41 '{{enum|name}}': {{enum_values(enum)|indent(6)}},
42 {% endfor %}
43 },
44 {% endif %}
45 }
46 {% endfor %}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698