def fmt_func(name, check_reserved=False, version=1): name = fmt_underscores(name) if check_reserved: name = _rename_if_reserved(name) if version > 1: name = '{}_v{}'.format(name, version) return name
def _generate_route_method_decl( self, namespace, route, arg_data_type, request_binary_body, method_name_suffix='', extra_args=None): """Generates the method prototype for a route.""" args = ['self'] if extra_args: args += extra_args if request_binary_body: args.append('f') if is_struct_type(arg_data_type): for field in arg_data_type.all_fields: if is_nullable_type(field.data_type): args.append('{}=None'.format(field.name)) elif field.has_default: # TODO(kelkabany): Decide whether we really want to set the # default in the argument list. This will send the default # over the wire even if it isn't overridden. The benefit is # it locks in a default even if it is changed server-side. if is_user_defined_type(field.data_type): ns = field.data_type.namespace else: ns = None arg = '{}={}'.format( field.name, self._generate_python_value(ns, field.default)) args.append(arg) else: args.append(field.name) elif is_union_type(arg_data_type): args.append('arg') elif not is_void_type(arg_data_type): raise AssertionError('Unhandled request type: %r' % arg_data_type) method_name = fmt_func(route.name + method_name_suffix, version=route.version) namespace_name = fmt_underscores(namespace.name) self.generate_multiline_list(args, 'def {}_{}'.format(namespace_name, method_name), ':')
def fmt_var(name, check_reserved=False): s = fmt_underscores(name) return _rename_if_reserved(s) if check_reserved else s
def field_name_raw(self, name): name = fmt_underscores(name) if name in RUST_RESERVED_WORDS: name += '_field' return name
def namespace_name_raw(self, ns_name): name = fmt_underscores(ns_name) if name in RUST_RESERVED_WORDS + RUST_GLOBAL_NAMESPACE: name = 'dbx_' + name return name