Index: mojo/public/tools/bindings/generators/mojom_python_generator.py |
diff --git a/mojo/public/tools/bindings/generators/mojom_python_generator.py b/mojo/public/tools/bindings/generators/mojom_python_generator.py |
index 295c656f4c5bf742a1f33b4a584c8bd42c288606..db5e8b696b06e1c2f5e3578e1c81091638c9c4bc 100644 |
--- a/mojo/public/tools/bindings/generators/mojom_python_generator.py |
+++ b/mojo/public/tools/bindings/generators/mojom_python_generator.py |
@@ -90,13 +90,9 @@ |
components = components[1:] |
return '_'.join([x.upper() for x in components]) |
-def FieldStyle(name): |
- components = NameToComponent(name) |
- return '_'.join([x.lower() for x in components]) |
- |
def GetNameForElement(element): |
if (mojom.IsEnumKind(element) or mojom.IsInterfaceKind(element) or |
- mojom.IsStructKind(element) or isinstance(element, mojom.Method)): |
+ mojom.IsStructKind(element)): |
return UpperCamelCase(element.name) |
if isinstance(element, mojom.EnumValue): |
return (GetNameForElement(element.enum) + '.' + |
@@ -104,9 +100,7 @@ |
if isinstance(element, (mojom.NamedValue, |
mojom.Constant)): |
return ConstantStyle(element.name) |
- if isinstance(element, mojom.Field): |
- return FieldStyle(element.name) |
- raise Exception('Unexpected element: %s' % element) |
+ raise Exception('Unexpected element: ' % element) |
def ExpressionToText(token): |
if isinstance(token, (mojom.EnumValue, mojom.NamedValue)): |
@@ -126,7 +120,7 @@ |
return token |
-def GetFullyQualifiedName(kind): |
+def GetStructClass(kind): |
name = [] |
if kind.imported_from: |
name.append(kind.imported_from['python_module']) |
@@ -161,7 +155,7 @@ |
return '_descriptor.MapType(%s)' % ', '.join(arguments) |
if mojom.IsStructKind(kind): |
- arguments = [ 'lambda: %s' % GetFullyQualifiedName(kind) ] |
+ arguments = [ 'lambda: %s' % GetStructClass(kind) ] |
if mojom.IsNullableKind(kind): |
arguments.append('nullable=True') |
return '_descriptor.StructType(%s)' % ', '.join(arguments) |
@@ -176,7 +170,7 @@ |
class_name = 'SingleFieldGroup' |
if field.kind == mojom.BOOL: |
class_name = 'FieldDescriptor' |
- arguments = [ '%r' % GetNameForElement(field) ] |
+ arguments = [ '%r' % field.name ] |
arguments.append(GetFieldType(field.kind, field)) |
arguments.append(str(packed_field.index)) |
arguments.append(str(packed_field.ordinal)) |
@@ -188,19 +182,11 @@ |
return '_descriptor.%s(%s)' % (class_name, ', '.join(arguments)) |
def GetFieldGroup(byte): |
- if byte.packed_fields[0].field.kind == mojom.BOOL: |
+ if len(byte.packed_fields) > 1: |
descriptors = map(GetFieldDescriptor, byte.packed_fields) |
return '_descriptor.BooleanGroup([%s])' % ', '.join(descriptors) |
assert len(byte.packed_fields) == 1 |
return GetFieldDescriptor(byte.packed_fields[0]) |
- |
-def GetResponseStructFromMethod(method): |
- return generator.GetDataHeader( |
- False, generator.GetResponseStructFromMethod(method)) |
- |
-def GetStructFromMethod(method): |
- return generator.GetDataHeader( |
- False, generator.GetStructFromMethod(method)) |
def ComputeStaticValues(module): |
in_progress = set() |
@@ -288,18 +274,14 @@ |
python_filters = { |
'expression_to_text': ExpressionToText, |
'field_group': GetFieldGroup, |
- 'fully_qualified_name': GetFullyQualifiedName, |
'name': GetNameForElement, |
- 'response_struct_from_method': GetResponseStructFromMethod, |
- 'struct_from_method': GetStructFromMethod, |
} |
@UseJinja('python_templates/module.py.tmpl', filters=python_filters) |
def GeneratePythonModule(self): |
return { |
+ 'imports': self.GetImports(), |
'enums': self.module.enums, |
- 'imports': self.GetImports(), |
- 'interfaces': self.GetQualifiedInterfaces(), |
'module': ComputeStaticValues(self.module), |
'structs': self.GetStructs(), |
} |
@@ -313,25 +295,6 @@ |
for each in self.module.imports: |
each['python_module'] = MojomToPythonImport(each['module_name']) |
return self.module.imports |
- |
- def GetQualifiedInterfaces(self): |
- """ |
- Returns the list of interfaces of the module. Each interface that has a |
- client will have a reference to the representation of the client interface |
- in the 'qualified_client' field. |
- """ |
- interfaces = self.module.interfaces |
- all_interfaces = [] + interfaces |
- for each in self.module.imports: |
- all_interfaces += each['module'].interfaces |
- interfaces_by_name = dict((x.name, x) for x in all_interfaces) |
- for interface in interfaces: |
- if interface.client: |
- assert interface.client in interfaces_by_name, ( |
- 'Unable to find interface %s declared as client of %s.' % |
- (interface.client, interface.name)) |
- interface.qualified_client = interfaces_by_name[interface.client] |
- return sorted(interfaces, key=lambda i: (bool(i.client), i.name)) |
def GetJinjaParameters(self): |
return { |