本文整理汇总了Python中thryft.util.indent函数的典型用法代码示例。如果您正苦于以下问题:Python indent函数的具体用法?Python indent怎么用?Python indent使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了indent函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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()
示例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()
示例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()
示例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()}
示例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()
示例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()}
示例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()
示例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()
示例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()
示例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()
示例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()
示例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()
示例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()
示例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
示例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()