本文整理汇总了Python中skrutil.string_utils.indent函数的典型用法代码示例。如果您正苦于以下问题:Python indent函数的具体用法?Python indent怎么用?Python indent使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了indent函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __native_constructor_with_variable
def __native_constructor_with_variable(self):
space_str = ''
native_constructor = indent(4) + 'private native long nativeCreate{0}('.format(self.__class_name)
for space_index in range(0, len(indent(4) + 'private native long nativeCreate{0}('.format(self.__class_name))):
space_str += ' '
for index in range(0, len(self.__java_var_list)):
java_var = self.__java_var_list[index]
java_var_type = java_var.var_type
if index == 0:
if java_var_type == VarType.cpp_enum:
native_constructor += 'int {0},\n'.format(java_var.name_str)
elif java_var_type == VarType.cpp_string_array:
native_constructor += 'String[] {0},\n'.format(java_var.name_str)
else:
native_constructor += '{0} {1},\n'.format(java_var.var_type.to_java_getter_setter_string(), java_var.name_str)
else:
if java_var_type == VarType.cpp_enum:
native_constructor += space_str + 'int {0},\n'.format(java_var.name_str)
elif java_var_type == VarType.cpp_string_array:
native_constructor += space_str + 'String[] {0},\n'.format(java_var.name_str)
else:
native_constructor += space_str + '{0} {1},\n'.format(java_var.var_type.to_java_getter_setter_string(), java_var.name_str)
native_constructor = native_constructor[:-2]
native_constructor += ');' + _JAVA_BR
return native_constructor
示例2: __constructor_with_variable
def __constructor_with_variable(self):
constructor = indent(4) + 'public {0}('.format(self.__class_name)
space = len(indent(4) + 'public {0}('.format(self.__class_name))
space_str = ''
for space_index in range(0, space):
space_str += ' '
for index in range(0, len(self.__java_var_list)):
java_var = self.__java_var_list[index]
java_var_type = java_var.var_type
if index == 0:
if java_var_type == VarType.cpp_enum:
constructor += '{0} {1},\n'.format(java_var.java_enum, java_var.name_str)
elif java_var_type == VarType.cpp_string_array:
constructor += 'String[] {0},\n'.format(java_var.name_str)
else:
constructor += '{0} {1},\n'.format(java_var.var_type.to_java_getter_setter_string(), java_var.name_str)
else:
if java_var_type == VarType.cpp_enum:
constructor += space_str + '{0} {1},\n'.format(java_var.java_enum, java_var.name_str)
elif java_var_type == VarType.cpp_string_array:
constructor += space_str + 'String[] {0},\n'.format(java_var.name_str)
else:
constructor += space_str + '{0} {1},\n'.format(java_var.var_type.to_java_getter_setter_string(), java_var.name_str)
constructor = constructor[:-2]
constructor += '){\n'
constructor += indent(2) + 'mNativeHandler = nativeCreate{0}('.format(self.__class_name)
for java_var in self.__java_var_list:
if java_var.var_type == VarType.cpp_enum:
constructor += java_var.name_str + '.getValue(), '
else:
constructor += java_var.name_str + ', '
constructor = constructor[:-2]
constructor += ');\n'
constructor += indent(4) + '}' + _JAVA_BR
return constructor
示例3: __http_function
def __http_function(self, api):
http_function = indent(4) + 'public void ' + string_utils.first_char_to_lower(api.function_name)
input_variable = self.__input_variable_declarations(api.input_var_list)
http_function += '({0}{1}response){{\n'\
.format(input_variable, self.__variable_type_from_var_list(api.output_var_list))
http_function += indent(8) + 'm{0}Response'.format(api.function_name) + ' = response;\n'
for variable in api.input_var_list:
if variable.var_type == VarType.cpp_enum:
http_function += indent(8) + 'int {0} = {1}.getValue();\n'\
.format(variable.name_str + "_int", variable.name_str)
if variable.var_type == VarType.cpp_object:
http_function += indent(8) + 'long {0} = {1}.getNativeHandler();\n'\
.format(variable.name_str + '_handler', variable.name_str)
if variable.var_type == VarType.cpp_object_array:
http_function += indent(8) + 'long[] {0} = new long[{1}.size()];\n'\
.format(variable.name_str + '_handler', variable.name_str)
http_function += indent(8) + 'for (int i = 0; i < {0}.size(); i++){{\n'.format(variable.name_str)
http_function += indent(12) + '{0}[i] = {1}.get(i).getNativeHandler();\n'\
.format(variable.name_str + '_handler', variable.name_str)
http_function += indent(8) + '}'
input_variable_call = self.__input_variable_call(api.input_var_list)
http_function += indent(8) + 'native{0}(mNativeHandler{1});\n'\
.format(api.function_name, input_variable_call)
http_function += indent(4) + "}"
return http_function
示例4: generate_fetch_native
def generate_fetch_native(self):
"""Gets fetch method JNI part implementation code. Paris with <generate_fetch>.
Returns:
Implementation of JNI part of fetch methods.
"""
fetch_function = ''
for fetch_command in self.__fetch_commands:
by_list = []
if fetch_command.where != '':
by_list = re.split(',', fetch_command.where)
if fetch_command.alias != '':
fetch_fun_name_native = fetch_command.alias
elif not fetch_command.is_plural:
fetch_fun_name_native = 'Fetch{0}FromCache'.format(self.__object_name)
else:
fetch_fun_name_native = 'Fetch{0}FromCache'.format(self.__plural_object_name)
if not fetch_command.is_plural:
if len(by_list) == 0:
skr_log_warning('Singular often comes with at least one by parameter')
fetch_function += indent(4) + 'private native long native' + fetch_fun_name_native
fetch_function += self.__convert_bys_to_string(by_list, True, False) + ';' + _JAVA_BR
else:
fetch_function += indent(4) + 'private native long[] native' + fetch_fun_name_native
fetch_function += self.__convert_bys_to_string(by_list, True, False) + ';' + _JAVA_BR
return fetch_function
示例5: __manager_http_implementation
def __manager_http_implementation(self, api_description):
capture_parameters = ''
input_parameters = ''
for input_var in api_description.input_var_list:
input_parameters += input_var.name + ', '
if input_var.capture:
capture_parameters += input_var.name + ', '
output_callback_parameters = ''
output_parameters = '(bool success, const std::string &error'
if len(api_description.output_var_list) > 0:
for output_var in api_description.output_var_list:
output_parameters += ', '
output_parameters += output_var.to_set_description_string()
output_callback_parameters += ', '
output_callback_parameters += output_var.to_move_string()
output_parameters += ')'
impl = string_utils.indent(2) + 'WebApi::Api()->{0}({1}[{3}this, callback]{2} {{\n'.format(api_description.name, input_parameters, output_parameters, capture_parameters)
impl += string_utils.indent(4) + 'if (success) {\n'
for output_var in api_description.output_var_list:
impl += self.__cpp_cache_by_cache_description_name(output_var.cache_desc, output_var.name)
for extra in api_description.extra_list:
impl += self.__cpp_cache_by_cache_description_name(extra)
impl += string_utils.indent(4) + '}\n'
impl += string_utils.indent(4) + 'callback(success, error{0});\n'.format(output_callback_parameters)
impl += string_utils.indent(2) + '});'
return impl
示例6: getter
def getter(self):
"""Getter method using JNI.
New development should use <getter_v2>.
Returns:
Java getter method using JNI. For example:
public int getPosition() {
return nativeGetPosition(mNativeHandler);
}
"""
function_str = ''
if self.__var_type == VarType.cpp_bool:
function_str += indent(1) + 'public {0} is{1}() {{\n'\
.format(self.__var_type.to_java_getter_setter_string(), self.__title_style_name)
function_str += indent(2) + 'return nativeIs{0}(mNativeHandler);\n'.format(self.__title_style_name)
function_str += indent(1) + '}'
elif self.__var_type == VarType.cpp_string_array:
function_str += self.__to_get_list_of_string_implementation()
elif self.__var_type == VarType.cpp_enum:
function_str += indent(1) + 'public {0} get{1}() {{\n'.format(self.__java_enum, self.__title_style_name)
function_str += indent(2) + 'return {0}.get{0}ByValue(nativeGet{1}(mNativeHandler));\n'\
.format(self.__java_enum, self.__title_style_name)
function_str += indent(1) + '}'
else:
function_str += indent(1) + 'public {0} get{1}() {{\n'.\
format(self.__var_type.to_java_getter_setter_string(), self.__title_style_name)
function_str += indent(2) + 'return nativeGet{0}(mNativeHandler);\n'.format(self.__title_style_name)
function_str += indent(1) + '}'
return function_str
示例7: generate_constructor_implementation
def generate_constructor_implementation(self):
impl = '- (instancetype)init {\n'
impl += string_utils.indent(2)
impl += 'if (self = [super init]) {\n'
impl += string_utils.indent(4)
impl += '_coreManagerHandler = lesschat::{0}Manager::DefaultManager();\n'.format(self.object_name)
impl += string_utils.indent(2)
impl += '}\n'
impl += string_utils.indent(2)
impl += 'return self;\n'
impl += '}'
return impl
示例8: generate_java
def generate_java(self):
"""Gets Java with JNI implementation. The class inherits from |CoreObject| which means invoker should release
the object himself/herself by calling |CoreObject.dispose()|.
New development should use <generate_java_v2> instead.
Returns:
A string which is the class implementation.
"""
file_name = self.__class_name + '.java'
file_path = 'build/com/lesschat/core/' + self.__group_name + '/' + file_name
output_java = open(file_path, 'w')
java_package = 'package com.lesschat.core.' + self.__group_name + ';'
output_java.write(java_package + _JAVA_BR)
java_import = 'import android.os.Parcel;\n'
java_import += 'import android.os.Parcelable;' + _JAVA_BR
java_import += 'import com.lesschat.core.jni.CoreObject;' + _JAVA_BR
java_import += 'import java.util.ArrayList;\n'
java_import += 'import java.util.Arrays;\n'
if self.__class_name != 'List':
java_import += 'import java.util.List;'
java_class_start = 'public class ' + self.__class_name + ' extends CoreObject implements Parcelable {'
java_class_end = '}'
output_java.write(java_import + _JAVA_BR)
output_java.write(java_class_start + _JAVA_BR)
output_java.write(self.__constructors())
output_java.write(indent(4) + '@Override\n')
output_java.write(indent(4) + 'public void dispose() {\n')
output_java.write(indent(2) + 'nativeRelease{0}(mNativeHandler);\n'.format(self.__class_name))
output_java.write(indent(4) + '}' + _JAVA_BR)
for java_enum in self.__java_enum_list:
output_java.write(java_enum.generate_java_enum(_JAVA_SPACE) + '\n')
for java_var in self.__java_var_list:
output_java.write(java_var.getter() + _JAVA_BR)
output_java.write(_JAVA_BR)
output_java.write(self.__native_constructors())
output_java.write(indent(4) + 'private native void nativeRelease{0}(long handler);'.format(self.__class_name) + _JAVA_BR)
for java_var in self.__java_var_list:
output_java.write(java_var.native_getter() + _JAVA_BR)
output_java.write(self.__parcelable())
output_java.write(java_class_end)
示例9: __http_function_response_v2
def __http_function_response_v2(self, api):
http_function_response = indent(4) + 'public void on{0}(boolean success, String error{1}){{\n' \
.format(api.function_name, self.__output_variable_declaration_v2(api.output_var_list))
http_function_response += indent(8) + 'if (m{0}Response == null){{\n'.format(api.function_name)
http_function_response += indent(12) + 'return;\n'
http_function_response += indent(8) + '}\n'
http_function_response += indent(8) + 'if (success){\n'
http_function_response += indent(12) + 'm{0}Response.onSuccess({1});\n' \
.format(api.function_name, self.__output_variable_call(api.output_var_list))
http_function_response += indent(8) + '} else {\n'
http_function_response += indent(12) + 'm{0}Response.onFailure(error);\n'.format(api.function_name)
http_function_response += indent(8) + '}\n'
http_function_response += indent(4) + '}'
return http_function_response
示例10: objc_form_cpp_parameter
def objc_form_cpp_parameter(self, indent):
objc_code = ''
if self.var_type == VarType.cpp_object_array:
objc_code += string_utils.indent(indent)
objc_code += 'NSMutableArray *{0} = [NSMutableArray array];\n'.format(self.__objc_name())
objc_code += string_utils.indent(indent)
objc_code += 'for (auto it = core{0}.begin(); it != core{0}.end(); ++it) {{\n'.format(self.to_title_style_name())
objc_code += string_utils.indent(2 + indent)
objc_code += '[{0} addObject:[LCC{1} {2}WithCore{1}:**it]];\n'.format(self.__objc_name(), self.var_type.object_class_name, string_utils.first_char_to_lower(self.var_type.object_class_name))
objc_code += string_utils.indent(indent)
objc_code += '}'
elif self.var_type == VarType.cpp_object:
objc_code += string_utils.indent(indent)
objc_code += 'LCC{0} *{1} = [LCC{0} {1}WithCore{0}:*core{0}];'.format(self.var_type.object_class_name, self.__objc_name())
return objc_code
示例11: __constructors
def __constructors(self):
"""Java class constructor with native handler as parameter.
Returns:
A string which is the implementation of the constructor. For example:
public Task(long nativeHandler) {
mNativeHandler = nativeHandler;
}
"""
constructor = indent(4) + 'public {0}() {{ \n mNativeHandler = nativeCreate{0}(); \n }}'\
.format(self.__class_name) + _JAVA_BR
constructor += indent(4) + 'public {0}(long nativeHandler) {{\n'.format(self.__class_name)
constructor += indent(2) + 'mNativeHandler = nativeHandler;\n'
constructor += indent(4) + '}\n\n'
return constructor
示例12: generate_web_api_implementations
def generate_web_api_implementations(self, config):
"""Generates Objective-C++ web api implementations.
Args:
config: A <Config> object represents user-defined info.
Returns:
A string which is Objective-C++ web api implementations.
"""
impl = ''
for api in self.apis:
impl += self.__web_api_declaration(api, config)
impl += ' {\n'
impl += string_utils.indent(2)
impl += '_coreManagerHandler->\n'
impl += string_utils.indent(2)
impl += api.alias + '('
for input_var in api.input_var_list:
impl += input_var.cast_to_cpp_parameter()
impl += ', '
impl += '[successBlock, failureBlock](bool success, const std::string& errorUTF8String'
for output_var in api.output_var_list:
impl += ', {0}'.format(output_var.objc_wrapper_from_cpp_parameter(config))
impl += ') {\n'
impl += string_utils.indent(4)
impl += 'if (success) {\n'
for output_var in api.output_var_list:
impl += output_var.objc_form_cpp_parameter(6, config)
impl += _OBJC_BR
impl += string_utils.indent(6)
impl += 'successBlock('
for i, output_var in enumerate(api.output_var_list):
if i != 0:
impl += ', '
impl += string_utils.to_objc_property_name(output_var.name)
impl += ');\n'
impl += string_utils.indent(4)
impl += '} else {\n'
impl += string_utils.indent(6)
impl += 'NSString *error = [NSString stringWithUTF8String:errorUTF8String.c_str()];\n'
impl += string_utils.indent(6)
impl += 'failureBlock({0}(error));\n'.format(config.objc_error_method)
impl += string_utils.indent(4)
impl += '}\n'
impl += string_utils.indent(2)
impl += '});\n}'
impl += _OBJC_BR
return impl
示例13: __to_get_list_of_string_implementation
def __to_get_list_of_string_implementation(self):
function = indent(1) + 'public List<String> get{0}() {{\n'.format(self.__title_style_name)
function += indent(2) + 'String[] strs = nativeGet{0}(mNativeHandler);\n'.format(self.__title_style_name)
function += indent(2) + 'if (strs == null) {\n'
function += indent(3) + 'return new ArrayList<String>();\n'
function += indent(2) + '}\n'
function += indent(2) + 'List<String> list = new ArrayList<String>(Arrays.asList(strs));\n'
function += indent(2) + 'return list;\n'
function += indent(1) + "}"
return function
示例14: native_getter
def native_getter(self):
"""Gets Java native getter.
Returns:
Java native getter. For example:
private native String nativeGetTaskId(long handler);
"""
if self.__var_type == VarType.cpp_bool:
return indent(1) + 'private native {0} nativeIs{1}(long handler);'.format(
self.__var_type.to_java_getter_setter_string(), self.__title_style_name)
elif self.__var_type == VarType.cpp_string_array:
return indent(1) + 'private native String[] nativeGet{0}(long handler);'.format(self.__title_style_name)
elif self.__var_type == VarType.cpp_enum:
return indent(1) + 'private native int nativeGet{0}(long handler);'.format(self.__title_style_name)
else:
return indent(1) + 'private native {0} nativeGet{1}(long handler);'.format(
self.__var_type.to_java_getter_setter_string(),self.__title_style_name)
示例15: __constructors_v2
def __constructors_v2(self):
"""Java class constructor with all fields as parameters.
Returns:
A string which is the implementation of the constructor. For example:
/*package*/ File(String fileId,
@File.Type int type,
@File.Visibility int visibility,
@File.Belong int belong,
@File.FolderPermissionSetting int folderPermissionSetting,
String createdBy,
long createdAt,
String updatedBy,
long updatedAt) {
mFileId = fileId;
... Remainder omitted...
}
"""
package_class = indent(4) + '/*package*/ {0}'.format(self.__class_name)
num_line_indent = len(package_class) + 1
if len(self.__java_var_list) > 1:
first_var = self.__java_var_list[0].input_parameter_name()
constructor = '{0}({1},\n'.format(package_class, first_var)
for var in self.__java_var_list:
if first_var == var.input_parameter_name():
continue
constructor += indent(num_line_indent) + '{0},'.format(var.input_parameter_name()) + '\n'
constructor = constructor[:-2] # remove break line and last comma
elif len(self.__java_var_list) == 1:
first_var = self.__java_var_list[0].input_parameter_name()
constructor = '{0}({1})'.format(package_class, first_var)
else:
constructor = '{0}()'.format(package_class)
constructor += ') {\n'
for var in self.__java_var_list:
constructor += indent(8) + var.assignment() + '\n'
constructor += indent(4) + '}'
return constructor