本文整理汇总了Python中thryft.util.indent函数的典型用法代码示例。如果您正苦于以下问题:Python indent函数的具体用法?Python indent怎么用?Python indent使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了indent函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: cpp_sync_handler
def cpp_sync_handler(self):
name = self.cpp_name()
response_name = upper_camelize(self.__parent_function.cpp_name()) + 'Response'
if self.__parent_function.return_field is not None:
call_prefix = "request.respond(%(response_name)s(" % locals()
call_suffix = "))"
else:
call_prefix = ''
call_suffix = """;
request.respond(%(response_name)s())""" % locals()
call_parameters = \
', '.join("request.%s()" % parameter.cpp_getter_name()
for parameter in self.fields)
call_method_name = self.__parent_function.name
call = "%(call_prefix)simpl_->%(call_method_name)s(%(call_parameters)s)%(call_suffix)s;" % locals()
if len(self.__parent_function.throws) > 0:
catches = []
for exception in self.__parent_function.throws:
exception_name = exception.cpp_name()
exception_type_qname = exception.type.cpp_qname()
catches.append("""\
} catch (const %(exception_type_qname)s& %(exception_name)s) {
request.respond(%(exception_name)s);""" % locals())
catches = "\n".join(catches) + "\n}"
call = indent(' ' * 2, call)
call = """\
try {
%(call)s
%(catches)s""" % locals()
call = indent(' ' * 2, call)
return """\
virtual void handle(const %(name)s& request) {
%(call)s
}""" % locals()
开发者ID:minorg,项目名称:thryft,代码行数:34,代码来源:cpp_function.py
示例2: java_write_protocol
def java_write_protocol(self, value, depth=0):
key_ttype = self.key_type.thrift_ttype_name()
key_type_name = self.key_type.java_boxed_qname()
key_write_protocol = \
indent(' ' * 4,
self.key_type.java_write_protocol(
"_iter%(depth)u.getKey()" % locals(),
depth=depth + 1
)
)
value_ttype = self.value_type.thrift_ttype_name()
value_type_name = self.value_type.java_boxed_qname()
value_write_protocol = \
indent(' ' * 4,
self.value_type.java_write_protocol(
"_iter%(depth)u.getValue()" % locals(),
depth=depth + 1
)
)
return """\
oprot.writeMapBegin(org.thryft.protocol.Type.%(key_ttype)s, org.thryft.protocol.Type.%(value_ttype)s, %(value)s.size());
for (com.google.common.collect.ImmutableMap.Entry<%(key_type_name)s, %(value_type_name)s> _iter%(depth)u : %(value)s.entrySet()) {
%(key_write_protocol)s
%(value_write_protocol)s
}
oprot.writeMapEnd();""" % locals()
开发者ID:minorg,项目名称:thryft,代码行数:26,代码来源:java_map_type.py
示例3: cpp_to_string
def cpp_to_string(self, depth, oss, value):
key_to_string = \
indent(' ' * 2,
self.key_type.cpp_to_string(
depth=depth+1,
oss=oss,
value="i%(depth)u->first" % locals()
)
)
value_to_string = \
indent(' ' * 2,
self.value_type.cpp_to_string(
depth=depth+1,
oss=oss,
value="i%(depth)u->second" % locals()
)
)
qname = self.cpp_qname()
return """\
oss << "{";
for (%(qname)s::const_iterator i%(depth)u = %(value)s.begin(); i%(depth)u != %(value)s.end(); ++i%(depth)u) {
if (i%(depth)u != %(value)s.begin()) {
oss << ", ";
}
%(key_to_string)s
oss << ": ";
%(value_to_string)s
}
oss << "]";""" % locals()
开发者ID:minorg,项目名称:thryft,代码行数:30,代码来源:cpp_map_type.py
示例4: js_validation
def js_validation(self, value, value_name, depth=0):
key_type_validation = \
indent(' ' * 4,
self.key_type.js_validation(
depth=depth + 1,
value="__key" % locals(),
value_name=value_name + " key" % locals()
)['type']
)
value_type_validation = \
indent(' ' * 4,
self.value_type.js_validation(
depth=depth + 1,
value="__value" % locals(),
value_name=value_name + " value" % locals()
)['type']
)
return {'type': """\
if (typeof %(value)s !== "object") {
return "expected %(value_name)s to be an object";
}
for (var __key in %(value)s) {
var __value = %(value)s[__key];
%(key_type_validation)s
%(value_type_validation)s
}""" % locals()}
开发者ID:minorg,项目名称:thryft,代码行数:26,代码来源:js_map_type.py
示例5: js_validation
def js_validation(self):
validation = {}
for annotation in self.annotations:
if annotation.name == 'validation':
validation = annotation.value.copy()
break
validation.pop('blank', None)
validation['required'] = self.required
name = self.js_name()
qname = self.js_qname()
validation.update(self.type.js_validation(depth=0, value='value', value_name=qname))
type_validation = validation.pop('type')
if not self.required:
type_validation = indent(' ' * 4, type_validation)
type_validation = """\
if (typeof attr !== "undefined" && attr !== "null") {
%(type_validation)s
}
""" % locals()
type_validation = indent(' ' * 8, type_validation)
validation = json.dumps(validation).lstrip('{').rstrip('}')
return """\
%(name)s: {
"fn": function(value, attr, computedState) {
%(type_validation)s
},
%(validation)s
}""" % locals()
开发者ID:minorg,项目名称:thryft,代码行数:28,代码来源:js_field.py
示例6: _py_method_update
def _py_method_update(self):
if len(self.fields) == 0:
return {}
doc = indent(' ' * 4, "\n".join(field.py_sphinx_doc()
for field in self.fields))
name = self.py_name()
other_name = decamelize(self.py_name())
object_updates = "\n".join(indent(' ' * 8,
("self.%s(%s.%s)" % (field.py_setter_name(), other_name, field.py_getter_call())
for field in self.fields)
))
return {'update': """\
def update(self, %(other_name)s):
'''
%(doc)s
'''
if isinstance(%(other_name)s, %(name)s):
%(object_updates)s
elif isinstance(%(other_name)s, dict):
for key, value in %(other_name)s.items():
getattr(self, 'set_' + key)(value)
else:
raise TypeError(%(other_name)s)
return self
""" % locals()}
开发者ID:minorg,项目名称:thryft,代码行数:27,代码来源:_py_compound_type.py
示例7: dart_repr
def dart_repr(self):
name = self.dart_name()
sections = []
sections.append(indent(' ' * 2, "\n".join(self._dart_member_declarations())))
sections.append(indent(' ' * 2, "\n\n".join(self._dart_methods())))
sections = lpad("\n", "\n\n".join(section for section in sections if len(section) > 0))
return """\
class %(name)s {%(sections)s
}""" % locals()
开发者ID:minorg,项目名称:thryft,代码行数:9,代码来源:_dart_compound_type.py
示例8: js_repr
def js_repr(self):
class_properties = ",\n\n".join(indent(' ' * 8, self._js_class_properties()))
properties = ",\n\n".join(indent(' ' * 8, self._js_properties()))
qname = self.js_qname()
return """\
%(qname)s = Backbone.Model.extend(
{
%(properties)s
},
{
%(class_properties)s
}
);""" % locals()
开发者ID:minorg,项目名称:thryft,代码行数:13,代码来源:_js_compound_type.py
示例9: java_read_protocol
def java_read_protocol(self, **kwds):
def try_catch(statement, throws):
if len(throws) == 0:
return statement
statement = indent(' ' * 4, statement)
return """\
try {
%s
}%s
""" % (statement, ''.join("""\
catch (final %(exception_type_name)s e) {
throw new org.thryft.protocol.InputProtocolException(e);
}""" % locals()
for exception_type_name in throws))
key_read_protocol = \
indent(' ' * 16, try_catch(
'key = ' + self.key_type.java_read_protocol(**kwds) + ';',
self.key_type.java_read_protocol_throws_checked() + self.key_type.java_read_protocol_throws_unchecked()
))
key_type_name = self.key_type.java_boxed_qname()
value_read_protocol = \
indent(' ' * 16, try_catch(
'value = ' + self.value_type.java_read_protocol(**kwds) + ';',
self.value_type.java_read_protocol_throws_checked() + self.value_type.java_read_protocol_throws_unchecked()
))
value_type_name = self.value_type.java_boxed_qname()
return """\
(new com.google.common.base.Function<org.thryft.protocol.InputProtocol, com.google.common.collect.ImmutableMap<%(key_type_name)s, %(value_type_name)s>>() {
@Override
public com.google.common.collect.ImmutableMap<%(key_type_name)s, %(value_type_name)s> apply(final org.thryft.protocol.InputProtocol iprot) {
try {
final org.thryft.protocol.MapBegin mapBegin = iprot.readMapBegin();
final com.google.common.collect.ImmutableMap.Builder<%(key_type_name)s, %(value_type_name)s> map = com.google.common.collect.ImmutableMap.builder();
for (int entryI = 0; entryI < mapBegin.getSize(); entryI++) {
final %(key_type_name)s key;
%(key_read_protocol)s
final %(value_type_name)s value;
%(value_read_protocol)s
map.put(key, value);
}
iprot.readMapEnd();
return map.build();
} catch (final org.thryft.protocol.InputProtocolException e) {
throw new org.thryft.protocol.UncheckedInputProtocolException(e);
}
}
}).apply(iprot)""" % locals()
开发者ID:minorg,项目名称:thryft,代码行数:50,代码来源:java_map_type.py
示例10: cpp_repr
def cpp_repr(self):
name = self.cpp_name()
extends = lpad(' : public ', self._cpp_extends())
template_parameters = rpad(self._cpp_template_parameters(), "\n")
sections = []
# sections.append(indent(' ' * 4, repr(self._CppBuilder(self))))
sections.append(lpad("public:\n", "\n\n".join(indent(' ' * 2,
self._cpp_constructors() + [self._cpp_destructor()] + self._cpp_methods_list()
))))
sections.append(lpad("private:\n", "\n".join(indent(' ' * 2, self._cpp_member_declarations()))))
sections = lpad("\n", "\n\n".join(section for section in sections if len(section) > 0))
return """\
%(template_parameters)sclass %(name)s%(extends)s {%(sections)s
};""" % locals()
开发者ID:minorg,项目名称:thryft,代码行数:14,代码来源:_cpp_compound_type.py
示例11: py_repr
def py_repr(self):
extends = ', '.join(self._py_extends())
sections = []
builder = self._py_builder()
if builder is not None:
sections.append(indent(' ' * 4, builder))
field_metadata_enum = self._py_field_metadata_enum()
if field_metadata_enum is not None:
sections.append(indent(' ' * 4, field_metadata_enum))
sections.append(indent(' ' * 4, "\n".join(self._py_methods())))
sections = "\n\n".join(sections)
name = self.py_name()
return """\
class %(name)s(%(extends)s):
%(sections)s""" % locals()
开发者ID:minorg,项目名称:thryft,代码行数:15,代码来源:_py_compound_type.py
示例12: java_repr
def java_repr(self):
class_annotations = rpad("\n".join(self._java_annotations()), "\n")
javadoc = self.java_doc()
name = self.java_bean_name()
methods = self._java_methods()
sections = []
sections.append(indent(' ' * 4, self._java_field_metadata_enum()))
sections.append("\n\n".join(indent(' ' * 4,
self._java_constructors() + \
[methods[key] for key in sorted(methods.keys())])))
sections.append("\n\n".join(indent(' ' * 4, self._java_member_declarations())))
sections = lpad("\n", "\n\n".join(section for section in sections if len(section) > 0))
return """\
%(javadoc)s%(class_annotations)spublic class %(name)s implements org.thryft.StructBean {%(sections)s
}""" % locals()
开发者ID:minorg,项目名称:thryft,代码行数:15,代码来源:bean_java_generator.py
示例13: _java_method_do_post
def _java_method_do_post(self):
read_http_servlet_request_body = indent(' ' * 4, self._java_read_http_servlet_request_body())
function_dispatches = []
if len(self.functions) == 0:
function_dispatches = indent(' ' * 8, """\
__doPostError(httpServletRequest, httpServletResponse, new org.thryft.waf.lib.protocols.json.JsonRpcErrorResponse(-32601, String.format("the method '%s' does not exist / is not available", messageBegin.getName())), messageBegin.getId());
return;
""")
else:
function_dispatches = \
indent(' ' * 8, ' else '.join(
["""\
if (messageBegin.getName().equals("%s")) {
doPost%s(httpServletRequest, httpServletResponse, iprot, messageBegin.getId());
}""" % (function.name, upper_camelize(function.name))
for function in self.functions
] + ['''\
{
__doPostError(httpServletRequest, httpServletResponse, new org.thryft.waf.lib.protocols.json.JsonRpcErrorResponse(-32601, String.format("the method '%s' does not exist / is not available", messageBegin.getName())), messageBegin.getId());
return;
}''']
))
return """\
@Override
protected void doPost(final javax.servlet.http.HttpServletRequest httpServletRequest, final javax.servlet.http.HttpServletResponse httpServletResponse) throws java.io.IOException, javax.servlet.ServletException {
%(read_http_servlet_request_body)s
org.thryft.protocol.MessageBegin messageBegin = null;
try {
final org.thryft.waf.lib.protocols.json.JsonRpcInputProtocol iprot;
try {
iprot = new org.thryft.waf.lib.protocols.json.JsonRpcInputProtocol(new org.thryft.waf.lib.protocols.json.JacksonJsonInputProtocol(httpServletRequestBody));
messageBegin = iprot.readMessageBegin();
} catch (final org.thryft.waf.lib.protocols.json.JsonRpcInputProtocolException e) {
throw e;
} catch (final org.thryft.protocol.InputProtocolException e) {
throw new org.thryft.waf.lib.protocols.json.JsonRpcInputProtocolException(e, -32600);
}
if (messageBegin.getType() != org.thryft.protocol.MessageType.CALL) {
throw new org.thryft.waf.lib.protocols.json.JsonRpcInputProtocolException(-32600, "expected request");
}
%(function_dispatches)s
} catch (final org.thryft.waf.lib.protocols.json.JsonRpcInputProtocolException e) {
__doPostError(httpServletRequest, httpServletResponse, new org.thryft.waf.lib.protocols.json.JsonRpcErrorResponse(e), messageBegin != null ? messageBegin.getId() : null);
return;
}
}
""" % locals()
开发者ID:minorg,项目名称:thryft,代码行数:48,代码来源:json_rpc_servlet_java_generator.py
示例14: java_checks
def java_checks(self, depth, exception_prefix, message_prefix, value):
checks = list(_JavaContainerType.java_checks(
self,
depth=depth,
exception_prefix=exception_prefix,
message_prefix=message_prefix,
value=value
))
if not hasattr(self.element_type, 'java_checks'):
return checks
element_type_checks = \
self.element_type.java_checks(
depth=depth+1,
message_prefix=message_prefix + 'element: ',
exception_prefix=exception_prefix,
value="__element%(depth)d" % locals()
)
if len(element_type_checks) == 0:
return checks
element_type_checks = "\n".join(indent(' ' * 4, element_type_checks))
element_type_name = self.element_type.java_boxed_qname()
checks.append("""\
for (final %(element_type_name)s __element%(depth)d : %(value)s) {
%(element_type_checks)s
}""" % locals())
return checks
开发者ID:minorg,项目名称:thryft,代码行数:26,代码来源:_java_sequence_type.py
示例15: _cpp_constructor_required
def _cpp_constructor_required(self):
if len(self.fields) == 0:
return None # Will be covered by default constructor
elif len(set([field.required for field in self.fields])) <= 1:
# All fields are optional or all fields are required
return None # Will be covered by total constructor
body = lpad("\n", indent(' ' * 2, self._cpp_constructor_body()))
initializers = []
name = self.cpp_name()
parameters = []
for field in self.fields:
if field.required:
initializers.append(field.cpp_initializer())
parameters.append(field.cpp_parameter())
else:
default_initializer = field.cpp_default_initializer()
if default_initializer is not None:
initializers.append(default_initializer)
initializers = \
lpad("\n : ", ', '.join(initializers))
parameters = ", ".join(parameters)
return """\
%(name)s(%(parameters)s)%(initializers)s {%(body)s
}""" % locals()
开发者ID:minorg,项目名称:thryft,代码行数:25,代码来源:_cpp_compound_type.py
示例16: dart_interface
def dart_interface(self):
functions = "\n".join(indent(' ' * 2, (function.dart_declaration() for function in self.functions)))
name = self.dart_name()
return """\
abstract class %(name)s {
%(functions)s
}""" % locals()
开发者ID:minorg,项目名称:thryft,代码行数:7,代码来源:dart_service.py
示例17: java_checks
def java_checks(self, depth, exception_prefix, message_prefix, value):
checks = list(_JavaContainerType.java_checks(
self,
depth=depth,
exception_prefix=exception_prefix,
message_prefix=message_prefix,
value=value
))
entry_checks = []
for entry_part in ('key', 'value'):
entry_part_type = getattr(self, entry_part + '_type')
if hasattr(entry_part_type, 'java_checks'):
entry_checks.extend(
entry_part_type.java_checks(
depth=depth+1,
message_prefix=message_prefix + entry_part + ': ',
exception_prefix=exception_prefix,
value="__entry%d.get%s()" % (depth, entry_part.capitalize())
)
)
if len(entry_checks) == 0:
return checks
entry_checks = "\n".join(indent(' ' * 4, entry_checks))
key_type_name = self.key_type.java_boxed_qname()
value_type_name = self.value_type.java_boxed_qname()
checks.append("""\
for (final java.util.Map.Entry<%(key_type_name)s, %(value_type_name)s> __entry%(depth)d : %(value)s.entrySet()) {
%(entry_checks)s
}""" % locals())
return checks
开发者ID:minorg,项目名称:thryft,代码行数:30,代码来源:java_map_type.py
示例18: _ts_method_translate_attribute_name
def _ts_method_translate_attribute_name(self):
compound_type_name = self.ts_name()
field_cases = []
for field in self.fields:
field_ts_name = field.ts_name()
field_cases.append("case \"%(field_ts_name)s\": return \"%(field_ts_name)s\";" % locals())
field_thrift_name = field.name
if field_ts_name != field_thrift_name:
field_cases.append("case \"%(field_thrift_name)s\": return \"%(field_ts_name)s\";" % locals())
field_cases = "\n".join(indent(' ' * 4, field_cases))
unknown_attribute_log_level = self._parent_generator()._unknown_attribute_log_level
return {'translateAttributeName': """\
private _translateAttributeName(attributeName: string): string {
switch (attributeName) {
case "id": return attributeName;
%(field_cases)s
default:
console.%(unknown_attribute_log_level)s("%(compound_type_name)s: unknown attribute " + attributeName);
return attributeName;
}
}""" % locals(), 'translateAttributeNames': """\
private _translateAttributeNames(attributes: any): any {
const translatedAttributes = {};
for (var attributeName in attributes) {
const value = attributes[attributeName];
const translatedAttributeName = this._translateAttributeName(attributeName);
if (attributeName === translatedAttributeName) {
translatedAttributes[attributeName] = value;
} else {
translatedAttributes[translatedAttributeName] = value;
}
}
return translatedAttributes;
}"""}
开发者ID:minorg,项目名称:thryft,代码行数:34,代码来源:backbone_ts_generator.py
示例19: cpp_write_protocol
def cpp_write_protocol(self, write_field=True):
id_ = self.id if self.id is not None else 0
name = self.name
getter_name = self.cpp_getter_name()
ttype = self.type.thrift_ttype_name()
value = getter_name + "()"
if not self.required:
value += '.get()'
write_protocol = self.type.cpp_write_protocol(value)
if write_field:
write_protocol = """\
oprot.write_field_begin("%(name)s", ::thryft::protocol::Type::%(ttype)s, static_cast<int16_t>(%(id_)d));
%(write_protocol)s
oprot.write_field_end();
""" % locals()
if not self.required:
write_protocol = indent(' ' * 4, write_protocol)
write_protocol = """\
if (%(getter_name)s().present()) {
%(write_protocol)s
}""" % locals()
if not write_field:
write_protocol += """\
else {
oprot.write_null();
}"""
return write_protocol
开发者ID:minorg,项目名称:thryft,代码行数:27,代码来源:cpp_field.py
示例20: cpp_declaration
def cpp_declaration(self, line_ending="\n", override=False):
override = ' override' if override else ''
name = self.cpp_name()
parameters = \
', '.join(parameter.cpp_parameter()
for parameter in self.parameters)
if self.return_field is not None:
return_type_name = self.return_field.type.cpp_qname()
else:
return_type_name = 'void'
declaration = """\
%(return_type_name)s %(name)s(%(parameters)s)%(override)s""" % locals()
if len(declaration) < 80:
return declaration
parameters = indent(' ' * 2,
(',' + line_ending).join(parameter.cpp_parameter()
for parameter in self.parameters))
return """\
%(return_type_name)s%(line_ending)s%(name)s(%(line_ending)s%(parameters)s%(line_ending)s)%(override)s""" % locals()
开发者ID:minorg,项目名称:thryft,代码行数:26,代码来源:cpp_function.py
注:本文中的thryft.util.indent函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论